Professional Documents
Culture Documents
LFR Report
LFR Report
Internal Guide
B. N. Manjunatha Reddy
Assistant Professor
Dept. of E&C, GAT
2005
GLOBAL ACADEMY OF TECHNOLOGY
(National Education Foundation)
Rajarajeshwari Nagar, Ideal Home Township,
Off. Mysore Road, Bangalore – 560098.
CERTIFICATE
Certified that the project work entitled LINE FOLLOWING ROBOT carried out by Mr
Amithash E, Prasad USN 1GA01EC002 a bonafide student of 8th Semester in partial
fulfillment for the award of Bachelor of Engineering in Electronics and Communication of
Visvesvaraya Technological University, Belgaum, during the year 2005. It is certified that
the corrections/suggestions indicated for Internal Assessment have been incorporated in the
Report department library. The project report has been approved as it satisfies the academic
requirements in respect of project work prescribed for the said degree.
External Viva
Name of the Examiners Signature with date
1.
2.
ACKNOWLEDGEMENT
An endeavor over long period can be successful only with advice and guidance of many well
wishers.
My sincere thanks to the management and Dr. T. S. Seetharam, principal, Global Academy
of Technology, for providing me the opportunity to conduct my project work.
I would also like to thank the staff of E& C Dept for their generous guidance.
I’d like to thank Prof. A. J. Menon, Instrumentation department, IISC, Bangalore, for his
valuable support and guidance throughout the project.
Last but not the least we would like to thank our friends and family for their help in every
way for the success of this project report.
AMITHASH E. PRASAD
CONTENTS
1. SYNOPSIS………………………………………………………………. 01
2. PREAMBLE……………………………………………………………... 03
2.1 INTRODUCTION………………………………………….... 03
2.2 PROBLEM DEFINITION………………………..………... 04
2.3 OBJECTIVES OF THE STUDY……………………………. 04
2.4 SCOPE OF STUDY…………………………………………. 05
2.5 REVIEW OF LITERATURE……………………………….. 05
2.6 APPLICATIONS………………………………………......... 06
2.7 LIMITATIONS…………………………………………….... 06
2.8 METHODOLOGY…………………………………………... 07
3. THEORY……………………………………………………………….... 09
3.1 THE DIFFRENTIAL STEERING SYSTEM……………….. 09
3.2 D.C. MOTORS……………………………………………… 10
3.3 H-BRIDGE MOTOR CONTROL…………………………... 11
3.4 INTELLIGENCE……………………………………………. 14
3.5 THE PIC 16F873 MICROCONTROLLER…………………. 16
3.6 PWM SPEED CONTROL…………………………………... 18
3.7 THE PICMICRO CCP MODULES…………………………. 18
4. DESIGN AND IMPLEMENTATION…………………………………. 22
4.1 SCHEMATIC……………………………………….………... 22
4.2 PROCESS EXPLANATION…………………………..……... 35
4.3 FLOW CHART………………………………..…….……….. 37
4.4 CODE……………………………………………………….... 40
4.5 CODE EXPLANATION…………………………...………… 51
5. RESULT & CONCLUSION………………………………………….. 55
6. BIBLIOGRAPHY……………………………………………………….. 56
7. APPENDIX……………………………………………………………… 58
LINE FOLLOWING ROBOT
1. SYNOPSIS
The line following robot, operates as the name specifies. It is programmed to
follow a dark line on a white background and detect turns or deviations and modify the
motors appropriately. The optical sensor is an array of commercially available IR
reflective type sensors.
The core of the robot is the PIC 16F873 microcontroller. The speed control of the
motors is achieved by the two PWM modules in the µC. The direction control is provided
by 2 I/O pins. The H-Bridge motor driving/control chip takes these signals and translates
it into current direction entering the motor armature. The motors require separate supply
for operation.
The differential steering system is used to turn the robot. In this system, each back
wheel has a dedicated motor while the front wheels are free to rotate. To move in a
straight line, both the motors are given the same voltage (same polarity). To manage a
turn of different sharpness, the motor on the side of the turn required is given lesser
voltage. To take a sharp turn, its polarity is reversed.
The control has 6 modes of operation, turn left/right, move left/right, and drift
left/right. The actual action is caused by controlling the direction/speed of the two motors
(the two back wheels), thus causing a turn. The actual implementation is a behavior based
(neural) control with the sensors providing the inputs. The robot can also be programmed
to find the line by pseudo-random movement in case no line is detected by the optical
sensor.
1
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Main Motor
Clock
Power Power
4 MHz
Supply Supply
Left
H - Bridge Motor
PIC 16F873 DC Motor
Microcontroller HEX Control
Inverter Right
Motor
Priority
Encoder Threshold
Analog
Comparators Voltage
NOR
Gate
Sensor Array
2
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
2. PREAMBLE
2.1. INTRODUCTION
The robots of the movies, such as C-3PO and the Terminator are portrayed as
fantastic, intelligent, even dangerous forms of artificial life. However, robots of today are
not exactly the walking, talking intelligent machines of movies, stories and our dreams.
In the 1970’s scientists proposed that in the year 2000 we would have created
artificial life forms, almost perfect in terms of intelligence and capabilities. The dream of
free and efficient labor made the researchers of the time go on day and night to bring the
dream to existence. But the task was futile due to the lack of compact processors to carry
out the calculations which were oh so necessary. Now in the year 2000, the micro-
processor technology is thousands of times more advanced than what existed back then.
But still the robots of today are no way close to what our movies portray them to be. This
is not only due to drawbacks in processor technology, but also in various other fields such
as vision, motor control so and so forth.
Robots may never make it to our kitchens or living rooms as personal slaves, but
they certainly have made their way to the manufacturing industry, aero-space industry,
and yes to the work benches of robotic hobbyists. Robots are now working in dangerous
places, such as nuclear disposal, space explorers, fire fighting, etc.
The word "robot" originates from the Czech word for forced labor or serf. Robots
are electronic devices intended to perform a desired function. Many refer to them as
"machines", however, a drill press is a machine, yet it requires an operator to perform its
function, where robots can be programmed to do it themselves. Robots have the potential
to change our economy, our health, our standard of living, our knowledge and the world
in which we live. As the technology progresses, we are finding new ways to use robots.
Each new use brings new hope and possibilities, but also potential dangers and risks.
Robotics is not only a science, but it is also an art. The bots we build reflect the ideas and
personalities we portray. There are many different versions of robots that can be made.
From turtle bots to vehicles like the Mars rovers to rovers like R2-D2. From walkers that
have anywhere from 1 to 10 legs to robotic arms to androids. Whatever you can dream,
you can create. The level of expertise you want your robot to have and how much
3
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
learning and research you want to do is up to you. For those who have relative experience
in computer programming and electronics, this may come easier to you than anyone new
to the hobby. Those who build models, RC vehicles, and other artwork will find it
challenging to modify some of their previous projects.
We have seen how ants always travel in a line, following an invisible route in
search of food, or back home. How on roads we follow lanes to avoid accidents and
traffic jams. Ever thought about a robot which follows line? A perfect or near perfect
mimic of mother-nature? After all the purpose of robotics is to recreate in terms of
machines what we see around to solve a problem or fulfill a requirement.
Programming intelligence into a robot (or computer) is a difficult task and one
that has not been very successful to date even when supercomputers are used. This is not
to say that robots cannot be programmed to perform very useful, detailed, and difficult
tasks; they are. Some tasks are impossible for humans to perform quickly and
productively. For instance, imagine trying to solder 28 filament wires to a 1/4in square
sliver of silicon in 2 s to make an integrated circuit chip. It’s not very likely that a human
would be able to accomplish this task without a machine. But machine task performance,
as impressive as it is, isn’t intelligence.
• The robot must be insensitive to environmental factors such as lighting and noise.
• It must allow calibration of the line’s darkness threshold.
• The robot must be reliable
• Scalability must be a primary concern in the design.
• The color of the line must not be a factor as long as it is darker than the
surroundings.
The next resource for the PIC microcontroller was the MIDRANGE MANUAL
which provides a detailed explanation of each and every hardware feature and the
instruction set. The most helpful is the design tips section which answered most of the
questions which were bogging my head down.
5
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Looking through the library on books on robotics, there was one thing I noticed.
There are no books which deal with understandable basics, or implementation. After a lot
of search, I found “PIC Robotics, A beginner’s guide to robotics projects using the
PICmicro” by John Iovine on the net in the form of an e-Book, which I later printed out
and got it bound! This book is an excellent compliment to the book by Predko.
Robotics by C. K. Kuo was another book I referred for this project. Even though it
was of no direct use to this project, it made me understand many aspects of robotics
which I’d have ignored otherwise. Hopefully, the knowledge I have gained by this book
will come in handy in my next robotic endeavor.
Last but definitely not the least, the Internet. This is where I found websites giving
detailed explanations on a few terminologies. Reference of similar projects created by
others and badly needed tutorials. There is no other place to easily get the data sheets of
the used components. I have listed out a few websites which were of most help for the
project. And in the finale, a huge thanks to Google.com, no other search engine is even
close! No I could not have done anything without the NET even if I had a million books.
The NET is worth much more.
2.6. APPLICATION
• Industrial automated equipment carriers
• Entertainment and small household applications.
• Automated cars.
• Tour guides in museums and other similar applications.
• Second wave robotic reconnaissance operations.
2.7. LIMITATIONS
• Choice of line is made in the hardware abstraction and cannot be changed by
software.
• Calibration is difficult, and it is not easy to set a perfect value.
• The steering mechanism is not easily implemented in huge vehicles and
impossible for non-electric vehicles (petrol powered).
• Few curves are not made efficiently, and must be avoided.
• Lack of a four wheel drive, makes it not suitable for a rough terrain.
6
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
2.8. METHODOLOGY
The first idea was to use optical imaging (CCD cameras) to see the line. This was
later given up due to various reasons including complexity and unavailability of
components. Later a choice was made to use an array of sensors which solved most of
the problems pertaining to complexity.
The resistor values used in the sensor array were experimentally determined rather
than theoretical mathematical design calculations. This was done as the data sheets of
the proximity sensor was not available anywhere and most of the parameters had to be
determined experimentally.
The L293D chip is used as it was a much better option than forming an H-Bridge
out of discrete transistors, which would make the design unstable and prone to risk of
damage.
The PIC microcontroller was used as it is the only device I have a full practical
knowledge about, and most of all a RISC processor which are better suited for real-
time operations. Thus the midrange devices were chosen. The part 16F873 was used
as it has 2 CCP modules which I could use in PWM mode thus simplifying the
software routines which I’d otherwise had to write to generate the PWM control for
the motors.
A priority encoder was used to reduce the number of I/O lines used, which
reduces it to 5 which otherwise would require 7 and a lot of additional complexity in
software which only results is sluggish operation and inefficiency.
Extra hardware was added to let the robot know if it is on a surface or not. This
helps it from not running off a table or preserving battery if manually lifted off the
floor.
7
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Software was coded day and night, deciding on a few algorithms and few tiny
details which gradually got the robot to do what was required. Then extra code was
put to find a line if it is not on one.
The PCB is the only thing in the whole project for which I turned for outside help.
By the time the design became successful, time had run out. I no longer had time or
resources to create a PCM myself. This was done by JI Electronics.
The project was entirely (other than PCB) designed, created, soldered, tested and
coded by me. For which I’m thankful for, as I have learnt much more in the processes and
not to mention the fun had.
8
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
3. THEORY
The differential steering system is familiar from ordinary life because it is the
arrangement used in a wheelchair. Two wheels mounted on a single axis are
independently powered and controlled, thus providing both drive and steering. Additional
passive wheels (usually casters) are provided for support. Most of us have an intuitive
grasp of the basic behavior of a differential steering system. If both drive wheels turn in
tandem, the robot moves in a straight line. If one wheel turns faster than the other, the
robot follows a curved path. If the wheels turn at equal speed, but in opposite directions,
the robot pivots.
where give the displacement (distance traveled) for the left and right wheels
respectively, is the turn radius for the inner (left) wheel, is the distance between
wheels (from center-to-center along the length of the axle), and is the angle of the turn
9
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Once we've established the simple geometry for the differential steering system, it
is easy to develop algorithms for controlling the robot's path. Note, though, that we did
make an important simplifying assumption: the wheels maintain a steady velocity. We
neglected the effects of acceleration. If the wheels are allowed to accelerate, the curve
which describes the robot's trajectory can become much more complicated. When
working with very light robots, where the mass (and inertia) of the platform is small, we
can often get away with treating changes in speed as nearly instantaneous. The path that
the robot follows will not be truly circular, but it will be close enough for many
applications. For larger and heavier robots, of course mass is important and acceleration
must be considered.
If the right wheel is moving at a velocity of VR and the left wheel at a velocity of VL, then
the following equation can be derived.
Where a positive θ implies counter-clockwise rotation; the above equation clearly shows
that the angle of the turn can be increased by either,
• Increasing the difference in the wheel’s velocities (VR – VL), or
• Keep the wheels at the different velocity for a longer time (t)
All this while b remains constant; in the line following robot, both these parameters are
dynamically changed by the sensors in order to keep the robot on the line.
10
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Several characteristics are important when selecting DC motors and these can be
split into two specific categories. The first category is associated with the input ratings of
the motor and specifies its electrical requirements, like operating voltage and current.
The second category is related to the motor's output characteristics and specifies the
physical limitations of the motor in terms of speed, torque and power.
Characteristic Value
Torque: 30 gm-cm
As noticed, the torque provided can hardly move 30gm of weight around with
wheel diameter of about 2cm. This is a fairly a huge drawback as the robot could easily
weigh about a kg. This is accomplished by gears which reduce the speed (2400 rpm is
highly impractical) and effectively increase the torque. If the speed is reduced by using a
gear system by a factor of ρ then the torque is increased by the same factor. For
example, if the speed is reduced from 2400 rpm, to 30 rpm, then the torque is increased
by a factor of (2400/30 = 80) in other words the torque becomes 30 × 80 2400 gm-cm or
2.4 kg-cm which is more than sufficient.
1 0 0 1 CLOCKWISE
0 1 1 0 COUNTER-CLOCKWISE
11
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
The Explanation is simple, If A & D are turned on, then the current flows in the direction
shown in the figure below.
If B & C are turned on, then the motor rotates in counter clockwise direction.
If you turn on the two upper circuits, the motor resists turning, so you effectively
have a breaking mechanism. The same is true if you turn on both of the lower circuits.
This is because the motor is a generator and when it turns it generates a voltage. If the
terminals of the motor are connected (shorted), then the voltage generated counteracts the
motors freedom to turn. It is as if you are applying a similar but opposite voltage to the
one generated by the motor being turned. In other words, it acts like a brake. Any other
state like A & C = ON or B & D = ON will cause a direct path to ground causing a very
high current to pass through the relays thus causing a burnt fuse (if it exists).
The following figure shows an H-Bridge using only transistors. The same theory
applies.
Usually, the above circuitry can be used only for direction control. The Existing H-Bridge
is further modified to include another transistor, now making speed control possible too.
This is shown in the figure below.
The same direction rules apply, but now the motor will behave as per the direction
control only when a ‘1’ is given to the EN input. Speed control is usually done by giving
a PWM signal, and the duty cycle is varied to vary the speed of the motor. Usually
protection diodes are also incorporated across the transistors to catch the back voltage that
is generated by the motor's coil when the power is switched on and off. This fly-back
voltage can be many times higher than the supply voltage! If diodes are not used, the
transistors have a good chance to get burnt.
3.4. INTELLIGENCE
There are two schools of thought concerning the creation of intelligence in
artificial systems. The first approach programs an expert system (top down); the second is
a neural or behavior based system (bottom up). The expert system uses rules to guide the
robot in task performance. Behavior based programs create an “artificial” behavior in the
robot that causes it to reflectively (automatically) perform the task required. Behaviors
may be programmed (software) or may be hardwired into the robot. Behavior based
intelligence doesn’t require a central processor, although such a system may have one.
Let’s look at a practical programming problem and see how each approach differs.
Suppose you worked for a company that designed a new robotic vacuum cleaner. The
purpose of the robot is to vacuum the floor of a customer’s home or apartment. Your job
is to program the navigation system. The robot needs to move autonomously throughout
the house. How would you go about programming the robot to accomplish navigation
around the home so it could travel in and out of rooms without destroying the place?
Let’s assume you first decide to try an expert navigation system. This approach uses brute
force programming and a lot of memory. You might begin by dividing the task of
vacuuming the apartment or home into smaller tasks such as vacuuming individual
rooms. You begin by programming into the robot’s memory an electronic map (floor
plan) of the home or area where the robot needs to vacuum. Then you map out each
individual room and its contents. The robot must have the ability to measure its
movement as it moves as well as compass direction to maintain its location integrity.
Once this is accomplished, the robot must have an exact start location on the floor plan.
14
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
The robot’s movement from the start position is measured and plotted on its
internal floor plan map. Problems occur if an object is positioned differently or is out of
place, such as a trash receptacle or chair that has been moved. In this situation the real
world does not match the robot’s internal map. Similar problems occur if new objects are
left on the floor such as a bag, toy, or pet.
Even so, these obstacles would not present too much of a problem for an expert
system. To compensate, a secondary collision detection subprogram could be written to
detect, map, and go around an obstacle not existing on the internal map. The robot
continues to move and vacuum the floor. Keep in mind that as the robot navigates around
new obstacles, it’s continually updating its internal map as it travels, to maintain its
location integrity. These tasks are gobbling up computer time and memory.
The robot vacuum accomplished its task. Now suppose you w ant to share this
robot or rent it. Now you have a problem. Each new house and every room in the new
house would require its own electronic map. Although expert programming does work, it
tends to be inflexible and not adaptive toward new or innovative situations.
Now let’s try the other approach that uses behavior based or bottom-up
programming. Instead of programming internal maps, we program sensor responses and
behavior based algorithms (feed-forward and feedback loops) for sensing and traveling
around obstacles and avoiding getting stuck underneath furniture or trapped in corners.
Without any internal map we allow the robot to travel and move around the house in a
random manner. The idea is that while traveling in a haphazard manner, it will eventually
make its way throughout the rooms, cleaning the floor as it goes. Because the robot
travels randomly, it will take longer for the robot to vacuum the entire floor, and it may
miss a spot here and there, but it gets the job done. Since this behavior based type of robot
vacuum isn’t programmed for a particular house or room, it may be used in any house in
any room at any time.
While our example is simple, it does illustrate the main differences between
expert and behavior based (neural) programming. But let’s look at just one more example
before we move on.
15
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Expert systems typically have all the answers that the designers believe will be required
by the system programmed into the system before it begins. It may store and categorize
new information, but based on previously determined categories and existing knowledge.
An example of this system could be a rock identification system. The robot examines
unknown rocks based on known characteristics of rocks, such as color, hardness,
scratchability, acid reaction tests, mass, etc. The expert system fails if it inadvertently
picks up a piece of ice that melts to water during the tests. Well, it fails as long as the
designer(s) never anticipated the robot picking up a piece of ice by mistake and made
allowances for it.
Neural (behavior based) systems are not programmed and are more adaptive, as
shown in the previous example. But is a neural system suitable for this task of rock
identification? Probably not! There are instances in which expert systems are the method
of choice. One shouldn’t blindly assume one system is better than the other in all cases.
To date, behavior based robots are more successful at task accomplishments such
as traveling over unfamiliar and rough terrain than are programmed robots. (Other neural
based intelligence includes speech recognition, artificial vision, speech generation,
complex analysis of stock market data, and life insurance policies.)
The line following robot uses behavior based programming, to accomplish the
task at hand. For one, the system may not be a “neural” system pre say. But this is
simulated in software.
16
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Peripheral Features:
• Port A: 6bit bidirectional port
• Port B & C: 8bit bidirectional port
• Timer0: 8-bit timer/counter with 8-bit pre-scalar
• Timer1: 16-bit timer/counter with pre-scalar, can be incremented during
SLEEP via external crystal/clock
• Timer2: 8-bit timer/counter with 8-bit period register, pre-scalar and post-
scalar
• Two Capture, Compare, PWM modules (CCP modules)
• 10-bit, 5 - channel Analog-to-Digital converter
• Synchronous Serial Port (SSP) with SPI (Master mode) and I2C
(Master/Slave)
Universal Synchronous Asynchronous Receiver
• Transmitter (USART/SCI) with 9-bit address detection
• Brown-out detection circuitry for Brown-out Reset (BOR)
17
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
128 bytes in the RAM is reserved for the special purpose registers which show the
status or allows configuring of the microcontroller. The rest of the features are explained
as they are used in the following sections. The programming is done via an ICSP
compatible programmer. The Line following robot was programmed using the ElCheapo
programmer.
1
t∫
A= vdt
t
1 ON
t ∫0
A= + 5dt
t ON
= 12V × ρ
A = 12
t
Where ρ is the duty cycle of the PWM control signal; this shows that by varying the
duty cycle of the PWM control, we effectively vary the DC voltage supplied to the
motors, thus controlling their speed. This is generated by the microcontroller built-in
hardware.
Each CCP module has 3 registers. Multiple CCP modules may exist on a single
device. Throughout this section we’ll use generic names for the CCP registers. These
generic names are shown in the table below.
18
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
The PIC 16F873 has 2 CCP modules, with a common timer resource. Thus, if
both the CCP modules are configured as PWM modules, then both of they will have the
same period, but can have different duty cycles. In PWM mode, the timer 2 resource is
used and hence should not be used for other purposes.
In Pulse Width Modulation (PWM) mode, the CCPx pin produces up to a 10-bit
resolution PWM output. Since the CCPx pin is multiplexed with the PORT data latch, the
corresponding TRIS bit must be cleared to make the CCPx pin an output. The PWM
module’s block diagram is shown in the figure below.
19
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
20
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
25
To achieve a 25% duty cycle, then PWM duty cycle = 12.8 μ s × = 3.2 μs .
100
3.2 μ s = [DCx] • 50 ns • 1
DCx = 64 = 1000000b
Thus, clear the bits DCxB1 & DCxB0 and load 10000b i.e. 16 into the CCPRxL register.
21
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
4.1. SCHEMATIC
The schematic of the “Line following robot” is shown in the figure. The main
component is the PIC 16F873 microcontroller. Due to page limitations, the schematic is
divided into two sections; one the Sensor Array Board, and the other the motor-control or
main board.
The main features incorporated into the hardware are given below:
• The PIC 16F873 microcontroller
• The voltage regulator and supporting components.
• Crystal oscillator (4MHz)
• The 74HC04 CMOS inverters
• The H-bridge motor control IC (L293D)
• Motors, with coupled reduction gears.
• The 74HC148 priority encoder
• The 74HC27 NOR gate.
• 12V, 1.2AH Lead-Acid battery.
• MOC7811 IR interrupt sensor, modified to be a reflective sensor.
• The LM339 quad comparator IC
• A POT to calibrate the reference voltage.
• Connectors to join the different boards to form one functional device.
The 74HCTXX versions of the IC’s are used whenever possible. This is due to their
higher speed and better TTL and CMOS compatibility. The 74HCXX versions are used
only when the corresponding HCT version is not available. Note that the 74LSXX are
TTL logic IC’s where as their HC & HCT counterparts are CMOS logic IC’s.
Each of the hardware is dissected and was designed/implemented separately for their
functional and later incorporated as one whole application. This helped in the debugging
processes. In similar fashion the separate modules forming the ensemble will be
explained separately.
22
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
The PIC microcontroller was used as it’s a RISC processor which is better suited
for real-time operations. Thus the midrange devices were chosen. The part 16F873 was
used as it has 2 CCP modules which could be used in PWM mode thus simplifying the
software routines to generate the PWM control for the motors.
4.1.3. BATTERY
Motors on a robot consume most of the power. For most of them, each DC motor
typically consumes 1.5W on the average. For differential steering, two DC motors
consume up to 3W. By comparison, the logic components typically draw a total of about
80mA. Even at a supply voltage of 12V, the logic component only consumes 1W.
If we assume the whole robot consume 5W, it requires 4500J of energy to last 15
minutes. If we use a 12V battery, it must have a capacity of 4500J/12V=375Asec or
104mAH. This may imply that getting a battery of 150mAH is sufficient. Unfortunately,
the discharge curve of a 150mAH will not sustain the required voltage for 15 minutes.
Thus a Lead Acid battery was used of rating of 1.2AH for the robot to last longer
than 15min and also to take practical situations into considerations.
25
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
It has been shown that practically all electronic devices need DC supply. A direct
voltage of constant magnitude requires to be supplied, for the smooth and efficient
functioning of these devices. A properly designed voltage regulator ensures that,
irrespective of change in supply voltage, load impedance or temperature, the DC supply is
maintained at a constant level. This is achieved by incorporating some type of feedback in
the regulator circuit.
An IC voltage regulator unit contains all the circuitry required in a single IC. Thus
there are no discrete components and the circuitry needed for the reference source, the
comparator and control elements are fabricated on a single chip. Even the over load and
short-circuit protection mechanism is integrated into the IC. IC voltage regulators are
designed to provide either a fixed positive or negative voltage, or an adjustable voltage
which can be set for any value ranging between two voltage levels.
The circuit requires two voltage sources; one for the digital IC’s (+5V) and a
+12V to the motors. The motor is supplied 12V unregulated supply directly from the
battery as regulation would be difficult and unnecessary; whereas the digital IC’s and the
microcontroller require a perfect ripple free +5V to function properly. The L7805C is a
5V voltage regulator IC. The capacitors added to the input of the voltage regulator are to
isolate the spikes generated by the motor from the input and to reduce noise. The 10 μ F
capacitor at the output is to maintain stability and improve regulation. These are standard
values. The 0.1 μ F capacitor is used at the input because of the fact that high value
capacitors have poor high frequency response.
26
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
27
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
The entire motor control circuitry is shown in the above figure along with the
internal circuitry of the L293D motor control IC. The table below clearly indicated the
operation of the IC.
The total number of directional control signals required is 4; but as it can be observed in
the above table, IN1 & IN2 are complimentary (and so is IN3 & IN4) that is, both the
inputs have to take the opposite states for a safe operation. This is done by connecting DL
to IN1 and D L to IN2. The same is done to IN3 & IN4. Now we have 1 directional
control per motor. The ENABLE of each motor section is given PWM inputs to further
improve on the control. Now, each motor has a direction control and a speed control. The
clamping diodes are built into the chip which prevent the back EMF generated by the
motors to harm the H-bridge. The inversion was achieved using the 74HCT04 HEX
inverter IC having a slew rate of about 6ns which is negligible compared to the reaction
time of the H-bridge itself.
The L293D chip can operate on PWM signals up to 5kHz, which was decided to be used.
Three speeds are used for the line following robot and their corresponding duty
cycles are 0%, 50% & 96%. These calculations are shown below.
For the emitter, the collector resistor was determined experimentally on a trial and
error basis. It was decided to use a value of 56 kΩ . For this value, the potential across the
30
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
detector is normally 4.6V, when an object reflects the rays towards the detector, then the
potential drops to 0.6V. The output is obviously analog in nature.
4.1.9. COMPARATOR
A comparator is a circuit which compares a signal voltage applied at one input of
an op-amp with a known reference voltage at the other input, and produces either a high
or a low output voltage, depending on which input is higher. The input / output
characteristics of a comparator is as shown.
The sensor circuit is redrawn using the comparator, and this is shown below.
The reference voltage is generated by the 20k POT and given to all the
comparators to the non-inverting input. When the respective sensor is on the line, the
emitted light is absorbed by the line and the transistor is the cut-off mode, thus a potential
of 4.6V is given to the inverting input which is greater than Vref (which is chosen to be
2.5V), thus the output of the comparator goes low. When the sensor is not on the line
(reflective white surface) the potential across the detector is usually 0.6V. Thus the output
of the comparator goes high (the non-inverting input has a greater potential). Thus the
output of the comparator goes low only when the sensor is over the line. The comparator
is open collector, and hence a pull-up resistor of 10 kΩ is required at the output.
31
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
This priority encoder accepts 8 input request lines 0–7 and outputs 3 lines A0–A2.
The priority encoding ensures that only the highest order data line is encoded. The
extreme sensors are given to the higher order inputs so that they are given a higher
priority compared to the inner sensors so that no required turn is left out of the priority
process. This is shown in the figure shown below. The truth table is also shown.
32
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
As can be noticed from the truth table, the 74HC148 is an active low priority
encoder. The chip has an active low enable (EI) input which is always grounded. If the
robot is not on any line, all the input lines will be high, thus the GS line will go high. This
pin is used as the input to the microcontroller for it to decide if it is on a line or not. The
0’th input is always connected to +Vcc = 5V thus allowing the other inputs to generate an
output from 0 to 6. The chip used is 74HC148 which is a high speed CMOS priority
encoder.
Noticing the placement of the sensors A, B & G, it can be noticed that under no
conditions will all of them detect a line (go low). This will only happen when the line is
too thick, or when the robot is lifted off the surface. Only when all the lines go low, will
the NOR gate’s output go high. This line is used by the microcontroller to sense a surface.
The NOR gate used is the 74HCT27 which is a high speed CMOS gate.
33
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
NS GS A2 A1 A0 STATE IN ACTION
The process involved is taken care of the software. The comparator outputs could have
been directly connected to the microcontroller and all these operations could have been
accomplished in software. But considering that the software would require at least a few
34
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
tens of micro seconds whereas the hardware accomplishes the same in say a 100ns. Thus
due to speed considerations, the present design was arrived at.
If no line is seen, the microcontroller just follows the previous action. This
process is continued till either 5 seconds elapse or a line is reached. If a line is not
reached within 5 seconds (software controlled), the microcontroller shifts into “line find”
mode. In this mode, the robot takes a right turn and starts rotating about a fixed point. The
35
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
radius is continuously incremented every second. Thus the robot follows the path of a
spiral. This process is continued till either a line is reached or till the robot has achieved a
maximum radius of curvature (is traveling in straight line) when the process is reset and
the robot is made to turn in the starting circle, but now at a different point. This is the
algorithm with minimum complexity considering speed requirements.
START
STOP
TMR0 INTERRUPT
HANDLER
Is
surface Stop motors
NO
detected
YES
Is line NO
YES
A RETI
37
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Adjust command
register to have just
3 bits
Is command
NO
different
from
previous?
YES
CALL motor
subroutine
YES
Error
C
?
NO
RETI
38
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
MOTOR
TURN LEFT
YES Both motors = forward
Cmd
Left motor = zero speed
=010
Right motor = high speed
NO
TURN RIGHT
YES
Cmd Both motors = forward
=011 Left motor = high speed
Right motor = zero speed
NO
MOVE LEFT
Cmd YES
Both motors = forward
=100 Left motor = low speed
Right motor = high speed
NO
MOVE RIGHT
Cmd YES
Both motors = forward
=101 Left motor = high speed
Right motor = low speed
NO
GO STRAIGHT
YES
Cmd Both motors = forward
=110 Both motors = high speed
NO
RETURN
39
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
4.4. CODE
The code is divided into 4 modules.
LFR.ASM = this has the main code (Initialization). The rest of the work is done by the
TMR0 interrupt service routine.
LFR.INC = this is an include file holding all the macro definitions, defines and constant
declarations used in the program.
ROUTINE.INC = this is the TMR0 interrupt service routine, does the entire work.
SUBROUTINES.INC = this has all the subroutines used in the program, one delay
subroutine and the “motor” subroutine.
4.4.1. LFR.ASM
;==========================================================;
;==============LINE FOLLOWING ROBOT =======================;
;====================FIRMWARE==============================;
;==================VERSION: 2.0============================;
;**********************************************************;
;+CODE BY: AMITHASH E. PRASAD, ELECTRONICS & COMMUNICATION+;
;++++++++++GLOBAL ACADEMY OF TECHOLOGY+++++++++++++++++++++;
;**********************************************************;
;==========================================================;
LIST P=PIC16F873
#INCLUDE "P16F873.INC"
#INCLUDE "LFR.INC"
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
CBLOCK 0X20
40
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
;|--------------------------------------------------|
;| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | DESCRIPTION |
;|---|---|---|---|---|---|---|---|------------------|
;| X | X | X | X | X | 0 | 0 | 0 | SHARP TURN LEFT |
;| X | X | X | X | X | 0 | 0 | 1 | SHARP TURN RIGHT |
;| X | X | X | X | X | 0 | 1 | 0 | TURN LEFT |
;| X | X | X | X | X | 0 | 1 | 1 | TURN RIGHT |
;| X | X | X | X | X | 1 | 0 | 0 | MOVE LEFT |
;| X | X | X | X | X | 1 | 0 | 1 | MOVE RIGHT |
;| X | X | X | X | X | 1 | 1 | 0 | GO STRAIGHT |
;| X | X | X | X | X | 1 | 1 | 1 | DONT CARE |
;|--------------------------------------------------|
ENDC
;***********************************************************
ORG 0
GOTO INITIALIZATION
ORG 4
;***********************************************************
#INCLUDE ROUTINE.INC
;~450US MAX OVERHEAD TIME
;***********************************************************
ORG 0X51
INITIALIZATION:
BANK1
CLRF TRISC INBANK1 ;PORTC AS OUTPUT
MOVLW 0X1F
MOVWF TRISB INBANK1 ;RB0-RB4 SET AS INPUTS,
;RB5-RB7 AS OUTPUTS
CLRF TRISA INBANK1
MOVLW 0X02
MOVWF OPTION_REG INBANK1
; ENABLE WEAK PULLUPS ON PORTB
;TMR0 CLK SOURCE = INSTRUCTION CLK
;PRESCALAR SET TO TMR0 & SET TO 1:8
;SENSORS SAMPLED EVERY 2.05ms
41
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
MOVLW 0X0C8
MOVWF PR2 INBANK1 ;A PERIOD OF 200 MICRO SECONDS
;(FOR 5KhZ PWM) PUT IN PR REG...
BANK0
CLRF TMR0
MOVLW 0X20
MOVWF INTCON ;ENABLE TMR0 INTERRUPT,
;BUT KEEP MASKED BY CLEARING GIE
NOP
CLRF T2CON ;POSTSCALAR & PRESCALE SET TO 1:1,
;TMR2 = OFF
BSF T2CON,TMR2ON ; TURN ON TMR 2
CLRF CCP1CON ; RESET THE CCP1 MODULE
CLRF CCP2CON ; RESET THE CCP2 MODULE
MOVLW 0X0C ;00001100
MOVWF CCP1CON ;CCP MODE SET TO PWM MODE AND THE
;LOWER TWO BITS OF DUTY CYCLE
;ARE SET TO 0.
MOVWF CCP2CON ;CCP MODE SET TO PWM MODE AND THE
;LOWER TWO BITS OF DUTY CYCLE
;ARE SET TO 0.
MOVLW HIGHSPEED
MOVWF CCPR1L ;SET TO HIGHSPEED DUTY CYCLE
MOVWF CCPR2L ;SET TO HIGHSPEED DUTY CYCLE
BSF INTCON,GIE ;ENABLE INTERRUPTS
CLR16F TIME_COUNT ;INITIALIZE TIME COUNT TO ZERO
MOVLW 0X07
MOVWF PREV_COMMAND_WORD
CLRF TEMP_FLAG
;***********************************************************
GOTO $ ;LOOP HERE INDEFINATELY (WAIT FOR INTERRUPT)
;***********************************************************
#INCLUDE "SUBROUTINES.INC"
;***********************************************************
END
42
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
4.4.2. LFR.INC
;MACRO DEFINITIONS
;GENERAL MACROS AND DEFINES.....
;BANK SELECT MACROS
BANK0 MACRO
BCF STATUS,IRP
BCF STATUS,RP1
BCF STATUS,RP0
ENDM
BANK1 MACRO
BCF STATUS,IRP
BCF STATUS,RP1
BSF STATUS,RP0
ENDM
BANK2 MACRO
BSF STATUS,IRP
BSF STATUS,RP1
BCF STATUS,RP0
ENDM
BANK3 MACRO
BSF STATUS,IRP
BSF STATUS,RP1
BSF STATUS,RP0
ENDM
43
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
;CONSTANTS USED
CONSTANT FORWARD = 0X03 ;0011
CONSTANT ST_LEFT = 0X02 ;0001
CONSTANT ST_RIGHT = 0X01 ;0010
44
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
45
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
4.4.3. ROUTINE.INC
TMR0_ROUTINE:
BTFSS INTCON,T0IF
GOTO INITIALIZATION
;RESET IF A WRONG INTERRUPT IS ENCOUNTERED,
;ELSE CONTINUE WITH ROUTINE
CLRF TMR0
SURFACE_CHECK:
BTFSS NO_SURFACE
GOTO LINE_CHECK
CLRF CCPR2L
CLRF CCPR1L ;STOP BOTH MOTORS IF NO SURFACE IS DETECTED
GOTO EXIT_T0
LINE_CHECK:
BCF NO_LINE_PA ;DEBOUNSING CODE OF THE NO_LINE INPUT
BTFSC NO_LINE
BSF NO_LINE_PA
CALL DELAY_FF_US ;TMP_FLAG,1 IS THE DEBOUNCED INPUT
;IF THE DEBOUNCED INPUT IS 1,
;THEN ROBO SEES NO LINE
BSF NO_LINE_PR
BTFSC NO_LINE_PA ;ELSE ITS JUST A FLICKER,
;CONTINUE TO MODIFIERS
BTFSS NO_LINE
BCF NO_LINE_PR
NOP
BTFSC NO_LINE_PR
GOTO NO_LINE_CODE
MODIFIERS:
BCF LINE_FIND_MODE
BCF NOT_LF_FIRST
MOV16LW TIME_COUNT,0X094C
MOVF PORTB,W
ANDLW 0X07
46
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
MOVWF COMMAND_WORD
XORWF PREV_COMMAND_WORD,W
BTFSC STATUS,Z
GOTO EXIT_T0
MOVF COMMAND_WORD,W
MOVWF PREV_COMMAND_WORD
CALL MOTORS ;16us
SUBLW 0X00
BTFSS STATUS,Z
GOTO INITIALIZATION ;THE DONT CARE STATE IS REACHED,
;PROBABLY ERROR IN INPUTS
;GOTO INITIALIZATION JUST TO MAKE
;SURE IT IS NOT A SOFTWARE PROBLEM.
;ELSE CARRY ON
GOTO EXIT_T0
NO_LINE_CODE:
;NO LINE CODE
BTFSC LINE_FIND_MODE ;IF IN LINE FIND MODE, SKIP THE
COUNTING CODE
GOTO NLA
DEC16F TIME_COUNT
BTFSS STATUS,Z ;IF TIME_COUNT IS NOT YET OVER,
;JUST EXIT ROUTINE (FOLLOW THE
;REMEMBERED STATE)
GOTO EXIT_T0
BCF NOT_LF_FIRST ;IF TIME_COUNT IS 0 (~5SEC) THEN
;SHIFT TO LINE FIND MODE
NLA:
BSF LINE_FIND_MODE ;START NO LINE CODE
MOVLW 0X03 ;SET TO TURN RIGHT
BTFSS NOT_LF_FIRST ;IS THIS THE FIRST OF NO LINE CODE
CALL MOTORS ;IF YES MODIFY MOTORS
BTFSC NOT_LF_FIRST ;IS THIS THE FIRST OF NO LINE CODE
GOTO SKIP_INI
47
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
DEC16F TIME_COUNT
BTFSS STATUS,Z
GOTO EXIT_T0
MOV16LW TIME_COUNT,0X01DC ;INITILIZE TIME_COUNT TO
;TURN ZERO EVERY SECOND
MOVF CCPR2L,W ;INCREMENT CCP2 REG BY 10
ADDLW 0X0A
MOVWF CCPR2L
SUBLW HIGHSPEED
BTFSC STATUS,C
GOTO EXIT_T0
CLRF CCPR2L
EXIT_T0:
BCF INTCON,T0IF ;CLEAR TMR0 INTERRUPT FLAG
RETFIE
;***********************************************************
4.4.4. SUBROUTINES.INC
ORG 0X074
DELAY_FF_US:
;256uS DELAY
MOVLW 0X0FF
MOVWF DELL
DELLOOP:
DECFSZ DELL,1
GOTO DELLOOP
NOP
RETURN
;***********************************************************
48
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
MOTORS:
;TABLE
;COMMAND IS IN W BEFORE CALLING,
ADDWF PCL,F ;EXECUTE THE APPROPRIATE CODE
GOTO SHARP_TURN_LEFT
GOTO SHARP_TURN_RIGHT
GOTO TURN_LEFT
GOTO TURN_RIGHT
GOTO MOVE_LEFT
GOTO MOVE_RIGHT
GOTO GO_STRAIGHT
RETLW 0X0FF ;ERROR INDICATOR, WRONG STATE
MOVE_RIGHT
MOVLW LOWSPEED ;LOW SPEED TO RIGHT MOTOR
MOVWF CCPR2L
MOVLW HIGHSPEED ;HIGH SPEED TO LEFT MOTOR
MOVWF CCPR1L
MOVLW FORWARD ;BOTH MOTORS FORWARD
BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT
MOVWF PORTA ;GIVEN BY THE PREVIOUS_STATE FLAG
BCF PREVIOUS_STATE
RETLW 0X00 ;RETURN FROM KNOWN STATE
MOVE_LEFT
MOVLW HIGHSPEED ;HIGH SPEED TO RIGHT MOTOR
MOVWF CCPR2L
MOVLW LOWSPEED ;LOW SPEED TO LEFT MOTOR
MOVWF CCPR1L
MOVLW FORWARD ;BOTH MOTORS FORWARD
BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT
MOVWF PORTA ;GIVEN BY THE PREVIOUS_STATE FLAG
BCF PREVIOUS_STATE
RETLW 0X00 ;RETURN FROM KNOWN STATE
49
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
TURN_RIGHT
CLRF CCPR2L ;ZERO SPEED TO RIGHT MOTOR
MOVLW HIGHSPEED
MOVWF CCPR1L ;HIGH SPEED TO LEFT MOTOR
MOVLW FORWARD ;BOTH MOTORS FORWARD
BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT
MOVWF PORTA ;GIVEN BY THE PREVIOUS_STATE FLAG
BCF PREVIOUS_STATE
NOP
RETLW 0X00 ;RETURN FROM KNOWN STATE
TURN_LEFT
MOVLW HIGHSPEED ;HIGH SPEED TO RIGHT MOTOR
MOVWF CCPR2L
CLRF CCPR1L ;ZERO SPEED TO LEFT MOTOR
MOVLW FORWARD ;BOTH MOTORS FORWARD
BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT
MOVWF PORTA ;GIVEN BY THE PREVIOUS_STATE FLAG
BCF PREVIOUS_STATE
NOP
RETLW 0X00 ;RETURN FROM KNOWN STATE
SHARP_TURN_RIGHT
MOVLW HIGHSPEED ;HIGH SPEED TO BOTH MOTORS
MOVWF CCPR2L
MOVWF CCPR1L
MOVLW ST_RIGHT ;REVERSE RIGHT MOTOR
MOVWF PORTA
BSF PREVIOUS_STATE ;PREVIOUS STATE NO LONGER FORWARD
NOP
NOP
RETLW 0X00 ;RETURN FROM KNOWN STATE
50
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
SHARP_TURN_LEFT
MOVLW HIGHSPEED ;HIGH SPEED TO BOTH MOTORS
MOVWF CCPR2L
MOVWF CCPR1L
MOVLW ST_LEFT ;REVERSE LEFT MOTOR
MOVWF PORTA
BSF PREVIOUS_STATE ;PREVIOUS STATE NO LONGER FORWARD
NOP
NOP
RETLW 0X00 ;RETURN FROM KNOWN STATE
GO_STRAIGHT
MOVLW HIGHSPEED ;HIGH SPEED TO BOTH MOTORS
MOVWF CCPR2L
MOVWF CCPR1L
MOVLW FORWARD ;BOTH MOTORS FORWARD
BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT
MOVWF PORTA ;GIVEN BY THE PREVIOUS_STATE FLAG
BCF PREVIOUS_STATE
NOP
RETLW 0X00 ;RETURN FROM KNOWN STATE
;***********************************************************
INITILIZATION PROCESS
• Port A & C are set as outputs
• Port B is set as inputs
51
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
4.5.2. LFR.INC
• Bank0 to bank3 macros are used to set the bank select bits in the status register to
put the processor in the required bank.
• The INBANK1 to INBANK3 defines are used whenever a register not in bank 0 is
accessed. This removes the messages shown after build.
The 16 bit macros are used to simplify the code whenever 16bit numbers and
variables are manipulated. The macros are
• INC16F – increment a 16 bit variable in small end-in format.
• DEC16F – decrements a 16 bit variable in small end-in format.
• MOV16LW – loads the 16 bit variable in small end-in format with the specified
immediate 16 bit number
• CLR16F – clears a 16 bit variable in small end-in format.
The rest of the “defines” and constant declarations are used to make understanding the
code easier. But the purpose is lost if the reader skips this section. In fact, even though
this section is the second one presented, it must be the first one to read.
4.5.3. ROUTINE.INC
The first lines of the code check if the interrupt was actually a timer 0 overflow
interrupt just to make sure that no rogue interrupt has occurred. Then the NO_SURFACE
pin is checked; if high, both the motors are stopped and the routine is exited. If the
NO_SURFACE pin is low, it implies that the robot is actually on a surface and the
routine can continue.
52
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
Next, the NO_LINE pin is de-bounced high in software. That is, the pin is read,
then sampled again after 256 μs and compared with the previous value. The no line
section of the code is executed only when both the past and the present inputs were the
same and equal to 1. Otherwise it is assumed that the robot can see the line, and thus
continued onto the modifiers section of the code.
Once the 5 seconds are up, the NLA section of the code is reached. In this the
TIME_COUNT is initialized to 476 (0X01DC) so as to give a delay of 1 second and the
“motor” subroutine is called to set the motors to TURN RIGHT. Once this is done this
section of the code is skipped from the next second onwards. Every time TIME_COUNT
goes to zero (1 second), it is initialized back to 476, and CCPR2L is incremented by 10
thus increasing the radius of curvature of the curve the robot is tracing. CCPR2L is reset
back to zero when it incremented beyond HIGHSPEED. Note that every time, the timer 0
routine is exited.
4.5.4. SUBROUTINES.INC
The first subroutine is a simple 256 μs delay routine using just a single 8 bit
register. The second is the main one called the MOTOR subroutine. This is the one
responsible to modifying the PORT A pins and the PWM duty cycles to achieve the
53
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
required turns. Before the subroutine is called, the W register must hold the
COMMAND_WORD. This value is added to the PCL register, thus causing a jump
dependent on the value. For example if W contained 0, then the immediate instruction is
executed. This is a table of goto’s causing the control to shift to the appropriate locations.
The operations performed by each leg of the subroutine are as shown in the table below.
A user defined flag remembers if the last operation was a forward or something else. This
makes sure that the PORT A bits are not unnecessarily changed. NOP’s are added to each
leg so that each of them are of the same length, thus making the subroutine execute in the
same number of cycles for every command word.
This completes the code explanation. The code occupies 191 program memory words.
54
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
55
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
6. BIBLIOGRAPHY
BOOKS
Programming and Customizing the PIC microcontroller
by Myke Predko Second edition – McGraw Hill
WEBSITES REFERRED
The Seattle Robotics Society Encoder library of robotics articles
http://www.seattlerobotics.org/encoder/library.html
Dallas Personal Robotics Group. Most of these tutorials and articles were referred.
http://www.dprg.org/articles/index.html
http://www.dprg.org/tutorials/index.html
Carnegie Mellon Robotics Club. This is the links page with lots of useful resources
http://www.roboticsclub.org/links.html
56
Department of Electronics & Communication, GAT, Bangalore - 98
LINE FOLLOWING ROBOT
This page is called the “Micro-mouse Handbook” and an excellent tutorial for small scale
robotics.
http://www.drtak.org/teaches/UCD/book/book/
This is the main website of microchip. Thousands of application notes, tutorials &
manuals can be found here.
http://www.microchip.com
57
Department of Electronics & Communication, GAT, Bangalore - 98
PCB LAYOUT
Top Side
Bottom Side
LFR.HEX
:020000040000FA
:02000000512885
:080008000B1D51288101061EA9
:100010000C289B0195014F28241086192414742064
:10002000A4142418861DA4100000A4182A28A411C2
:1000300024120930A6004C30A50006080739A30099
:10004000220603194F282308A2007A20003C031D32
:1000500051284F28A4193328A503250A0319A603FC
:10006000031D4F282412A4150330241E7A20241ABD
:100070003D280130A600DC30A5002416A503250A82
:100080000319A603031D4F280130A600DC30A5008C
:100090001B080A3E9B00C03C03184F289B010B1114
:1000A000090083130313831687011F30860085011F
:1000B00002308100C8309200831303138312810140
:1000C00020308B0000009201121597019D010C3029
:1000D00097009D00C03095009B008B17A501A601DD
:1000E0000730A200A4017328FF30A100A10B7628DD
:1000F000000008008207B028A7289E2895288C2891
:100100008328B928FF3464309B00C0309500033049
:100110002419850024110034C0309B006430950000
:10012000033024198500241100349B01C030950050
:10013000033024198500241100000034C0309B00D6
:100140009501033024198500241100000034C030CB
:100150009B0095000130850024150000000000344C
:10016000C0309B009500023085002415000000007F
:100170000034C0309B009500033024198500241101
:040180000000003447
:02400E00723FFF
:00000001FF
PIC16F87X
28/40-Pin 8-Bit CMOS FLASH Microcontrollers
PIC16F877/874
RE0/RD/AN5 8 33 RB0/INT
branches which are two cycle RE1/WR/AN6 9 32 VDD
• Operating speed: DC - 20 MHz clock input RE2/CS/AN7 10 31 VSS
VDD 11 30 RD7/PSP7
DC - 200 ns instruction cycle
VSS 12 29 RD6/PSP6
• Up to 8K x 14 words of FLASH Program Memory, OSC1/CLKIN 13 28 RD5/PSP5
Up to 368 x 8 bytes of Data Memory (RAM) OSC2/CLKOUT 14 27 RD4/PSP4
PDIP, SOIC
MCLR/VPP 1 28 RB7/PGD
RA0/AN0 2 27 RB6/PGC
RA1/AN1 3 26 RB5
PIC16F876/873
RA2/AN2/VREF- 4 25 RB4
RA3/AN3/VREF+ 5 24 RB3/PGM
RA4/T0CKI 6 23 RB2
RA5/AN4/SS 7 22 RB1
VSS 8 21 RB0/INT
OSC1/CLKIN 9 20 VDD
OSC2/CLKOUT 10 19 VSS
RC0/T1OSO/T1CKI 11 18 RC7/RX/DT
RC1/T1OSI/CCP2 12 17 RC6/TX/CK
RC2/CCP1 13 16 RC5/SDO
RC3/SCK/SCL 14 15 RC4/SDI/SDA
RA3/AN3/VREF+
RA2/AN2/VREF-
MCLR/VPP
RB7/PGD
RB6/PGC
RA1/AN1
RA0/AN0
PLCC
RB5
RB4
NC
NC
6
5
4
3
2
1
44
43
42
41
40
RA4/T0CKI 7 39 RB3/PGM
RA5/AN4/SS 8 38 RB2
RE0/RD/AN5 9 37 RB1
RE1/WR/AN6 10 36 RB0/INT
RE2/CS/AN7 11 PIC16F877 35 VDD
VDD 12 34 VSS
VSS 13
PIC16F874 33 RD7/PSP7
OSC1/CLKIN 14 32 RD6/PSP6
OSC2/CLKOUT 15 31 RD5/PSP5
RC0/T1OSO/T1CK1 16 30 RD4/PSP4
NC 17 9 RC7/RX/DT
18
19
20
21
22
23
24
25
26
27
282
RC1/T1OSI/CCP2
RC3/SCK/SCL
RC4/SDI/SDA
RC2/CCP1
RC3/SCK/SCL
RD0/PSP0
RD1/PSP1
RD2/PSP2
RD3/PSP3
RC1/T1OSI/CCP2
RC5/SDO
NC
RC4/SDI/SDA
RC6/TX/CK
RC6/TX/CK
RC2/CCP1
RD3/PSP3
RD2/PSP2
RD1/PSP1
RD0/PSP0
RC5/SDO
NC
QFP
44
43
42
41
40
39
38
37
36
35
34
RC7/RX/DT 1 33 NC
RD4/PSP4 2 32 RC0/T1OSO/T1CKI
RD5/PSP5 3 31 OSC2/CLKOUT
RD6/PSP6 4 30 OSC1/CLKIN
RD7/PSP7 5 PIC16F877 29 VSS
VSS 6 28 VDD
VDD 7
PIC16F874 27 RE2/AN7/CS
RB0/INT 8 26 RE1/AN6/WR
RB1 9 25 RE0/AN5/RD
RB2 10 24 RA5/AN4/SS
RB3/PGM 11 23 RA4/T0CKI
12
13
14
15
16
17
18
19
20
21
22
RA3/AN3/VREF+
RB4
RB5
RA0/AN0
RA1/AN1
NC
NC
RB6/PGC
RB7/PGD
MCLR/VPP
RA2/AN2/VREF-
Program Data
Device Data Memory
FLASH EEPROM
PIC16F873 4K 192 Bytes 128 Bytes
PIC16F876 8K 368 Bytes 256 Bytes
Synchronous
Data EEPROM CCP1,2 USART
Serial Port
8
M 1
0
RA4/T0CKI U M
X SYNC
pin U 2 TMR0 Reg
1 0
X Cycles
T0SE
T0CS
PSA Set Flag Bit T0IF
on Overflow
PRESCALER
0
M 8-bit Prescaler
U
Watchdog 1 X 8
Timer
8 - to - 1MUX PS2:PS0
PSA
0 1
WDT Enable bit
MUX PSA
WDT
Time-out
bit 7 RBPU
bit 6 INTEDG
bit 5 T0CS: TMR0 Clock Source Select bit
1 = Transition on T0CKI pin
0 = Internal instruction cycle clock (CLKOUT)
bit 4 T0SE: TMR0 Source Edge Select bit
1 = Increment on high-to-low transition on T0CKI pin
0 = Increment on low-to-high transition on T0CKI pin
bit 3 PSA: Prescaler Assignment bit
1 = Prescaler is assigned to the WDT
0 = Prescaler is assigned to the Timer0 module
bit 2-0 PS2:PS0: Prescaler Rate Select bits
Bit Value TMR0 Rate WDT Rate
000 1:2 1:1
001 1:4 1:2
010 1:8 1:4
011 1 : 16 1:8
100 1 : 32 1 : 16
101 1 : 64 1 : 32
110 1 : 128 1 : 64
111 1 : 256 1 : 128
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
Note: To avoid an unintended device RESET, the instruction sequence shown in the PICmicro™ Mid-Range MCU
Family Reference Manual (DS33023) must be executed when changing the prescaler assignment from
Timer0 to the WDT. This sequence must be followed even if the WDT is disabled.
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
- n = Value at POR ’1’ = Bit is set ’0’ = Bit is cleared x = Bit is unknown
TRISC<2>
PWM duty cycle =(CCPR1L:CCP1CON<5:4>) •
Comparator
Clear Timer, TOSC • (TMR2 prescale value)
CCP1 pin and
latch D.C. CCPR1L and CCP1CON<5:4> can be written to at any
PR2
time, but the duty cycle value is not latched into
CCPR1H until after a match between PR2 and TMR2
Note 1: The 8-bit timer is concatenated with 2-bit internal Q occurs (i.e., the period is complete). In PWM mode,
clock, or 2 bits of the prescaler, to create 10-bit time-
base. CCPR1H is a read-only register.
The CCPR1H register and a 2-bit internal latch are
A PWM output (Figure 8-4) has a time-base (period)
used to double buffer the PWM duty cycle. This double
and a time that the output stays high (duty cycle). The
buffering is essential for glitch-free PWM operation.
frequency of the PWM is the inverse of the period
(1/period). When the CCPR1H and 2-bit latch match TMR2, con-
catenated with an internal 2-bit Q clock, or 2 bits of the
FIGURE 8-4: PWM OUTPUT TMR2 prescaler, the CCP1 pin is cleared.
The maximum PWM resolution (bits) for a given PWM
Period frequency is given by the formula:
(FOSC
log FPWM )
Duty Cycle
Resolution = bits
log(2)
TMR2 = PR2
Note: If the PWM duty cycle value is longer than
TMR2 = Duty Cycle
the PWM period, the CCP1 pin will not be
TMR2 = PR2 cleared.
PWM Frequency 1.22 kHz 4.88 kHz 19.53 kHz 78.12kHz 156.3 kHz 208.3 kHz
Timer Prescaler (1, 4, 16) 16 4 1 1 1 1
PR2 Value 0xFFh 0xFFh 0xFFh 0x3Fh 0x1Fh 0x17h
Maximum Resolution (bits) 10 10 10 8 7 5.5
0Bh,8Bh, INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u
10Bh, 18Bh
0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000
0Dh PIR2 — — — — — — — CCP2IF ---- ---0 ---- ---0
8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000
8Dh PIE2 — — — — — — — CCP2IE ---- ---0 ---- ---0
87h TRISC PORTC Data Direction Register 1111 1111 1111 1111
0Eh TMR1L Holding Register for the Least Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
0Fh TMR1H Holding Register for the Most Significant Byte of the 16-bit TMR1 Register xxxx xxxx uuuu uuuu
10h T1CON — — T1CKPS1 T1CKPS0 T1OSCEN T1SYNC TMR1CS TMR1ON --00 0000 --uu uuuu
15h CCPR1L Capture/Compare/PWM Register1 (LSB) xxxx xxxx uuuu uuuu
16h CCPR1H Capture/Compare/PWM Register1 (MSB) xxxx xxxx uuuu uuuu
17h CCP1CON — — CCP1X CCP1Y CCP1M3 CCP1M2 CCP1M1 CCP1M0 --00 0000 --00 0000
1Bh CCPR2L Capture/Compare/PWM Register2 (LSB) xxxx xxxx uuuu uuuu
1Ch CCPR2H Capture/Compare/PWM Register2 (MSB) xxxx xxxx uuuu uuuu
1Dh CCP2CON — — CCP2X CCP2Y CCP2M3 CCP2M2 CCP2M1 CCP2M0 --00 0000 --00 0000
Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by Capture and Timer1.
Note 1: The PSP is not implemented on the PIC16F873/876; always maintain these bits clear.
Note: Additional information on the mid-range instruction set is available in the PICmicro™ Mid-Range MCU
Family Reference Manual (DS33023).
ORDERING NUMBERS:
DESCRIPTION
The Device is a monolithic integrated high volt- L293DD L293D
age, high current four channel driver designed to
accept standard DTL or TTL logic levels and drive
inductive loads (such as relays solenoides, DC
and stepping motors) and switching power tran-
sistors.
To simplify use as two bridges each pair of chan-
nels is equipped with an enable input. A separate The L293D is assembled in a 16 lead plastic
supply input is provided for the logic, allowing op- packaage which has 4 center pins connected to-
eration at a lower voltage and internal clamp di- gether and used for heatsinking
odes are included. The L293DD is assembled in a 20 lead surface
This device is suitable for use in switching appli- mount which has 8 center pins connected to-
cations at frequencies up to 5 kHz. gether and used for heatsinking.
BLOCK DIAGRAM
SO(12+4+4) Powerdip(12+2+2)
THERMAL DATA
Symbol Decription DIP SO Unit
Rth j-pins Thermal Resistance Junction-pins max. – 14 °C/W
Rth j-amb Thermal Resistance junction-ambient max. 80 50 (*) °C/W
Rth j-case Thermal Resistance Junction-case max. 14 –
(*) With 6sq. cm on board heatsink.
2/7
Aiv'lIiJIKA. TRADING CO.,
,4nnexeto Ambika No. loa, Shankara Park,
Bangalore . 560 004.
Telefax: 6613337, 6602160
e.mail: ambikaramesh@hotmail.com
Radial torque kg 5
Lateral torque kg-cm '1 5
Output shafts eJ 4.00,4.76,5.00,6.00,6.35 &7.00 (others on request)
Ambient' temperature operation .C -15...+55 . . .,...,... .
Transmission ratios
.,mm,
I .
- ---~'--
(5
J -~O~O~~.~~
J --GEAr~.~~AD (533
---~
- ._d~ ~.
,
o.
,
:;;:. --"---
_--nn__---
I I
~
/
25 28.1 i
nos.8 Bp,.tappings ! n-I :
On17PCD i 2J~L---i
'" ,
MOTOR DC 25 GEAR HEAD (528
a. ---- "I -' 01
"0--- -, Q G'
(5
:;;: '-..1
I I
\
4 nos. 8BA \ .29.L._. J 26.1 j
i
On 17.0PCD
47.9 -,_..1
""-,, '0.. .,.
LM339, LM239, LM2901,
LM2901V, NCV2901,
MC3302
PIN CONNECTIONS
Output 2 1 14 Output 3
Output 1 2 13 Output 4
VCC 3 12 GND
− Input 1 4 11 + Input 4
* )
1 4
+ Input 1 5
) * 10 − Input 4
− Input 2 6 9 + Input 3
*2 )
3
) *
+ Input 2 7 8 − Input 3
(Top View)
ORDERING INFORMATION
See detailed ordering and shipping information in the package
dimensions section on page 7 of this data sheet.
*For additional information on our Pb−Free strategy and soldering details, please
download the ON Semiconductor Soldering and Mounting Techniques
Reference Manual, SOLDERRM/D.
PIN DESCRIPTION
Fig.1 Pin configuration. Fig.2 Logic symbol. Fig.3 IEC logic symbol.
FUNCTION TABLE
INPUTS OUTPUT
nA nB nC nY
L L L H
X X H L
X H X L
H X X L
Notes
1. H = HIGH voltage level
L = LOW voltage level
X = don’t care
December 1990 3
MM74HC148 8-3 Line Priority Encoder
October 1987
Revised September 2001
MM74HC148
8-3 Line Priority Encoder
General Description Features
The MM74HC148 priority encoder utilizes advanced sili- ■ Typical propagation delay: 13 ns
con-gate CMOS technology. It has the high noise immunity ■ Wide supply voltage range: 2V–6V
and low power consumption typical of CMOS circuits, as
well as the speeds and output drive similar to LB-TTL.
This priority encoder accepts 8 input request lines 0–7 and
outputs 3 lines A0–A2. The priority encoding ensures that
only the highest order data line is encoded. Cascading cir-
cuitry (enable input EI and enable output EO) has been
provided to allow octal expansion without the need for
external circuitry. All data inputs and outputs are active at
the low logic level.
All inputs are protected from damage due to static dis-
charge by internal diode clamps to VCC and ground.
Ordering Code:
Order Number Package Number Package Description
MM74HC148M M16A 16-Lead Small Outline Integrated Circuit (SOIC), JEDEC MS-012, 0.150" Narrow
MM74HC148N N16E 16-Lead Plastic Dual-In-Line Package (PDIP), JEDEC MS-001, 0.300" Wide
5 3A 3Y 6
2Y 4 GND(1) 11 5A
3A 5 10 5Y 9 4A 4Y 8
3Y 6 9 4A 11 5A 5Y 10
7 8
13 6A 6Y 12
GND 4Y
Top view MBL760
MNA342
(1) The die substrate is attached to this pad using conductive die
attach material. It can not be used as a supply pin or input.
handbook, halfpage 1
1 2
1
3 4
1
5 6
handbook, halfpage
A Y
1
9 8 MNA341
1
11 10
1
13 12
MNA343
2003 Jul 23 4
LM78XX Series Voltage Regulators
May 2000
LM78XX
Series Voltage Regulators
General Description put, although this does improve transient response. Input by-
passing is needed only if the regulator is located far from the
The LM78XX series of three terminal regulators is available filter capacitor of the power supply.
with several fixed output voltages making them useful in a
For output voltage other than 5V, 12V and 15V the LM117
wide range of applications. One of these is local on card
series provides an output voltage range from 1.2V to 57V.
regulation, eliminating the distribution problems associated
with single point regulation. The voltages available allow
these regulators to be used in logic systems, instrumenta- Features
tion, HiFi, and other solid state electronic equipment. Al- n Output current in excess of 1A
though designed primarily as fixed voltage regulators these n Internal thermal overload protection
devices can be used with external components to obtain ad- n No external components required
justable voltages and currents.
n Output transistor safe area protection
The LM78XX series is available in an aluminum TO-3 pack- n Internal short circuit current limit
age which will allow over 1.0A load current if adequate heat
n Available in the aluminum TO-3 package
sinking is provided. Current limiting is included to limit the
peak output current to a safe value. Safe area protection for
the output transistor is provided to limit internal power dissi- Voltage Range
pation. If internal power dissipation becomes too high for the
LM7805C 5V
heat sinking provided, the thermal shutdown circuit takes
over preventing the IC from overheating. LM7812C 12V
Considerable effort was expanded to make the LM78XX se- LM7815C 15V
ries of regulators easy to use and minimize the number of
external components. It is not necessary to bypass the out-
Connection Diagrams
DS007746-3
DS007746-2
Top View
Bottom View Order Number LM7805CT,
Order Number LM7805CK, LM7812CT or LM7815CT
LM7812CK or LM7815CK See NS Package Number T03B
See NS Package Number KC02A