Professional Documents
Culture Documents
discussions, stats, and author profiles for this publication at: https://www.researchgate.net/publication/270903472
READS
822
1 AUTHOR:
Debarghya Dutta
Indian Institute of Technology Delhi
1 PUBLICATION 0 CITATIONS
SEE PROFILE
By
DEBARGHYA DATTA
[Roll No.- 16004411010]
[Registration No.- 111600410056 of 2011-2012]
ACKNOWLEDGEMENT
______________
Debarghya Datta
ii
ABSTRACT
Automatic bottle filling machine (ABM) wills a new innovation manufacturing industry
especially sector filling. Automatic bottle filling machine is commercial refilling system
that involves Motor Drives and microcontroller. The system operates automatically in
three stations, which are refilling, checking, and feedback. Filling system operated by
automatic follow bottle height respectively. Motor Drive operates to control motor as
disc through signal forwarded by IR sensor. Microcontroller will obtain signal from IR
sensor and data will be displayed on Liquid Crystal Display (LCD).
The objective of the thesis is to explore the approach of designing a
microcontroller based closed loop controller with on line calculation in order to keep
better flexibility and versatility. Hence the design of a closed loop bottle filling model
using a 12V D.C unipolar Stepper Motor and a 4.8-6V Servomotor have been presented.
The hardware & software are validated in real time by considering different step
settings. The interface circuit and software are all designed with consideration of a small
sampling time to achieve better performance. Implementation of the controller has been
done through a ATMEGA8 AVR microcontroller assembly language programming.
iii
TABLE OF CONTENT
CHAPTER I: INTRODUCTION
1.1
1.2
1.3
1.4
Introduction
Literature Review
Problem Statement Of The Dissertation
Goal Of The Dissertation
1
2
4
5
6
6
8
9
9
10
10
3.3
3.4
3.5
3.6
3.7
3.8
3.9
Working Procedure
Requirements
3.2.1 Hardware Requirement
3.2.2 Software Requirement
Block Diagram
Block Diagram Description
Circuit Diagram
Flow Chart
Flow Chart Description
LCD Used In This Dissertation
Software Approach
11
12
12
29
32
32
33
35
36
36
37
40
42
REFERENCES
43
APPENDIX
44-56
iv
List of Figures
Figure 1. Power supply .................................................................................................................. 10
Figure 2. Rotating Disc .................................................................................................................. 12
Figure 3.Stepper motor .................................................................................................................. 13
Figure 4. Stepper motor connection ............................................................................................. 14
Figure 5. Servo Motor .................................................................................................................... 15
Figure 6.Servo Motor Connection ................................................................................................. 16
Figure 7.Servo motor ..................................................................................................................... 16
Figure 8.Servo Motor .................................................................................................................... 18
Figure 9.IR Sensor Working Principle .......................................................................................... 18
Figure 10.IR Sensor Array............................................................................................................. 19
Figure 11.Ultrasonic Sensor .......................................................................................................... 19
Figure 12.Microcontroller Layout ................................................................................................. 22
Figure 13.Oscillator ....................................................................................................................... 22
Figure 14.Serial Communication ................................................................................................... 24
Figure 15. General Overview ......................................................................................................... 27
Figure 16.Pin Configuration ........................................................................................................... 28
Figure 17.AVR Studio Setup ......................................................................................................... 29
Figure 18.AVR Chip Burning Steps .............................................................................................. 30
Figure 19. Selecting The Chip for Burning ................................................................................... 30
Figure 20.Building The Project ..................................................................................................... 31
Figure 21.Block Diagram .............................................................................................................. 32
Figure 22.Circuit Diagram ............................................................................................................. 33
Figure 23.Project Layout ................................................................................................................ 34
Figure 24.LCD ............................................................................................................................... 36
Figure 25.Program Writing Screenshot ......................................................................................... 37
Figure 26. Selecting the Chip for burning process ........................................................................ 38
Figure 27. Selecting the Hex file for Burning Process .................................................................. 38
Figure 28.Final Step while burning ................................................................................................ 39
CHAPTER I: INTRODUCTION
1.1 INTRODUCTION
Many works have been done on the application of Microcontroller based bottle
filling plant in engineering application as compared to web and data base application.
This chapter presents the works regarding the use of AVR based automatic refilling in
engineering fields.
Control is important for most industrial process to avoid disturbances, which
degrade the overall process performance, and hence a great deal of work is being done in
this field. Electronic controllers, first introduced many years ago, have gradually excelled
in performance over their predecessors both in terms of performance and its economy.
They have reached the highest level of sophistication due to the rapid advances made in
the industry.
The methods of Bottle filling system using controllers like microcontroller or
microprocessor are normally simpler and less expensive than that of some other methods
used in the industry now-a-days. Robotic manipulators are also of wide demand in this
particular area of work due to their precise, wide, simple and continuous control
characteristics, and moreover, for certain advantages over conventional analog servos.
In the present investigation, attempts have been made to design and development
of Microcontroller based Embedded system miniature model of a bottle filling plant. As
all other good things, this powerful component is basically very simple and is obtained
by uniting tested and high- quality "ingredients" (components) as per following receipt:
the simplest computers processor is used as a "brain" of the future system. An
ATMEGA8 controller has been used in our dissertation for control purpose and
execution.
The Stepper Motor and the Servo motor offers the accurate control of the disc or
belt carrying the disc of bottles which is to be filled. Stepper motors consist of a
permanent magnet rotating shaft, called the rotor, and electromagnets on the stationary
portion that surrounds the motor, called the stator.
A command signal which is issued from the user's interface panel comes into the
servo's "positioning controller". The positioning controller is the device which stores
information about various jobs or tasks. It has been programmed to activate the
motor/load, i.e. change speed/position. The Servo motor actually controls the position of
the filler arm which is coupled to it. A reservoir can be incorporated with the system for
larger applications of the same.
The overall project has been designed with the Motor drives with a microcontroller
and typical Sensors for further operations. IR sensor and Ultrasound Sensor acts as the
sensing and actuating part which is directly connected with the driver circuit and the
embedded kit used for the purpose.
2.
In 1977 A.K. LIN and W.W. KOEPSEL proposed a little advanced microprocessor
based filling scheme. The digital system consisting of random logic circuits and an
Intel 8080 microcomputer offers overall advantages in price, performance,
flexibility, and reliability and power requirements.
3. In 1988 J.B. PLANT, S.J. JORNA and Y.T. CHAN has proposed a suitable method
for microprocessor implementation of controlling the conveyor belt. The derivation
of a simple control law is given next, followed by the stability and error analysis of
the controller.
4. In 1989 ZIYAD SALAMEH and SUNWAY WANG investigate the design and
implementation of a firing scheme using the Intel Microcontroller to control the
speed of Control motors, viz. Servo and Stepper motors.
5. In 1991 J.GORDON KETTLEBOROUGH,
controller. The motor drive system consists of a small Stepper motor. A torque
measuring system has also been incorporated.
7. In 1997 F.I. AHMED, A.M.EI-TOBSHY, A.A. MAHFOUZ and M.M.S.
IBRAHIM have introduced the traditional Proportional- Integral (P-I) controller
system for controlling the conveyor belt mechanism. Some improvements in this
field like theoretical studies for (P-I) and (I-P) controllers in the S-domain are
presented and the transfer functions for both are derived.
8. The paper Design of an environment for physical phenomena simulation:
application to visualization and animation of electric field and potential authored
by CASADO-REVUELTA E, MARTINEZ-JIMENEZ, BLANCA-PANCORBO
A. implements the environment towards orientation of automatic filler system.
9. ZAATAR W. and NASR G.E. presents in the paper An implementation scheme
for a microcontroller emulator a general method for defining a microcontroller
emulator, applicable in any high level programming language.
10. COUGHLAN K.L. and P.J. discusses in the paper Developing special purpose
simulators under Microsoft windows AVR the benefits of using Win AVR to
construct special purpose simulators. The development of a special purpose
simulator for the Irish Electricity supply board is described.
11. In 2004 A.H.M.S. UL utilized the SCADA model for the bottle filling entire
mechanism. The control algorithms are stored and implemented by the
microprocessor of the microcomputer. The system employs the use of Motor driver
implemented on the computer.
12. In 2007 T.MAITY, A.GHOSH and S.K. BHUNIA developed a software program
which is an integrated, automated and efficient control, using microcontroller based
embedded systems high level programming languages, through which the system
was successfully compiled and run, thus getting a more reliable autonomous filler
plant.
13. APARAJITH, S. ET AL. (2010) shows that Technology does not drive change, it
enables change. The primary purpose of Technology is its implementation in dayto-day life wherein it could enhance the lifestyle. The use of a robotic arm has been
implemented to design the conveyor belt system.
14. GOGATE, C.A. ET AL. (2004) explains that At present any consignment carried by
a conveyor belt system having a robotic arm which is further manipulated by a
indigenous DC motor can be implemented to pick an place the water filling bottles
in a sequential manner.
15. XING JIANPING ET AL. (2005) proposed a method of combining the two types of
procedures, i.e. a robotic arm with manipulator and SCADA technique for the bottle
filling process. It was initially generalized for bulky industrial systems.
16. DAI, Z. ET AL. (2007) describes the performance of the autonomous milk or water
filling systems with the help of a Proportional and Integral controller. For further
work Proportional-Integral-Derivative controller was also implemented. Numerical
results were Satisfactory.
CHAPTER-II: OVERVIEW
2.1 EMBEDDED CONTROL AND ITS NEED
An embedded control is done by a special-purpose computer system designed to
perform one or a few dedicated functions, often with real-time computing constraints. It
is usually embedded as part of a complete device including hardware and mechanical
parts. In contrast, a general-purpose computer, such as a personal computer, can do many
different tasks depending on programming. Embedded systems control many of the
common devices in use today.
Embedded controllers are often the heart of an industrial control system or a
process control application. The majority of computer systems in use today is embedded
in other machinery, such as automobiles, telephones, appliances, and peripherals for
computer systems. While some embedded systems are very sophisticated, many have
minimal requirements for memory and program length, with no operating system, and
low software complexity. Typical input and output devices include switches, relays,
solenoids, LEDs, small or custom LCD displays, radio frequency devices, and sensors for
data such as temperature, humidity, light level etc. Embedded systems usually have no
keyboard, screen, disks, printers, or other recognizable I/O devices of a personal
computer, and may lack human interaction devices of any kind.
2.2 ADVANTAGES AND IMPORTANT FEATURES OF EMBEDDED
CONTROLLER
The main differentiating feature of an embedded controller is that external PC
controls not all system operation. In fact, the CPU running the system is actually built
into the I/O system itself. While some type of general purpose Personal Computer
complete with mouse, monitor and other human interface devices (HID) hosts a typical,
slaved data acquisition system, an Embedded Controller's processor is usually dedicated
to controlling the I/O system and often does not provide any direct human interface.
Differences between an embedded controller and a standard PC are easily
observed. However, the differences in software are equally noticeable. While most PCs
operating systems for our desktop and laptop computer are large (in terms of RAM and
hard drive space needed), operating systems developed for embedded systems are likely
to be smaller and have been developed without all of the built-in GUIs as well as much of
office equipment peripheral support.
Since embedded processors are usually used to control devices, they sometimes
need to accept input from the device they are controlling. This is the purpose of the
analog to digital converter. Since processors are built to interpret and process digital data,
i.e. 1's and 0's, they won't be able to do anything with the analog signals that may be
being sent to it by a device. So the analog to digital converter is used to convert the
incoming data into a form that the processor can recognize. There is also a digital to
analog converter that allows the processor to send data to the device it is controlling .
In addition to the converters, many embedded microprocessors include a variety
of timers as well. One of the most common types of timers is the Programmable Interval
Timer, or PIT for short. A PIT just counts down from some value to zero. Once it
Reaches zero, it sends an interrupt to the processor indicating that it has finished
counting. This is useful for things such as thermostats, which periodically test the
temperature around them to see if they need to turn the air conditioner on, the heater on,
etc.
In the earliest years of computers in the 1930-40s, computers were sometimes
dedicated to a single task, but were far too large and expensive for most kinds of tasks
performed by embedded computers of today. Over time however, the concept of
programmable controllers evolved from traditional electromechanical sequencers, via
solid state devices, to the use of computer technology.
Since these early applications in the 1960s, embedded systems have come down
in price and there has been a dramatic rise in processing power and functionality. The
first microprocessor for example, the Intel 4004 was designed for calculators and other
small systems but still required many external memory and support chips. In 1978
National Engineering Manufacturers Association released a "standard" for programmable
microcontrollers, including almost any computer-based controllers, such as single board
computers, numerical, and event-based controllers.
Physically, embedded systems range from portable devices such as digital
watches and MP3 players, to large stationary installations like traffic lights, factory
controllers, or the systems controlling nuclear power plants. Complexity varies from low,
with a single microcontroller chip, to very high with multiple units, peripherals and
networks mounted inside a large chassis or enclosure.
10
3.2 REQUIREMENTS
3.2.1. HARDWARE REQUIREMENT
The Hardware of the Bottling Plant consists of Three parts :1. Moving System
2. Sensing System
3. Controlling System
MOVING SYSTEMRotating Disc :-- A circular disc in which all the bottles are fitted one after another is
driven by a stepper motor. The stepper motor is defined at a specific time intervals which
allows it to rotate the disc according to the signals generated from the Sensors.
12
Stepper Motor :-
Stepper Motors work under a very similar principle to DC motors, except they have
many coils instead of just one. So to operate a stepper motor, one must activate these
different coils in particular patterns to generate motor rotation. So stepper motors need to
be sent patterned commands to rotate. These commands are sent (by a microcontroller) as
high and low logic over several lines, and must be pulsed in a particular order and
combination. Steppers are often used because each 'step,' separated by a set step angle,
can be counted and used for feedback control. For example, a 10-degree step angle
stepper motor would require 36 commands to rotate 360 degrees. However, external
torque can force movement to a different step, invalidating feedback. Therefore, external
torque must never exceed the holding torque of a stepper.
Stepper motors consist of a permanent magnet rotating shaft, called the rotor,
and electromagnets on the stationary portion that surrounds the motor, called the stator.
Figure 5 illustrates one complete rotation of a stepper motor. At position 1, we can see
that the rotor is beginning at the upper electromagnet, which is currently active (has
voltage applied to it). To move the rotor clockwise (CW), the upper electromagnet is
deactivated and the right electromagnet is activated, causing the rotor to move 90 degrees
CW, aligning itself with the active magnet. This process is repeated in the same manner
at the south and west electromagnets until we once again reach the starting position.
In the above example, we used a motor with a resolution of 90 degrees or
demonstration purposes. In reality, this would not be a very practical motor for most
applications. The average stepper motor's resolution -- the amount of degrees rotated per
pulse -- is much higher than this. For example, a motor with a resolution of 5 degrees
would move its rotor 5 degrees per step, thereby requiring 72 pulses (steps) to complete a
full 360-degree rotation.
13
Voltage- Polarized
application motors. Higher voltages generally mean more torque, but they also require
more power. Steppers can run above or below rated voltage (to meet other design
requirements) most efficient at rated voltage.
Current-In case of a motor, we would consider Stall Current, Holding Current and
Operating Current (maximum and minimum).
Stall Current - The current that a stepper motor requires when powered but held so that
it does not rotate.
Holding Current - The current that a stepper motor requires when powered but not
signaled to rotate.
Operating Current - The current drawn when a stepper motor experiences zero
resistance torque.It is best to determine current curves relating voltage, current, and
required torque for optimization. When a stepper motor experiences a change in torque
(such as motor reversal), expect short-lived current spikes. Current spikes can be up to
2x the stall current, and can fry control circuitry if unprotected.
Power (Voltage x Current) - Running motors close to Stall Current often, or reversing
current frequently under high torque, can cause motors to melt Heat Sink.
14
Torque In case of a motor, we would consider Stall Torque and Operating Torque
(maximum and minimum).
Stall Torque - The torque a stepper motor requires when powered but held so that it does
not rotate.
Holding Torque - The torque a stepper motor requires when powered but not signaled to
rotate.
Operating Torque - The torque a stepper motor can apply when experiencing zero
resistance torque. Changing the voltage will change the torque.
Velocity - Motors run most efficient at the highest possible speeds. Gearing a motor
allows the stepper motor to run fast, yet have a slower output speed with much higher
torque.
Efficiency - Stepper motors are most efficient at rated voltage. They are less efficient
than DC motors due to non-continuous stepping.
Control Methods - Stepper Motors require a special stepper controller (driver) to
prevent loss of torque. It has a more precise control than a DC motor.
SERVO MOTOR:-
This is not easily defined nor self-explanatory since a servomechanism, or servo drive,
does not apply to any particular device. It is a term which applies to a function or a task.
The function, or task, of a servo can be described as follows. A command signal which is
issued from the user's interface panel comes into the servo's "positioning controller". The
positioning controller is the device which stores information about various jobs or tasks.
It has been programmed to activate the motor/load, i.e. change speed/position.
15
The signal then passes into the servo control or "amplifier" section. The servo control
takes this low power level signal and increases, or amplifies, the power up to appropriate
levels to actually result in movement of the servo motor/load.
These low power level signals must be amplified: Higher voltage levels are needed to
rotate the servo motor at appropriate higher speeds and higher current levels are required
to provide torque to move heavier loads.
This power is supplied to the servo control (amplifier) from the "power supply" which
simply converts AC power into the required DC level. It also supplies any low level
voltage required for operation of integrated circuits.
16
Therefore, a servo involves several devices. It is a system of devices for controlling some
item (load). The item (load) which is controlled (regulated) can be controlled in any
manner, i.e. position, direction, speed. The speed or position is controlled in relation to a
reference (command signal), as long as the proper feedback device (error detection
device) is used. The feedback and command signals are compared, and the corrections
made. Thus, the definition of a servo system is, that it consists of several devices which
control or regulate speed/position of a load.
A servo is a mechanical motorized device that can be instructed to move the output shaft
attached to a servo wheel or arm to a specified position. Inside the servo box is a DC
motor mechanically linked to a position feedback potentiometer, gearbox, electronic
feedback control loop circuitry and motor drive electronic circuit.
Servo Ratings-- The most common details available on a servo are its speed and torque
rating. Nearly all servo packages are listed with brand name, model name/ number,
speed, and torque output at 4.8 volts and 6.0 volts. Some information about metal, plastic
gears or ball bearings may also be listed.
Servo Speed-- Servo Speed is measured by the amount of time (in seconds)
it takes a 1 inch servo arm to sweep left or right through a 60 degree arc at either 4.8 or
6.0 volts. A servo rated at 0.22 seconds/60 degrees takes 0.22 seconds to sweep through a
60 degree arc. Some of the fastest servos available move in the 0.06 to 0.09 second
range. In some servos, faster speeds may
lower torque available.
Servo Torque-- Servo Torque is measured by the amount of weight (in ounces) that a
servo can hold at 1-inch out on the servo output arm in the horizontal plane, again at
either 5.0 or 6.0 volts to see when the servo stalls as it tries to lift the weight horizontally.
Servo Power-- Servo operate from 4.5 to 6.0 volts DC. At the higher voltage servos tend
to be faster and sometimes stronger, but can heat up faster when stalled or in a hold
position with stress forces against the servo output shaft. Some servo controllers require a
separate power source from the control source to deliver the higher 6.0 Vdc.
17
SENSING SYSTEM
IR Sensor- - Infra-Red sensor consists of an emitter (LED) and detector (photo
diode). Emitter sends IR pulses. Position calculation is done through intensity of
reflected light received by the detector. Ambient interference is negligible in IR sensors.
18
Ultrasonic sensors- - Parallax PING ultrasound Sensors can accurately measure distance
up to 3 meters. Connection is very easy requiring only 3 lines: +5V, GND and one Port
pin of Microcontroller.
CONTROLLING SYSTEM
Microcontroller Basics
Obviously, everything that occurs in the microcontroller occurs at high
speed and quite simple, but it would not be so useful if there were no special interfaces,
which make it, complete. Text below refers to that (in short).
19
EEPROM Memory
The EEPROM Memory is a special type of memory which not all the types
of the microcontrollers have. Its content can be changed during program execution
(similar to RAM), but it is permanently saved even after the power goes off (similar to
ROM). It is used for storing different values created and used during operating process
and which must be saved upon turning off the device (calibration values, codes, values to
count up to etc.). A disadvantage of this memory is that programming is relatively slowmeasured in milliseconds.
20
input/output port, each of the port pins can be configured as input or output (each bit in
this register controls the purpose of one single pin).
Program Counter
Program Counter is an engine which starts the program and indicates the
address in memory where next instruction to execute is found. Immediately after its
execution, the value of the counter is incremented by 1. For this automatic increment, the
program executes one instruction at a time as it is written. However ,the program counter
value could be changed at any moment, which will cause jump to a new location in the
program memory. This is how subroutines or branch instructions are executed.
Bit - This word indicates whether the voltage is applied to an electrical conductor or not.
In the first case, a logical one is present on the pin, i.e. the bits value is 1. Otherwise, if
the voltage level is 0 V, i.e. a logical zero is present on the pin, the bits value is 0
Input/output ports (I/O Ports)
The microcontroller cannot be of any use without being connected to
peripheral devices. For that reason, each microcontroller has one or more registers
connected to its pins (called ports in this case).
21
Oscillator
Figure 13.Oscillator
ordered by oscillator but several times slower. The reason for this is that each instruction
is executed in several steps (In some microcontrollers execution time of all instructions is
equal, while in others microcontrollers execution time differs for different instructions).
Consequently, if our system uses quartz crystal of 20MHz, execution time of a program
instruction is 200, 400 or even 800 nS.
Timers/Counters
Most programs use in some way these miniature electronic "stopwatches". They
are mostly 8- or 16-bit SFRs whose value is automatically incremented with each coming
pulse. Once the register is completely "filled up"- an interrupt is generated.
If the registers use internal oscillator for its operating then it is possible to measure
the time between two events ( if the register value is T1 at the moment measuring has
started, and T2 at the moment measuring has finished, then the time that has passed is
equal to the value gained by their subtraction T2-T1 ). If the registers for its operating use
pulses coming from external source then such a timer is converted to counter. This is a
very simple explanation used to describe the essence of the operating. It is a bit more
complicated in practice.
Register is another name for a memory cell. Beside 8 bits available to the user, each
register has also addressing part usually not visible to the user. It is important to know-All registers in ROM as well as those in RAM memory identified as generalpurpose registers are mutually equal. During programming, each register can be assigned
a name, which makes operating much easier.
All SFRs have their own names that are different for different types of the
microcontrollers and each of them has a particular role.
Brown out is potentially dangerous state coming up now the microcontroller is being
turned off or in situations when due to powerful disturbances, voltage supply comes to
the lowest limit. As the microcontroller consists of several circuits, which have different
operating voltage levels, this can cause its "out of control" performance. In order to
prevent that, a circuit for brown out reset is usually embedded. When the voltage level
drops below the lower limit then this circuit immediately resets the whole electronics.
23
Reset pin is usually identified as MCLR (Master Clear Reset) and serves for "external"
reset of the microcontroller by applying logical zero or one depending on type of the
microcontroller. In case the brown out is not embedded, a simple external circuit for
brown out reset can be connected to this pin.
Serial communication
Connection between the microcontroller and peripheral devices established through I/O
ports is an ideal solution for shorter distances- up to several meters. But, when it is
needed to enable communication between two devices on longer distances or when for
any other reason it is not possible to use "parallel" connection,in such and similar
situations, communication through pulses, called serial communication is the most
appropriate to use.
Serial communication problem has been resolved a long time ago and nowadays several
different systems enabling this kind of connection are embedded as a standard equipment
into most microcontroller.
One of the most important things concerning the use of serial communication is to
strictly observe the Protocol. It is a set of rules, which must be applied in order to enable
devices to recognize the data being exchanged. Fortunately, the microcontrollers
automatically take care of it, which leads to a reduction of the programmers work to
simple writing and reading data.
Byte - 8 bits next to each other make entity called a program word or a byte. If the bit is a
digit then it is logical that bytes are numbers. All mathematical operations can be
performed upon them, just like with usual decimal numbers and they are performed in the
ALU. It is important to note that byte ( as each number) has two sides, i.e. digits a byte
24
consists of are not of equal significance. The highest value has a digit on the far left
called the most significant bit (MSB). A digit on the far right has the least value and is
called the least significant bit (LSB). As 8 digits can be combined in 256 different ways,
the greatest decimal number that can present one byte is 255 (zero is also presented with
one combination).
Program
Unlike other integrated circuits, which only need to be connecting to other components
and then powered on, the microcontrollers need to be programmed too prior to turning
the power on.
Interrupt
Electronics is usually faster than physical process in environment it should keep under
control. Thats why the microcontroller spends the most of its time waiting for something
to happen or execute. In order to avoid continuous checking for logical state on input
pins and in internal registers, the interrupt is generated. It is a signal interrupting regular
program execution. Since several events can cause interrupt, when it occurs, the
microcontroller immediately stops operating and checks for the cause. If it is needed to
perform some action, a current state of the program counter is pushed on the Stack and
the appropriate program is executed (so called interrupt routine).
Stack
It is a part of RAM used for storing the current state of the program counter
(address).This address lets the controller know where to return after the subroutine has
been executed. Stack can consist of several levels. This enables subroutines nesting, i.e.
calling one subroutine from another.
Alphabetical List Of Instructions
ACALL- Absolute Call
ADD, ADDC- Add Accumulator (With Carry)
AJMP- Absolute Jump
ANL- Bitwise AND
CJNE- Compare and Jump if Not Equal
25
The AVR microcontroller is computer-on -chip is the brain of Bottle Filling Plant, which
makes decisions and controls all the functions of plant to make it autonomous along with
its circuitry. ATMEGA8 IC is used in which program is burned In its RAM.
Specifications
Operating Voltage- 4.5V to 5.5V
Speed Grades- 0 to 16MHz
Power Consumption at 4MHz, 3V, 25oC
Active- 3.6mA
Idle mode- 1mA
Power down mode- 0.5A
27
Pin Configuration
Pin Descriptions
VCC -- Digital supply voltage.
GND-- Ground.
Port B (PB7 to PB0)
XTAL1/XTAL2/TOSC1/
TOSC2 -- Port B is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port B output buffers have symmetrical drive characteristics
with both high sink and source capability. As inputs, Port B pins that are externally
pulled low will source current if the pull-up
resistors are activated. The Port B pins are tri-stated when a reset condition becomes
active.
28
Using the AVR kit and compiler For working with the ATMEGA kit, we first need to
install some software to write your program, compile them and burn it in our hardware
kit.
Softwares are:1. winAVR (free GNU compiler)
2. AVR Studio 4.0 (free IDE)
3. Extreme Burner
Running the IDE for the first time we need to follow the subsequent steps to run the IDE
for the first time:* Click on the AVR Studio 4 in desktop shortcut or in the All Programs Menu.
* On opening this dialog box should come. Click on New project.
29
Select AVR GCC, Select a suitable location (preferably desktop & Create new
folder there). Giving a project name then we have to click Next
Select AVR Simulator, Atmega8 from the device list. Click on finish
30
Right click on topmost item (usually on the project name) in the left hand tab (see
below) and click on Edit Configuration options
31
33
OVERVIEW OF WORK
34
35
Figure 24.LCD
The LCD which has been used is an alphanumeric LCD and it can display only numbers,
texts and symbols. It is very cost effective and also easy to interface with the system.
Typically there are 16 pins in a 16x2 LCD display. It means we can display upto 2 lines
and 16 characters in a line. Pin no. 1 and 2 are Ground and VDD respectively and are
36
connected with Gnd and +5V Bus. The Pin no. 3 is LCD contrast control pin. Pin no. 414 are needed for the interfacing with the microcontroller. These pins are directly
connected with the microcontroller port pins.
37
Then we have to click on Open, then select the *.hex file inside the default folder
inside the project folder.
38
39
Then when filling is done in the 1st bottle, the LCD displays likewise
40
After the bottle has been filled, the LCD shows the following display
In the similar process following the 1st step it shows the display of the 2nd bottle
In this way the process continues in a sequential order, one after another. I have used six
bottles in my project for the purpose.
Thus we can see that our purpose of making a prototype version of a bottle filling system
with the help of microcontroller, motor drives, sensors and using LCD display are
working and functioning properly without any errors.
41
CONCLUSION
The prototype of bottle filling plant based on embedded system was implemented
and working successfully using microcontroller AVR.
The industrial prototype was built and the conclusions are as follows:
The system can perform the task of autonomous quality control system used in
industrial production.
Implementation of various sensors like IR with Ultrasonic and switches for the
control of rotating disc is functioning successfully.
FUTURE SCOPE
Though the autonomous bottling plant made using the AVR microcontroller is quite
simple and automated, but this realization can be made advanced and faster using PLC
(programmable logical control) which provides faster realization of the circuits. PLCs are
well adapted to a range of automation tasks. These are typically industrial processes in
manufacturing where the cost of developing and maintaining the automation system is
high, relative to the cost of the automation, and where changes to the system would be
expected during its operational life.
Even though this project is very much set as per the production because, we can only fill
and pick up the bottle. We can further modify it using various technologies and processes
like capping the filled bottles, putting the label, varying the height and even packing four
to six bottles in a carton. Thus, we can create a lot of scope for future working with
certain modifications.
42
REFERENCES
[1] Gopal K. Dubey, Fundamentals of Electric Drives, Narosa Publishing House, New
Delhi-1989.
[2] Kumara MKSC, Dayananda PRD, Gunatillaka MDPR, Jayawickrama SS, PC based
speed controlling, A final year report University of Moratuwa Illiniaus USA, 2001102.
[3] J Nicolai and T. Castagnet, A flexible Micro controller based chopper driving a
motor drive, The European Power electronics Application. 1993.
[4] J. Chiasson, Nonlinear Differential- Geometric Techniques for microcontroller, IEEE
Transactionson Control Systems Technology, Vol 2, Page 35-42, 1994.
[5] Peter Spasov, Microcontroller Technology: The 68HC11 Prentice Hall, 5th edition,
2004.
[6] LCD Interfacing, the Microcontroller and Embedded systems by Muhammad Ali
Mazidi, Janice Gillispie Mazidi, Rolin D. Mckinlay.
[7] The 8051 Microcontroller by Kenneth J.Ayala.
[8] The 8051 Microcontroller and Embedded Systems by M. A. Mazidi.
[9] Introduction to Robotics by Sayeed B. Nikku.
[10] Manual book, A beginners guide to AVR, version 2.1. Singapore: Omron.2001
[11] ADC devices ATMEGA8L data sheet.
[12] Lawrence A. Duarte. The Microcontroller Beginners Handbook. 2nd Edition,
USA, Prompt Publication. 3-5; 1998.
[13] Iovine John, Microcontroller Project Book, 2nd Edition. Singapore: McGraw-Hill.
121-123; 2000.
[14] D. Roy Chowdhury, Linear Integrated Circuits, New Age International (P) Ltd.,
2003.
[15] Julia Case Bradley, Anita C. Millspaugh. Programming in Virtual Studio, Version
6. New York: McGraw-Hill/Irwin, 2002.
[16] Sensors and Transducers by A.K. Shawney.
[17] Abu Zaharin Ahmad and Mohd. Nasir Taib. A study on the micro-controller
mechanism, Asia SENSE SENSOR, 2003, Page 359-364.
[18] P.C. Sen and M.L. MacDonald. IEEE Transactions on Energy Conversion, 1978,
Vol. IECI-25, No. 4: 347-354.
43
APPENDIX
MICROCONTROLLER PROGRAMMING CODES
SERVO-MOTOR TEST
#include "lcd.h"
#include<util/delay.h>
#include<stdio.h>
#include"motor.h"
#include"adc.h"
#include<avr/interrupt.h>
uint8_t servo1_pos=45,servo1_temp;
int Read_Distance();
ISR(TIMER1_OVF_vect) // isr is called after 20ms ///
{
int k;
TCNT1=0xFD8F;
sbi(PORTC,1);
_delay_ms(1);
servo1_temp=servo1_pos;
for(k=0;k<135;k++)
{
_delay_us(7);
servo1_temp--;
if(servo1_temp==0) cbi(PORTC,1);
}
}
int main()
{
int i,j,level,zero_level;
LCD_Init();
DCM_Init();
TCCR1B=0x04;
TCNT1=0xFD8F;
sbi(TIMSK,TOIE1);
sei();
sbi(DDRC,1);
while(1)
{
LCD_Clrscr();
printf("Seeking \n Home ");
while(ADC_Read(1)>950)
44
STM_CW();
LCD_Clrscr();
servo1_pos=45;
_delay_ms(100);
zero_level=Read_Distance();
LCD_Clrscr();
level=0;
while(level<3)
{
LCD_Home();
printf("Filling Bottle 1 \nLevel = %dcm
level= zero_level- Read_Distance();
if(level<0) level=0;
}
LCD_Clrscr();
printf("Bottle Filled");
_delay_ms(2000);
servo1_pos=90;
",level);
for(j=2;j<7;j++)
{
LCD_Clrscr();
printf("Moving to\n Bottle - %d",j);
for(i=0;i<85;i++)
STM_CW();
servo1_pos=45;
_delay_ms(100);
zero_level=Read_Distance();
LCD_Clrscr();
level=0;
while(level<3)
{
LCD_Home();
printf("Filling Bottle %d \nLevel = %dcm
level=zero_level-Read_Distance();
if(level<0) level=0;
}
LCD_Clrscr();
printf("Bottle Filled");
_delay_ms(2000);
servo1_pos=90;
}
}
return 0;
}
#define in 0
#define out 1
int Read_Distance()
45
",j,level);
{
uint16_t dist;
sbi(DDRD,out);
cbi(DDRD,in);
sbi(PORTD,in);
TCCR0|=(1<<CS00);
TCNT0=214; // for 6us
cbi(PORTD,out);
_delay_us(10);
sbi(PORTD,out);
_delay_us(10);
cbi(PORTD,out);
dist=0;
cli();
while( (PIND & 0x01)==0);
while( ((PIND & 0x01)!=0) && (dist<30000))
{
while( (TIFR & (1<<TOV0)) == 0);
TCNT0=214;
TIFR |= (1<<TOV0);
dist++;
}
sei();
dist=dist/10;
return dist;
}
LCD TEST
#include "LCD.h"
#include <stdio.h>
#include<util/delay.h>
#include<compat/deprecated.h>
#define CLK 5
#define DATA 3
static int LCD_char(char data,FILE *stream);
static FILE uart_out= FDEV_SETUP_STREAM(LCD_char,
NULL,_FDEV_SETUP_WRITE);
void SPI_MasterInit(void)
{
46
LCD_e_high();
_delay_us(2); //sensitive when changing CPU MHz!!!!!!!!!!!!!
LCD_e_low();
_delay_us(2);
}
//----------------------------------------------------------------------------------------// FUNCTION: LCD_char
// PURPOSE: send a character to the LCD
static int LCD_char(char data,FILE *stream)
{
if (data=='\n')
{
if (g_nCurrentLine >= LCD_LINES - 1)
LCD_Setline(0);
else
LCD_Setline(g_nCurrentLine+1);
}
else
LCD_write(data,1);
return 0;
}
48
case 2:LCD_instr((1<<LCD_DDRAM)+LCD_START_LINE3+x);break;
case 3:LCD_instr((1<<LCD_DDRAM)+LCD_START_LINE4+x);break;
default: break;
}
#endif
}
MOTOR DRIVE TEST
#include<compat/deprecated.h>
#include <avr/io.h>
#define L_MOTOR_EN
1
#define R_MOTOR_EN
2
#define L_MOTOR_INA
0
#define L_MOTOR_INB
5
#define R_MOTOR_INA
6
#define R_MOTOR_INB
7
void DCM_Init()
{
DDRD|=0xE0; // set the motor drive pins as output ////
DDRB|=0X07;
}
void DCM_Forward()
{
sbi(PORTB,L_MOTOR_EN);
sbi(PORTB,R_MOTOR_EN);
sbi(PORTB,L_MOTOR_INA);
cbi(PORTD,L_MOTOR_INB);
cbi(PORTD,R_MOTOR_INA);
sbi(PORTD,R_MOTOR_INB);
}
void STM_CW()
{
//// sequence 1 //////////
sbi(PORTB,L_MOTOR_EN);
sbi(PORTB,R_MOTOR_EN);
cbi(PORTB,L_MOTOR_INA);
cbi(PORTD,L_MOTOR_INB);
cbi(PORTD,R_MOTOR_INA);
sbi(PORTD,R_MOTOR_INB);
_delay_ms(5);
//// sequence 2 //////////
sbi(PORTB,L_MOTOR_EN);
sbi(PORTB,R_MOTOR_EN);
cbi(PORTB,L_MOTOR_INA);
cbi(PORTD,L_MOTOR_INB);
sbi(PORTD,R_MOTOR_INA);
cbi(PORTD,R_MOTOR_INB);
_delay_ms(5);
50
_delay_ms(10);
//// sequence 1 //////////
sbi(PORTB,L_MOTOR_EN);
sbi(PORTB,R_MOTOR_EN);
cbi(PORTB,L_MOTOR_INA);
cbi(PORTD,L_MOTOR_INB);
cbi(PORTD,R_MOTOR_INA);
sbi(PORTD,R_MOTOR_INB);
_delay_ms(10);
}
ADC TEST
#include<avr/io.h>
//HEADER FILE FOR AVR INPUT OUTPUT
#include<compat/deprecated.h> //HEADER FILE FOR FUNCTIONS LIKE SBI
AND CBI
#include<util/delay.h>
//HEADER FILE FOR DELAY
52
53
UCSRA=(1<<U2X);
UCSRC=(1<<URSEL)|(3<<UCSZ0);
UCSRB=(1<<RXEN)|(1<<TXEN);
stdout = &uart_out;
}
AVR
#include<avr/io.h>
#include<compat/deprecated.h>
#include<util/delay.h>
int main()
{
DDRD=0b00011100;
DDRD=(1<<4)|(1<<3)|(1<<2);
DDRD=0x1C;
DDRD=28;
return 0;
A=~B;
y=A|B
Y=A&B
Y=A^B
PORTD=PORTD|(1<<4)|(1<<3);
PORTD=11111101
11101111
PORTD=PORTD&( ~(1<<4))
A|0=A 0 0 = 0
A|1=1 0 1 = 1
A&0=0; 1 0 = 1
A&1=A; 1 1 = 0
A^0=A
A^1=~A
DDRD=(1<<2);
while(1)
{
_delay_ms(1000);
PORTD^=(1<<2);
}
#define LED 2
#define SWITCH 3
int main()
{
int is_blinking=0;
cbi(DDRD,SWITCH); // centre switch iP
sbi(DDRD,LED); // bottom LED OP
sbi(PORTD,SWITCH); // activate PULLUP
while(1)
{
if(bit_is_set(PIND,SWITCH)==0)
{
_delay_ms(100);
while(bit_is_set(PIND,SWITCH)==0); // wait until user releases the key
if(is_blinking==0)
is_blinking=1;
else
is_blinking=0;
}
if(is_blinking==1)
{
_delay_ms(100);
PORTD^=(1<<LED);
}
}
}
#include"lcd.h"
#include<stdio.h>
int main()
{
int i=0;
LCD_Init();
while(1)
{
LCD_Home();
printf("HELLO WORLD\n i= %d",i++);
55
_delay_ms(1000);
}
}
#include"adc.h"
#include"lcd.h"
#include<stdio.h>
#include<util/delay.h>
int main()
{
uint16_t val1, val2;
LCD_Init();
while(1)
{
val1=ADC_Read(1);
val2=ADC_Read(2);
printf("V1 = %4.4d\nV2 = %4.4d",val1,val2);
_delay_ms(100);
}
}
56