91
Visvesvaraya Technological University, Belgaum Project Work II (EC8P2) Report on LINE FOLLOWING ROBOT Submitted in partial fulfillment of the requirement of VIII semester ELECTRONICS & COMMUNICATION Engineering by AMITHASH E. PRASAD (1GA01EC002) Under the guidance of Internal Guide B. N. Manjunatha Reddy Assistant Professor Dept. of E&C, GAT Department of Electronics and Communication Engineering Global Academy of Technology, Bangalore-98 2005

LFR Report

Embed Size (px)

Citation preview

Page 1: LFR Report

Visvesvaraya Technological University, Belgaum

Project Work II (EC8P2) Report

on

LINE FOLLOWING ROBOT

Submitted in partial fulfillment of the requirement of VIII semester ELECTRONICS & COMMUNICATION Engineering by

AMITHASH E. PRASAD (1GA01EC002)

Under the guidance of

Internal Guide B. N. Manjunatha Reddy

Assistant Professor

Dept. of E&C, GAT

Department of Electronics and Communication Engineering

Global Academy of Technology, Bangalore-98

2005

Page 2: LFR Report

GLOBAL ACADEMY OF TECHNOLOGY (National Education Foundation)

Rajarajeshwari Nagar, Ideal Home Township, Off. Mysore Road, Bangalore – 560098.

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

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.

Signature of the Guide Signature of the HOD Signature of the Principal

(B. N. Manjunatha Reddy) (Prof.N. Narasimha Swamy) (Dr.T.R.Seetharam)

External Viva

Name of the Examiners Signature with date

1.

2.

Page 3: LFR Report

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 am highly indebted to N.Narasimha Swamy, H.O.D, Electronics & Communication

Department, GAT for his assistance and constant source of encouragement.

I wish to express my profound and deep sense of gratitude to H. S. Manjunatha Reddy,

Assistant professor, Department of Electronics and Communication, Project Co-ordinator, for

sparing his valuable time to extend help in every step of my project work.

I whole heartedly express my thanks to, B. N. Manjunatha Reddy, Assistant Professor,

Electronics & Communication Department, GAT for sparing time to go through every tiny

detail and give his valuable suggestions to make this project and report a success.

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

Page 4: LFR Report

CONTENTS

1. SYNOPSIS………………………………………………………………. 2. PREAMBLE……………………………………………………………...

2.1 INTRODUCTION…………………………………………....

2.2 PROBLEM DEFINITION………………………..………...

2.3 OBJECTIVES OF THE STUDY…………………………….

2.4 SCOPE OF STUDY………………………………………….

2.5 REVIEW OF LITERATURE………………………………..

2.6 APPLICATIONS……………………………………….........

2.7 LIMITATIONS……………………………………………....

2.8 METHODOLOGY…………………………………………...

3. THEORY………………………………………………………………....

3.1 THE DIFFRENTIAL STEERING SYSTEM………………..

3.2 D.C. MOTORS………………………………………………

3.3 H-BRIDGE MOTOR CONTROL…………………………...

3.4 INTELLIGENCE…………………………………………….

3.5 THE PIC 16F873 MICROCONTROLLER………………….

3.6 PWM SPEED CONTROL…………………………………...

3.7 THE PICMICRO CCP MODULES………………………….

4. DESIGN AND IMPLEMENTATION………………………………….

4.1 SCHEMATIC……………………………………….………...

4.2 PROCESS EXPLANATION…………………………..……...

4.3 FLOW CHART………………………………..…….………..

4.4 CODE………………………………………………………....

4.5 CODE EXPLANATION…………………………...…………

5. RESULT & CONCLUSION…………………………………………..

6. BIBLIOGRAPHY……………………………………………………….. 7. APPENDIX………………………………………………………………

01

03

03

04

04

05

05

06

06

07

09

09

10

11

14

16

18

18

22

22

35

37

40

51

55

56

58

Page 5: LFR Report
Page 6: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

1

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 sensor is an array of 7 IR LED-Phototransistor pairs arranged in the form of

an inverted V. The output of each sensor is fed into an analog comparator with the

threshold voltage (used to calibrate the intensity level difference of the line with respect

to the surface). These 7 signals (from each photo-reflective sensor) is given to a priority

encoder, the output of which to the microcontroller.

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.

Page 7: LFR Report

LINE FOLLOWING ROBOT

Figure 1.1: Block Diagram of the Line Following Robot

PIC 16F873 Microcontroller

H - Bridge DC Motor

Control

Left Motor

Right Motor

Clock 4 MHz

Main Power Supply

Motor Power Supply

HEX Inverter

Sensor Array

Analog

ComparatorsThreshold

Voltage

Priority Encoder

NOR Gate

Department of Electronics & Communication, GAT, Bangalore - 98

2

Page 8: LFR Report
Page 9: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

3

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

Page 10: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

4

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.

2.2. PROBLEM DEFINITION In the industry carriers are required to carry products from one manufacturing

plant to another which are usually in different buildings or separate blocks.

Conventionally, carts or trucks were used with human drivers. Unreliability and

inefficiency in this part of the assembly line formed the weakest link. The project is to

automate this sector, using carts to follow a line instead of laying railway tracks which are

both costly and an inconvenience.

2.3. OBJECTIVES OF THE STUDY

• The robot must be capable of following a line.

• It should be capable of taking various degrees of turns

• It must be prepared of a situation that it runs into a territory which has no line to

follow. (Barren land syndrome)

• The robot must also be capable of following a line even if it has breaks.

Page 11: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

5

• 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.

2.4. SCOPE OF STUDY The robot can be further enhanced to let the user decide whether it is a dark line

on a white background or a white line on a dark background. The robot can also be

programmed to decide what kind of line it is, instead of a user interface. The motor

control could be modified to steer a convectional vehicle, and not require a differential

steering system. The robot could be modified to be a four wheel drive. Extra sensors

could be attached to allow the robot to detect obstacles, and if possible bypass it and get

back to the line. In other words, it must be capable predicting the line beyond the

obstacle. Speed control could also be incorporated. Position and distance sensing devices

could also be built in which can transmit information to a mother station, which would be

useful in tracking a lost carrier.

2.5. REVIEW OF LITERATURE First and foremost, no robot could have been built to completion without a strong

hold on the microcontroller used. Most of the basic, intermediate, and advanced literature

about the PIC microcontroller was found in the book “Programming and Customizing the

PIC Microcontroller” by Myke Predko. His detailed explanation of every topic made it

possible to overcome many problems which were encountered during design and

implementation. The book also provided a programmer for the PIC microcontroller which

was an indispensable tool helping me experiment with algorithms rather than blindly copy

code from the NET.

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.

Page 12: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

6

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.

Page 13: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

7

• Use of IR even though solves a lot of problems pertaining to interference, makes it

hard to debug a faulty sensor.

• Lack of speed control makes the robot unstable at times.

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.

Page 14: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

8

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.

Page 15: LFR Report
Page 16: LFR Report

LINE FOLLOWING ROBOT

3. THEORY

3.1. THE DIFFERENTIAL STEERING SYSTEM

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.

Figure 3.1: The Differential steering model

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

Department of Electronics & Communication, GAT, Bangalore - 98

9

Page 17: LFR Report

LINE FOLLOWING ROBOT

in radians ( ). is the speed at the center point on the main

axle. In this discussion, we will treat the axle's center point as the origin of the simulated

robot's frame of reference.

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.

3.2. D.C. MOTORS DC motors are widely used, inexpensive, small and powerful for their size.

Reduction gearboxes are often required to reduce the speed and increase the torque output

of the motor. Unfortunately more sophisticated control algorithms are required to achieve

accurate control over the axial rotation of these motors. Although recent developments in

stepper motor technologies have come a long way, the benefits offered by smooth control

and high levels of acceleration with DC motors far outweigh any disadvantages.

Department of Electronics & Communication, GAT, Bangalore - 98

10

Page 18: LFR Report

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.

Example specifications of the motors used are given below:

Characteristic Value

Operating Voltage: 6V to 12V

Operating Current: 2A Max. (Stall)

Speed: 2400 rpm

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.

×

3.3. H-BRIDGE MOTOR CONTROL DC motors are generally bi-directional motors. That is, their direction of rotation

can be changed by just reversing the polarity. But once the motors are fixed, control

becomes tricky. This is done using the H-Bridge. The figure is given below.

A B C D ACTION

1 0 0 1 CLOCKWISE

0 1 1 0 COUNTER-CLOCKWISE

0/1 0/1 1/0 1/0 BRAKE

ANY OTHER STATE FORBIDDEN

Department of Electronics & Communication, GAT, Bangalore - 98

11

Page 19: LFR Report

LINE FOLLOWING ROBOT

Figure 3.2: The H-Bridge Using Relays.

The Explanation is simple, If A & D are turned on, then the current flows in the direction

shown in the figure below.

Figure 3.3: Clockwise rotation

If B & C are turned on, then the motor rotates in counter clockwise direction.

Figure 3.4: Counter-Clockwise rotation

Department of Electronics & Communication, GAT, Bangalore - 98

12

Page 20: LFR Report

LINE FOLLOWING ROBOT

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.

Figure 3.5: H-Bridge using transistors.

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.

Figure 3.6: Enhanced H-Bridge

Department of Electronics & Communication, GAT, Bangalore - 98

13

Page 21: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

14

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.

Page 22: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

15

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.

Page 23: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

16

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.

3.5. THE PIC 16F873 MICROCONTROLLER The PIC microcontrollers are a group of 8 – bit microcontrollers of RISC

(Reduced Instruction Set Computer) architecture. It has various features few of which are

given below.

Microcontroller Core Features:

• Only 35 single word instructions to learn

• All single cycle instructions except for program branches which are two cycle

• Operating speed: DC - 20 MHz clock input

• 4K x 14 words of FLASH Program Memory,

• Up to 192 x 8 bytes of Data Memory (RAM)

Page 24: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

17

• Up to 128 x 8 bytes of EEPROM Data Memory

• Interrupt capability (up to 13 sources)

• Eight level deep hardware stack

• Direct, indirect and relative addressing modes

• Power-on Reset (POR)

• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)

• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable

operation

• Programmable code protection

• Power saving SLEEP mode

• Selectable oscillator options

• Low power, high speed CMOS FLASH/EEPROM technology

• Fully static design

• In-Circuit Serial Programming (ICSP) via two pins

• Single 5V In-Circuit Serial Programming capability

• Processor read/write access to program memory

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)

Page 25: LFR Report

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.

3.6. PWM SPEED CONTROL

Figure 3.7: PWM signal

∫= vdtt

A 1

∫ +=ONt

dtt

A0

51

ρ×== Vt

tA ON 1212

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.

3.7. THE PICMICRO CCP MODULES Each CCP (Capture/Compare/PWM) module contains a 16-bit register which can

operate as a 16-bit capture register, as a 16-bit compare register or as a 10-bit PWM

master/slave Duty Cycle register. The CCP modules are identical in operation, with the

exception of the operation of the special event trigger.

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.

Department of Electronics & Communication, GAT, Bangalore - 98 18

Page 26: LFR Report

LINE FOLLOWING ROBOT

Generic Name CCP1 CCP2 Comment

CCPxCON

CCPRxH

CCPRxL

CCPx

CCP1CON

CCPR1H

CCPR1L

CCP1

CCP2CON

CCPR2H

CCPR2L

CCP2

CCP control register

CCP High byte

CCP Low byte

CCP pin

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.

Figure 3.8: The PICmicro PWM module

Department of Electronics & Communication, GAT, Bangalore - 98

19

Page 27: LFR Report

LINE FOLLOWING ROBOT

Figure 3.8: The PWM output

When timer 2 just crosses PR2, it is forced to zero and the second comparator

asserts a high, setting the RS flip-flow, thus the CCPx pin goes high. Immediately, as the

timer 2 is reset the output of the second comparator goes back to 0 but the flip-flop holds

the high state. As timer 2 counts up and TMR2:Qx (10 bit, where Qx is the 2bit internal

clock which increments every clock cycle) reaches the value DCxB9:DCxB0 (10 bit,

formed with the CCPRxH concatenated with the bits CCPxCON<5:4>), the first

comparator goes high thus resetting the flip-flop forcing the CCPx pin to go low. This

state is maintained till timer 2 counts to PR2 again and the whole process repeats thus

generating a PWM signal at the CCPx pin. If both the CCP modules are configured as

PWM mode, then the timer 2 module (which decides the period) will be used by both the

modules. This effectively means that both the PWM signals at CCP1 & CCP2 pins will

have the same period but can have different duty cycle which depends on DC1B9:DC1B0

& DC2B9:DC2B0. This process is shown in the above diagram. The content of CCPRxL

is latched to the CCPRxH register every time timer counts up to PR2. Any change in the

duty cycle must be written to the CCPRxL register and not the CCPRxH register.

periodPWMcycledutyPWM

For example

Desired PWM frequency is 78.125 kHz, Fosc = 20 MHz & TMR2 prescale = 1

1/78.125 kHz= [(PR2) + 1] • 4 • 1/20 MHz • 1

12.8 μ s = [(PR2) + 1] • 4 • 50 ns • 1

PR2 = 63

Department of Electronics & Communication, GAT, Bangalore - 98

20

Page 28: LFR Report

LINE FOLLOWING ROBOT

To achieve a 25% duty cycle, then PWM duty cycle = 12.8μ s10025

× = 3.2 sμ .

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.

Department of Electronics & Communication, GAT, Bangalore - 98

21

Page 29: LFR Report
Page 30: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

22

4. DESIGN AND IMPLEMENTATION

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.

Page 31: LFR Report

LINE FOLLOWING ROBOT

Figure 4.1 Schematic – Main Board

Department of Electronics & Communication, GAT, Bangalore - 98

23

Page 32: LFR Report

LINE FOLLOWING ROBOT

Figure 4.2: Sensor array

Department of Electronics & Communication, GAT, Bangalore - 98

24

Page 33: LFR Report

LINE FOLLOWING ROBOT

4.1.1. THE MICROCONTROLLER

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.2 CRYSTAL OSCILLATOR

Figure 4.3: Crystal oscillator

The clock frequency is provided by one 4Mhz crystal which is connected across

the OSC1 & OSC2 pins as shown above. This provides an instruction execution time of

1μ s.

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.

Department of Electronics & Communication, GAT, Bangalore - 98

25

Page 34: LFR Report

LINE FOLLOWING ROBOT

4.1.4. VOLTAGE REGULATOR

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.

Figure 4.4: Voltage Regulators

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.

Department of Electronics & Communication, GAT, Bangalore - 98

26

Page 35: LFR Report

LINE FOLLOWING ROBOT

4.1.5. D.C. MOTORS

Figure 4.5: Geared D.C. Motor

Geared D.C. motors were used which can operate in the range from 0V to .

The D.C. motors have a speed of 2400rpm and a torque of 15gm-cm. The gears decrease

the speed to 30rpm at 6V and thus considerably increasing the torque so that the robot can

carry the load of its frame and the lead-acid battery. Two such motors are used in the rear

of the robot, and a dummy castor is fixed to the front to stabilize the robot.

V12±

4.1.6. THE H-BRIDGE CONTROL HARDWARE

Figure 4.6: The motor control.

Department of Electronics & Communication, GAT, Bangalore - 98

27

Page 36: LFR Report

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.

IN1 IN2 IN3 IN4 OPERATION

1 0 1 0 BOTH MOTORS FORWARD

(MOVE FORWARD)

0 1 0 1 BOTH MOTORS BACKWARD

(MOVE BACKWARD)

1 0 0 1 RIGHT MOTOR BACKWARD

LEFT MOTOR FORWARD

(TURN RIGHT)

0 1 1 0 RIGHT MOTOR FORWARD

LEFT MOTOR BACKWARD

(TURN LEFT)

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 LD 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.

4.1.7. PWM SPECIFICATIONS & CALCULATIONS The L293D chip can operate on PWM signals up to 5kHz, which was decided to be used.

1/5kHz = [(PR2) + 1] × 4 × (1/4MHz) × 1 200 sμ = [(PR2) + 1] 1× sμ PR2 = 200-1 = 199 200 ≈

Department of Electronics & Communication, GAT, Bangalore - 98

28

Page 37: LFR Report

LINE FOLLOWING ROBOT

Three speeds are used for the line following robot and their corresponding duty cycles are 0%, 50% & 96%. These calculations are shown below. For 0% duty cycle the value to be loaded is obviously zero, For 50 % duty cycle,

PWM duty cycle = 200μ s10050

× = 100 sμ .

100 μ s = [DCx] •0.25 sμ • 1

DCx = 400 = 110010000b

Thus, clear the bits DCxB1 & DCxB0 and load 1100100b i.e. 100 into the CCPRxL

register.

For 96 % duty cycle,

PWM duty cycle = 200μ s10096

× = 192 sμ .

192 μ s = [DCx] •0.25 sμ • 1

DCx = 768 = 1100000000b

Thus, clear the bits DCxB1 & DCxB0 and load 11000000b i.e. 192 into the CCPRxL

register.

4.1.8. THE IR SENSORS

The MOC7811 consists of an infrared emitting diode (λ = 950nm) and an NPN

silicon phototransistor mounted to face each other on a converging optical axis in a black

plastic housing. The phototransistor responds to radiation from the emitting diode only

when no object is present within its field of view. This sensor is physically modified so

that the emitter and detector face the same direction and thus the modified sensor serves

the purpose of an optical-reflective sensor. The sensor has a focal length of 8mm, thus the

surface must be at an optimum distance of 1.6cm. The original and modified sensors are

shown below.

Figure 4.7: LEFT: Original sensor, RIGHT: modified sensor

Department of Electronics & Communication, GAT, Bangalore - 98

29

Page 38: LFR Report

LINE FOLLOWING ROBOT

Figure 4.8: Reflective sensor

If a reflective (white) surface is present at the optimal distance (d = 1.6cm) then

the reflected waves will strike the detector which on radiation will start to conduct. The

circuit diagram is shown in the figure below.

Figure 4.9: The sensor

The drop across the emitter when forward biased is around 1.4V. According to the

data sheets, to have sustained radiation, a max of 40mA must flow through to avoid

damage. A safe margin is allowed and a current of 16mA is considered for the design.

IdVdVccR −

=

for, Vcc = 5V

Vd = 1.4V

Id = 16mA

R is calculated to be approximately 220Ω .

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

Department of Electronics & Communication, GAT, Bangalore - 98

30

Page 39: LFR Report

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.

Figure 4.10: Comparator transfer characteristics.

The sensor circuit is redrawn using the comparator, and this is shown below.

Figure 4.11: Sensor circuit redrawn with the comparator

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.

Department of Electronics & Communication, GAT, Bangalore - 98

31

Page 40: LFR Report

LINE FOLLOWING ROBOT

4.1.10. SENSOR ARRAY

7 sensors are totally used. They are in the form shown in the figure below, also

their outputs are also shown. The top view is chosen as it would be easier to infer the

process involved.

Figure 4.12: The sensor array

The sensors are mounted on a separate board along with the biasing resistors and a

2 pin connector supplies the power to the sensor array. And the output of each sensor is

connected to the main board via an 8 pin connector to the comparators on the main board.

4.1.11. THE PRIORITY ENCODER

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.

Department of Electronics & Communication, GAT, Bangalore - 98

32

Page 41: LFR Report

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.

Figure 4.13: The priority encoder

4.1.12. THE NO SURFACE LOGIC

Figure 4.14: The no surface logic

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.

Department of Electronics & Communication, GAT, Bangalore - 98

33

Page 42: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

34

4.1.13. MICROCONTROLLER SENSOR INPUTS

Thus totally the microcontroller gets 5 inputs from the sensor circuitry, 3 (A2 – A0)

decide what to do when on the line, The GS output tells whether the robot is on the line or

not, and finally the NO_SURFACE output from the NOR gate tells the microcontroller

whether the robot sees a surface or not. Below is the complete description about what

each input mean and what needs to be done.

NS GS

A2

A1

A0

STATE IN

ACTION

1 X

X

X

X

No surface is detected

Stop the motors

0 1

X

X

X

No line is detected

Execute the no line code (specially designed algorithm)

0 0

0

0

0

A detects the line

Sharp turn left

0

0

0

0

1

B detects the line

Sharp turn right

0

0

0 1

0

C detects the line

Turn left

0

0

0

1

1

D detects the line

Turn right

0

0

1

0

0

E detects the line

Move left

0

0 1 0 1 F detects the line Move right

0

0 1 1 0 G detects the line Go straight

0 0 1 1 1 Forbidden state Software reset the processor

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

Page 43: LFR Report

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.

4.2. PROCESS EXPLANATION

Figure 4.15: The line following process.

As shown in the figure above, is a typical situation involved. At every sampled

time the commands executed by the microcontroller is also shown. From the above

figure, it should be clear about the software requirements.

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

Department of Electronics & Communication, GAT, Bangalore - 98

35

Page 44: LFR Report

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.

Figure 4.17: Spiral movement during line find mode.

The surface is sampled every 2.1ms using the timer 0 interrupt routine. This

implies that the line is sampled 476 times in a second. From observations, the robot

travels at a maximum speed of around 10cm/sec. In other words, 47.6 samples are taken

per cm, or 4.76 samples per mm. This is more than ever required! Due to the fact that the

robot can remember and follow the previous task when its sensors do not see a line,

enables the robot to trace a sharp turn, even if in case the robot runs off the line while

making the turn.

Figure 4.18: Robot’s line approximation

Department of Electronics & Communication, GAT, Bangalore - 98

36

Page 45: LFR Report

LINE FOLLOWING ROBOT

4.3. FLOW CHART

START

• Initialize ports appropriately • Set CCP1 & CCP2 modules as

PWM. • Initialize PWM period to 200 sμ . • Initialize timer 0 to overflow

every 2.1ms • Enable TMR0 overflow interrupt • Clear/ Initialize temporary

registers

Wait for interrupt

STOP

TMR0 INTERRUPT HANDLER

Is surface detected

Stop motors NO

YES

Is line detected

? No line code

A

YES

NO

C

RETI

Department of Electronics & Communication, GAT, Bangalore - 98

37

Page 46: LFR Report

LINE FOLLOWING ROBOT

A

Get input from portB, copy to command register

Adjust command register to have just 3 bits

CALL motor subroutine

Is command different

from previous?

YES

NO

Error?

YES

C

RETI

NO

Department of Electronics & Communication, GAT, Bangalore - 98

38

Page 47: LFR Report

LINE FOLLOWING ROBOT LINE FOLLOWING ROBOT

MOTOR

Department of Electronics & Communication, GAT, Bangalore - 98

39 Department of Electronics & Communication, GAT, Bangalore - 98

39

Cmd=000

Cmd=001

Cmd=010

Cmd=011

Cmd=100

Cmd=101

Cmd=110

Report Error

SHARP TURN LEFT Left motor = reverse, Right motor = forward, Both motors = high speed.

RETURN

SHARP TURN RIGHT Left motor = forward, Right motor = reverse, Both motors = high speed.

TURN LEFT Both motors = forward Left motor = zero speed Right motor = high speed

TURN RIGHT Both motors = forward Left motor = high speed Right motor = zero speed

MOVE LEFT Both motors = forward Left motor = low speed Right motor = high speed

MOVE RIGHT Both motors = forward Left motor = high speed Right motor = low speed

GO STRAIGHT Both motors = forward Both motors = high speed

Report no error

YES

NO

YES

NO

YES

NO

YES

NO

YES

NO

YES

NO

YES

NO

Page 48: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

40

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

DELH ;USED FOR DELAY REUTINES

DELL ;

PREV_COMMAND_WORD ;USED AS A MEMORY OF THE PREVIOUS CW

TEMP_FLAG

TIME_COUNT:2

COMMAND_WORD

Page 49: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

41

------------------------------------------|

| 1 | 0 | DESCRIPTION |

0 | 0 | 0 | SHARP TURN LEFT |

0 | 1 | 0 | TURN LEFT |

| 1 | MOVE RIGHT |

| X | X | X | X | X | 1 | 1 | 0 | GO STRAIGHT |

| X | X | 1 | 1 | 1 | DONT CARE |

*************************************************

0X1F

NBANK1 ;RB0-RB4 SET AS INPUTS,

;RB5-RB7 AS OUTPUTS

; ENABLE WEAK PULLUPS ON PORTB

;TMR0 CLK SOURCE = INSTRUCTION CLK

;PRESCALAR SET TO TMR0 & SET TO 1:8

;SENSORS SAMPLED EVERY 2.05ms

;|--------

;| 7 | 6 | 5 | 4 | 3 | 2

;|---|---|---|---|---|---|---|---|------------------|

;| X | X | X | X | X |

;| X | X | X | X | X | 0 | 0 | 1 | SHARP TURN RIGHT |

;| X | X | X | X | X |

;| 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

;

;| X | X | X

;|--------------------------------------------------|

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

MOVWF TRISB I

CLRF TRISA INBANK1

MOVLW 0X02

MOVWF OPTION_REG INBANK1

Page 50: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

42

N ; RESET THE CCP1 MODULE

;00001100

DE SET TO PWM MODE AND THE

;LOWER TWO BITS OF DUTY CYCLE

E SET TO PWM MODE AND THE

O BITS OF DUTY CYCLE

D

;SET TO HIGHSPEED DUTY CYCLE

L ;SET TO HIGHSPEED DUTY CYCLE

T ;INITIALIZE TIME COUNT TO ZERO

***************************************

ELY (WAIT FOR INTERRUPT)

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 CCP1CO

CLRF CCP2CON ; RESET THE CCP2 MODULE

MOVLW 0X0C

MOVWF CCP1CON ;CCP MO

;ARE SET TO 0.

MOVWF CCP2CON ;CCP MOD

;LOWER TW

;ARE SET TO 0.

MOVLW HIGHSPEE

MOVWF CCPR1L

MOVWF CCPR2

BSF INTCON,GIE ;ENABLE INTERRUPTS

CLR16F TIME_COUN

MOVLW 0X07

MOVWF PREV_COMMAND_WORD

CLRF TEMP_FLAG

;********************

GOTO $ ;LOOP HERE INDEFINAT

;***********************************************************

#INCLUDE "SUBROUTINES.INC"

;***********************************************************

END

Page 51: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

43

;BANK SELECT MACROS

TERS NOT IN BANK0

4.4.2. LFR.INC

;MACRO DEFINITIONS

;GENERAL MACROS AND DEFINES.....

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

;DEFINES TO USE FOR REGIS

#DEFINE INBANK1 ^ 0X080

#DEFINE INBANK2 ^ 0X100

#DEFINE INBANK3 ^ 0X180

Page 52: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

44

ILATOR MACROS

;AFFECTS CARRY FLAG ON OVERFLOW

1,F

C

ENDM

AFFECTS ZERO FLAG ON ZERO

US,Z

DECF VAR+1,F

FLAGS ARE UNKNOWNAND SHOULD NOT BE

VAR2

MOVWF VAR1+1

W VAR2

;ZERO FLAG IS AFFECTED

CLRF VAR

CONSTANT FORWARD = 0X03 ;0011

CONSTANT ST_LEFT = 0X02 ;0001

CONSTANT ST_RIGHT = 0X01 ;0010

;16BIT MANUP

INC16F MACRO VAR

INCF VAR,F

BTFSC STATUS,Z

INCF VAR+

BCF STATUS,C

MOVF VAR+1,W

BTFSC STATUS,Z

BSF STATUS,

DEC16F MACRO VAR ;

DECF VAR,F

INCF VAR,W

BTFSC STAT

ENDM

MOV16LW MACRO VAR1,VAR2 ;

USED

MOVLW HIGH

MOVLW LO

MOVWF VAR1

ENDM

CLR16F MACRO VAR

CLRF VAR+1

ENDM

;CONSTANTS USED

Page 53: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

45

00 ;0000,

;PR2 = 0X0C8 = 200

ED = 0X064 ;=100, DUTY CYCLE = 50%

SPEED = 0X0C0 ;=192 DUTY CLCLE = 96%

.

B,3

PORTB,4

ES OF THE TEMP_FLAG USED FOR VARIOUS OPERATIONS

THE NO_LINE INPUT (PAST VALUE)

MP_FLAG,1 =>

NO_LINE INPUT (PRESENT VALUE)

_FLAG,2 =>

WAS A FORWARD,

OUS WAS NOT A FORWARD

FIND_MODE = TEMP_FLAG,3 =>

HAT LINE CODE IN?

, FOLLOWING THE LAST COMMAND

->

= TEMP_FLAG,4 =>

OF NO LINE CODE?

MP_FLAG,0

_PR TEMP_FLAG,1

EFINE PREVIOUS_STATE TEMP_FLAG,2

P_FLAG,3

CONSTANT BACKWARD = 0X

;NEVER USED, KEPT FOR FUTURE

CONSTANT LOWSPE

CONSTANT HIGH

;DEFINES FOR LFR..

#DEFINE NO_LINE PORT

#DEFINE NO_SURFACE

;DEFIN

; NO_LINE_PA = TEMP_FLAG,0 =>

; USED FOR DEBOUNCING

; NO_LINE_PR = TE

;USED FOR DEBOUNCING THE

; PREVIOUS_STATE = TEMP

;0 -> PREVIOUS

;1 -> PREVI

; LINE_

;W MODE WAS THE NO

;0 -> WAITING FOR A SEC

;1 LINE FIND MODE

; NOT_LF_FIRST

;FIRST PART

;0 -> YES 1 -> NO

#DEFINE NO_LINE_PA TE

#DEFINE NO_LINE

#D

#DEFINE LINE_FIND_MODE TEM

#DEFINE NOT_LF_FIRST TEMP_FLAG,

Page 54: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

46

LSE CONTINUE WITH ROUTINE

BTFSS NO_SURFACE

TECTED

ODE OF THE NO_LINE INPUT

CALL DELAY_FF_US ;TMP_FLAG,1 IS THE DEBOUNCED INPUT

NCED INPUT IS 1,

S NO LINE

;ELSE ITS JUST A FLICKER,

;CONTINUE TO MODIFIERS

BTFSC NO_LINE_PR

MOVF PORTB,W

ANDLW 0X07

4.4.3. ROUTINE.INC

TMR0_ROUTINE:

BTFSS INTCON,T0IF

GOTO INITIALIZATION

;RESET IF A WRONG INTERRUPT IS ENCOUNTERED,

;E

CLRF TMR0

SURFACE_CHECK:

GOTO LINE_CHECK

CLRF CCPR2L

CLRF CCPR1L ;STOP BOTH MOTORS IF NO SURFACE IS DE

GOTO EXIT_T0

LINE_CHECK:

BCF NO_LINE_PA ;DEBOUNSING C

BTFSC NO_LINE

BSF NO_LINE_PA

;IF THE DEBOU

;THEN ROBO SEE

BSF NO_LINE_PR

BTFSC NO_LINE_PA

BTFSS NO_LINE

BCF NO_LINE_PR

NOP

GOTO NO_LINE_CODE

MODIFIERS:

BCF LINE_FIND_MODE

BCF NOT_LF_FIRST

MOV16LW TIME_COUNT,0X094C

Page 55: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

47

ND_WORD

_COMMAND_WORD,W

AND_WORD

OTORS ;16us

THE DONT CARE STATE IS REACHED,

;PROBABLY ERROR IN INPUTS

;SURE IT IS NOT A SOFTWARE PROBLEM.

;ELSE CARRY ON

OVER,

OLLOW THE

;REMEMBERED STATE)

;IF TIME_COUNT IS 0 (~5SEC) THEN

;SHIFT TO LINE FIND MODE

A:

E_FIND_MODE ;START NO LINE CODE

T TO TURN RIGHT

IS THIS THE FIRST OF NO LINE CODE

MODIFY MOTORS

;IS THIS THE FIRST OF NO LINE CODE

MOVWF COMMA

XORWF PREV

BTFSC STATUS,Z

GOTO EXIT_T0

MOVF COMMAND_WORD,W

MOVWF PREV_COMM

CALL M

SUBLW 0X00

BTFSS STATUS,Z

GOTO INITIALIZATION ;

;GOTO INITIALIZATION JUST TO MAKE

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

;JUST EXIT ROUTINE (F

GOTO EXIT_T0

BCF NOT_LF_FIRST

NL

BSF LIN

MOVLW 0X03 ;SE

BTFSS NOT_LF_FIRST ;

CALL MOTORS ;IF YES

BTFSC NOT_LF_FIRST

GOTO SKIP_INI

Page 56: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

48

C ;INITILIZE TIME_COUNT

TURN ZERO EVERY SECOND

;NO LONGER THE FIRST LEG

NT,0X01DC ;INITILIZE TIME_COUNT TO

;TURN ZERO EVERY SECOND

L

*****************************************

ECFSZ DELL,1

MOV16LW TIME_COUNT,0X01D

;TO

SKIP_INI:

BSF NOT_LF_FIRST

DEC16F TIME_COUNT

BTFSS STATUS,Z

GOTO EXIT_T0

MOV16LW TIME_COU

MOVF CCPR2L,W ;INCREMENT CCP2 REG BY 10

ADDLW 0X0A

MOVWF CCPR2L

SUBLW HIGHSPEED

BTFSC STATUS,C

GOTO EXIT_T0

CLRF CCPR2

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:

D

GOTO DELLOOP

NOP

RETURN

;***********************************************************

Page 57: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

49

ND IS IN W BEFORE CALLING,

HARP_TURN_LEFT

;ERROR INDICATOR, WRONG STATE

;LOW SPEED TO RIGHT MOTOR

;HIGH SPEED TO LEFT MOTOR

FORWARD ;BOTH MOTORS FORWARD

;GIVEN BY THE PREVIOUS_STATE FLAG

;RETURN FROM KNOWN STATE

;HIGH SPEED TO RIGHT MOTOR

;LOW SPEED TO LEFT MOTOR

CCPR1L

;BOTH MOTORS FORWARD

TE ;CHANGE PORTA ONLY IF DIFFERENT

TA ;GIVEN BY THE PREVIOUS_STATE FLAG

_STATE

RETLW 0X00 ;RETURN FROM KNOWN STATE

MOTORS:

;TABLE

;COMMA

ADDWF PCL,F ;EXECUTE THE APPROPRIATE CODE

GOTO S

GOTO SHARP_TURN_RIGHT

GOTO TURN_LEFT

GOTO TURN_RIGHT

GOTO MOVE_LEFT

GOTO MOVE_RIGHT

GOTO GO_STRAIGHT

RETLW 0X0FF

MOVE_RIGHT

MOVLW LOWSPEED

MOVWF CCPR2L

MOVLW HIGHSPEED

MOVWF CCPR1L

MOVLW

BTFSC PREVIOUS_STATE ;CHANGE PORTA ONLY IF DIFFERENT

MOVWF PORTA

BCF PREVIOUS_STATE

RETLW 0X00

MOVE_LEFT

MOVLW HIGHSPEED

MOVWF CCPR2L

MOVLW LOWSPEED

MOVWF

MOVLW FORWARD

BTFSC PREVIOUS_STA

MOVWF POR

BCF PREVIOUS

Page 58: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

50

T

;ZERO SPEED TO RIGHT MOTOR

ORS FORWARD

GE PORTA ONLY IF DIFFERENT

;GIVEN BY THE PREVIOUS_STATE FLAG

;RETURN FROM KNOWN STATE

IGHSPEED ;HIGH SPEED TO RIGHT MOTOR

;ZERO SPEED TO LEFT MOTOR

TE ;CHANGE PORTA ONLY IF DIFFERENT

_STATE FLAG

ETURN FROM KNOWN STATE

ARP_TURN_RIGHT

HIGHSPEED ;HIGH SPEED TO BOTH MOTORS

GER FORWARD

ETURN FROM KNOWN STATE

TURN_RIGH

CLRF CCPR2L

MOVLW HIGHSPEED

MOVWF CCPR1L ;HIGH SPEED TO LEFT MOTOR

MOVLW FORWARD ;BOTH MOT

BTFSC PREVIOUS_STATE ;CHAN

MOVWF PORTA

BCF PREVIOUS_STATE

NOP

RETLW 0X00

TURN_LEFT

MOVLW H

MOVWF CCPR2L

CLRF CCPR1L

MOVLW FORWARD ;BOTH MOTORS FORWARD

BTFSC PREVIOUS_STA

MOVWF PORTA ;GIVEN BY THE PREVIOUS

BCF PREVIOUS_STATE

NOP

RETLW 0X00 ;R

SH

MOVLW

MOVWF CCPR2L

MOVWF CCPR1L

MOVLW ST_RIGHT ;REVERSE RIGHT MOTOR

MOVWF PORTA

BSF PREVIOUS_STATE ;PREVIOUS STATE NO LON

NOP

NOP

RETLW 0X00 ;R

Page 59: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

51

EFT

******************************************

or the definition of the work-area. When using this

rectiv

ted in the order from the address which was specified by the operand

N PROCESS

• Port A & C are set as outputs

• Port B is set as inputs

SHARP_TURN_L

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

;*****************

4.5 CODE EXPLANATION4.5.1. LFR.ASM

LABLE DEFINATION

CBLOCK directive was used f

di e, work-areas which were defined between CBLOCK and ENDC are

automatically alloca

of CBLOCK.

INITILIZATIO

Page 60: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

52

ave a pre scale of 1:8

is made to have a pre & post scale of 1:1

et and put in PWM mode

ble interrupts

nk3 macros are used to set the bank select bits in the status register to

bank 0 is

e messages shown after build.

The

able in small end-in format.

• e specified

immediate 16 bit number

ant declarations are used to make understanding the

e purpose is lost if the reader skips this section. In fact, even though

ne presented, it must be the first one to read.

make sure that no rogue interrupt has occurred. Then the NO_SURFACE

in is checked; if high, both the motors are stopped and the routine is exited. If the

implies that the robot is actually on a surface and the

rou e

• Timer 0 is set to h

Period register is initialized

• Timer 2 is turned ON and

• Both CCP modules are res

Initialize duty cycle registers of both the modules to high speed

• Initialize variables & ena

Once done the goto $ will cause the processor to loop indefinitely and thus waiting for an

interrupt.

4.5.2. LFR.INC

• Bank0 to ba

put the processor in the required bank.

The INBANK1 to INBANK3 defines are used whenever a register not in •

accessed. This removes th

16 bit macros are used to simplify the code whenever 16bit numbers and

variables are manipulated. The macros are

le in small end-in format. • INC16F – increment a 16 bit variab

ecrements a 16 bit vari• DEC16F – d

MOV16LW – loads the 16 bit variable in small end-in format with th

• CLR16F – clears a 16 bit variable in small end-in format.

The rest of the “defines” and const

code easier. But th

this section is the second o

4.5.3. ROUTINE.INC

The first lines of the code check if the interrupt was actually a timer 0 overflow

interrupt just to

p

NO_SURFACE pin is low, it

tin can continue.

Page 61: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

53

high in software. That is, the pin is read,

the a

Next, the NO_LINE pin is de-bounced

n s mpled again after 256 sμ and compared with the previous value. The no line

sec puts were the

sam ot can see the line, and thus

con u

keep only the lower 3 bits and set all others to 0. This register is now compared

ith its previous value stored at PREV_COMMAND_WORD. If they are the same, then

in instructing the motors again, thus exiting the routine; if they are

diff n

subrou appropriately.

TIME_COUNT is used.

As the timer 0 interrupts every 2.1ms, to get a delay of 5 seconds, a value of 2380

(0X

rect way of achieving a 5 second delay. Once

the ew user defined flag

bits e

p, 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

CCPR2L is reset

ented beyond HIGHSPEED. Note that every time, the timer 0

tion of the code is executed only when both the past and the present in

e and equal to 1. Otherwise it is assumed that the rob

tin ed onto the modifiers section of the code.

PORT B is read and copied into the COMMAND_WORD register. Then it is

masked to

w

there is no point

ere t then, COMMAND_WORD is loaded into the W register and the motor

tine is called which modifies the motors

In the NO_LINE_CODE section, a 16 bit variable called

094C) is put in the TIME_COUNT register initially. This is decremented, till it goes

to zero, the routine is exited. This is an indi

5 seconds are over, then a new section of the code is entered. A f

ar used to remember which mode was going on.

Once the 5 seconds are u

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.

back to zero when it increm

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

Page 62: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

54

require

lu

outine are as shown in the table below.

A user defined flag remembers if the last operation was a forward or something else. This

makes

d turns. Before the subroutine is called, the W register must hold the

COMMAND_WORD. This va e 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 subr

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.

COMMAND WORD

ACTION

0 SHARP TURN LEFT

Left motor = reverse, RA1 = 0 Right motor = forward, RA0 = 1 Both motors = high speed. (CCPR1L & CCPR2L)

1 SHARP TURN RIGHT

Left motor = forward, RA1 = 1 Right motor = reverse, RA0 = 0 Both motors = high speed. (CCPR1L & CCPR2L)

2

TURN LEFT

Both motors = forward, RA1 & RA0 = 1 Left motor = zero sRight motor = high

peed (CCPR2L) speed (CCPR1L)

3T

Both motors = forward, RA1 & RA0 = 1 URN RIGHT Left motor = high speed (CCPR2L)

Right motor = zero speed (CCPR1L) 4 MOVE LEFT

Both motors = forward, RA1 & RA0 = 1 Left motor = low speed (CCPR2L) Right motor = high speed (CCPR1L)

5

MOVE RIGHT

Both motors = forward, RA1 & RA0 = 1 Left motor = high speed (CCPR2L) Right motor = low speed (CCPR1L)

6

GO STRAIGHT

Both motors = forward, RA1 & RA0 = 1 Both motors = high speed (CCPR2L & CCPR1L)

7

ERROR

Return with 0XFF in W register

This completes the code explanation. The code occupies 191 program memory words.

Page 63: LFR Report
Page 64: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

55

5. RESULT AND CONCLUSION

The Line following robot was finally completed. A lot of effort was put into the

design, implementation and days of toil in front of the computer, writing and debugging

the code. The robot was finally running with a few glitches here and there which were

sorted in the later revisions of the firmware. The line following robot still has a few short-

comings but achieves most of the objectives.

I earned a lot of knowledge on micro-controllers, a deeper & clearer view of the

architecture, ports & all other functional blocks was achieved. Did a lot of research on

robotics and already have my next project planned. had a peek look at all simple

functional parts of the project like the crystal oscillator, logic gates and the works. Well,

these were the topics that we have already dealt with, but I must be honest and admit that

there were various practical issues which one would learn only during a project. There’s a

lot of learning & yet not the end, learning is a continuous never ending process but is

definitely fun.

Page 65: LFR Report
Page 66: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

56

6. BIBLIOGRAPHY BOOKS Programming and Customizing the PIC microcontroller

by Myke Predko Second edition – McGraw Hill

PICmicro Mid-Range MCU Family Reference Manual

by MICROCHIP

Design with PIC microcontrollers

by John B. Peatman – PEARSON Education

PIC Robotics, A beginner’s guide to robotics projects using the PICmicro

by John Iovine – McGraw Hill

Digital logic and computer design

by M. Morris Mano - Prentice – Hall of India PVT limited

Digital Systems Principles & applications

by Ronald J. Tocci Sixth Edition - Prentice – Hall of India PVT limited

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

Go Robotics.NET, this page has many useful links to robotics articles.

http://www.gorobotics.net/articles/index.php

Carnegie Mellon Robotics Club. This is the links page with lots of useful resources

http://www.roboticsclub.org/links.html

Page 67: LFR Report

LINE FOLLOWING ROBOT

Department of Electronics & Communication, GAT, Bangalore - 98

57

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

Page 68: LFR Report
Page 69: LFR Report

PCB LAYOUT

Top Side

Bottom Side

Page 70: LFR Report

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

Page 71: LFR Report

2001 Microchip Technology Inc. DS30292C-page 1

PIC16F87X

Devices Included in this Data Sheet:

Microcontroller Core Features:

• High performance RISC CPU• Only 35 single word instructions to learn

• All single cycle instructions except for program branches which are two cycle

• Operating speed: DC - 20 MHz clock inputDC - 200 ns instruction cycle

• Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory (RAM)Up to 256 x 8 bytes of EEPROM Data Memory

• Pinout compatible to the PIC16C73B/74B/76/77

• Interrupt capability (up to 14 sources)• Eight level deep hardware stack• Direct, indirect and relative addressing modes

• Power-on Reset (POR)• Power-up Timer (PWRT) and

Oscillator Start-up Timer (OST) • Watchdog Timer (WDT) with its own on-chip RC

oscillator for reliable operation• Programmable code protection• Power saving SLEEP mode

• Selectable oscillator options• Low power, high speed CMOS FLASH/EEPROM

technology• Fully static design• In-Circuit Serial Programming (ICSP) via two

pins• Single 5V In-Circuit Serial Programming capability

• In-Circuit Debugging via two pins• Processor read/write access to program memory• Wide operating voltage range: 2.0V to 5.5V

• High Sink/Source Current: 25 mA• Commercial, Industrial and Extended temperature

ranges• Low-power consumption:

- < 0.6 mA typical @ 3V, 4 MHz

- 20 µA typical @ 3V, 32 kHz- < 1 µA typical standby current

Pin Diagram

Peripheral Features:

• Timer0: 8-bit timer/counter with 8-bit prescaler• Timer1: 16-bit timer/counter with prescaler,

can be incremented during SLEEP via external crystal/clock

• Timer2: 8-bit timer/counter with 8-bit periodregister, prescaler and postscaler

• Two Capture, Compare, PWM modules- Capture is 16-bit, max. resolution is 12.5 ns- Compare is 16-bit, max. resolution is 200 ns

- PWM max. resolution is 10-bit• 10-bit multi-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

• Parallel Slave Port (PSP) 8-bits wide, withexternal RD, WR and CS controls (40/44-pin only)

• Brown-out detection circuitry forBrown-out Reset (BOR)

• PIC16F873• PIC16F874

• PIC16F876• PIC16F877

RB7/PGDRB6/PGC

RB5

RB4RB3/PGM

RB2

RB1

RB0/INT

VDD

VSS

RD7/PSP7

RD6/PSP6RD5/PSP5

RD4/PSP4

RC7/RX/DT

RC6/TX/CK

RC5/SDO

RC4/SDI/SDARD3/PSP3

RD2/PSP2

MCLR/VPP

RA0/AN0

RA1/AN1RA2/AN2/VREF-

RA3/AN3/VREF+

RA4/T0CKI

RA5/AN4/SS

RE0/RD/AN5

RE1/WR/AN6

RE2/CS/AN7VDD

VSS

OSC1/CLKIN

OSC2/CLKOUT

RC0/T1OSO/T1CKI

RC1/T1OSI/CCP2

RC2/CCP1

RC3/SCK/SCLRD0/PSP0

RD1/PSP1

1

2

3

4

5

6

7

8

910

11

12

13

14

15

16

17

18

1920

40

39

38

37

36

35

34

33

3231

30

2928

27

26

25

24

23

2221

PIC

16F

877/

874

PDIP

28/40-Pin 8-Bit CMOS FLASH Microcontrollers

Page 72: LFR Report

PIC16F87X

DS30292C-page 2 2001 Microchip Technology Inc.

Pin Diagrams

PIC

16F

876/

873

1011

23456

1

87

9

121314 15

1617181920

232425262728

2221

MCLR/VPP

RA0/AN0RA1/AN1

RA2/AN2/VREF-RA3/AN3/VREF+

RA4/T0CKIRA5/AN4/SS

VSS

OSC1/CLKINOSC2/CLKOUT

RC0/T1OSO/T1CKIRC1/T1OSI/CCP2

RC2/CCP1RC3/SCK/SCL

RB7/PGDRB6/PGCRB5RB4RB3/PGMRB2RB1RB0/INTVDD

VSS

RC7/RX/DTRC6/TX/CKRC5/SDORC4/SDI/SDA

1011121314151617

18 19 20 21 22 23 24 25 26

44

87

6 5 4 3 2 1

27 28

293031323334353637383940414243

9

PIC16F877

RA4/T0CKIRA5/AN4/SSRE0/RD/AN5

OSC1/CLKINOSC2/CLKOUT

RC0/T1OSO/T1CK1NC

RE1/WR/AN6RE2/CS/AN7

VDDVSS

RB3/PGMRB2RB1RB0/INTVDDVSSRD7/PSP7RD6/PSP6RD5/PSP5RD4/PSP4RC7/RX/DT

RA

3/A

N3/

VR

EF+

RA

2/A

N2/

VR

EF-

RA

1/A

N1

RA

0/A

N0

MC

LR/V

PP

NC

RB

7/P

GD

RB

6/P

GC

RB

5R

B4

NC

NC

RC

6/T

X/C

KR

C5/

SD

OR

C4/

SD

I/SD

AR

D3/

PS

P3

RD

2/P

SP

2R

D1/

PS

P1

RD

0/P

SP

0R

C3/

SC

K/S

CL

RC

2/C

CP

1R

C1/

T1O

SI/C

CP

2

1011

23456

1

18 19 20 21 2212 13 14 15

38

87

44 43 42 41 40 3916 17

2930313233

232425262728

36 3435

9

PIC16F877

37

RA

3/A

N3/

VR

EF+

RA

2/A

N2/

VR

EF-

RA

1/A

N1

RA

0/A

N0

MC

LR/V

PP

NC

RB

7/P

GD

RB

6/P

GC

RB

5R

B4

NC

RC

6/T

X/C

KR

C5/

SD

OR

C4/

SD

I/SD

AR

D3/

PS

P3

RD

2/P

SP

2R

D1/

PS

P1

RD

0/P

SP

0R

C3/

SC

K/S

CL

RC

2/C

CP

1R

C1/

T1O

SI/C

CP

2N

C

NCRC0/T1OSO/T1CKIOSC2/CLKOUTOSC1/CLKINVSS

VDD

RE2/AN7/CSRE1/AN6/WRRE0/AN5/RDRA5/AN4/SSRA4/T0CKI

RC7/RX/DTRD4/PSP4RD5/PSP5RD6/PSP6RD7/PSP7

VSS

VDD

RB0/INTRB1RB2

RB3/PGM

PLCC

QFP

PDIP, SOIC

PIC16F874

PIC16F874

Page 73: LFR Report

2001 Microchip Technology Inc. DS30292C-page 5

PIC16F87X

1.0 DEVICE OVERVIEW

This document contains device specific information.Additional information may be found in the PICmicro™Mid-Range Reference Manual (DS33023), which maybe obtained from your local Microchip Sales Represen-tative or downloaded from the Microchip website. TheReference Manual should be considered a complemen-tary document to this data sheet, and is highly recom-mended reading for a better understanding of the devicearchitecture and operation of the peripheral modules.

There are four devices (PIC16F873, PIC16F874,PIC16F876 and PIC16F877) covered by this datasheet. The PIC16F876/873 devices come in 28-pinpackages and the PIC16F877/874 devices come in40-pin packages. The Parallel Slave Port is notimplemented on the 28-pin devices.

The following device block diagrams are sorted by pinnumber; 28-pin for Figure 1-1 and 40-pin for Figure 1-2.The 28-pin and 40-pin pinouts are listed in Table 1-1and Table 1-2, respectively.

FIGURE 1-1: PIC16F873 AND PIC16F876 BLOCK DIAGRAM

FLASHProgramMemory

13 Data Bus 8

14ProgramBus

Instruction reg

Program Counter

8 Level Stack(13-bit)

RAMFile

Registers

Direct Addr 7

RAM Addr(1) 9

Addr MUX

IndirectAddr

FSR reg

STATUS reg

MUX

ALU

W reg

Power-upTimer

OscillatorStart-up Timer

Power-onReset

WatchdogTimer

InstructionDecode &

Control

TimingGeneration

OSC1/CLKINOSC2/CLKOUT

MCLR VDD, VSS

PORTA

PORTB

PORTC

RA4/T0CKIRA5/AN4/SS

RB0/INT

RC0/T1OSO/T1CKIRC1/T1OSI/CCP2RC2/CCP1RC3/SCK/SCLRC4/SDI/SDARC5/SDORC6/TX/CKRC7/RX/DT

8

8

Brown-outReset

Note 1: Higher order bits are from the STATUS register.

USARTCCP1,2Synchronous

10-bit A/DTimer0 Timer1 Timer2

Serial Port

RA3/AN3/VREF+RA2/AN2/VREF-RA1/AN1RA0/AN0

8

3

Data EEPROM

RB1RB2RB3/PGMRB4RB5RB6/PGCRB7/PGD

DeviceProgram FLASH

Data MemoryData

EEPROM

PIC16F873 4K 192 Bytes 128 Bytes

PIC16F876 8K 368 Bytes 256 Bytes

In-CircuitDebugger

Low VoltageProgramming

Page 74: LFR Report

2001 Microchip Technology Inc. DS30292C-page 7

PIC16F87X TABLE 1-1: PIC16F873 AND PIC16F876 PINOUT DESCRIPTION

Pin NameDIPPin#

SOICPin#

I/O/PType

BufferType

Description

OSC1/CLKIN 9 9 I ST/CMOS(3) Oscillator crystal input/external clock source input.

OSC2/CLKOUT 10 10 O — Oscillator crystal output. Connects to crystal or resonator in crystal oscillator mode. In RC mode, the OSC2 pin outputs CLKOUT which has 1/4 the frequency of OSC1, and denotes the instruction cycle rate.

MCLR/VPP 1 1 I/P ST Master Clear (Reset) input or programming voltage input. This pin is an active low RESET to the device.

PORTA is a bi-directional I/O port.

RA0/AN0 2 2 I/O TTL RA0 can also be analog input0.

RA1/AN1 3 3 I/O TTL RA1 can also be analog input1.

RA2/AN2/VREF- 4 4 I/O TTL RA2 can also be analog input2 or negative analog reference voltage.

RA3/AN3/VREF+ 5 5 I/O TTL RA3 can also be analog input3 or positive analogreference voltage.

RA4/T0CKI 6 6 I/O ST RA4 can also be the clock input to the Timer0 module. Output is open drain type.

RA5/SS/AN4 7 7 I/O TTL RA5 can also be analog input4 or the slave selectfor the synchronous serial port.

PORTB is a bi-directional I/O port. PORTB can be software programmed for internal weak pull-up on all inputs.

RB0/INT 21 21 I/O TTL/ST(1) RB0 can also be the external interrupt pin.

RB1 22 22 I/O TTL

RB2 23 23 I/O TTL

RB3/PGM 24 24 I/O TTL RB3 can also be the low voltage programming input.

RB4 25 25 I/O TTL Interrupt-on-change pin.

RB5 26 26 I/O TTL Interrupt-on-change pin.

RB6/PGC 27 27 I/O TTL/ST(2) Interrupt-on-change pin or In-Circuit Debugger pin. Serial programming clock.

RB7/PGD 28 28 I/O TTL/ST(2) Interrupt-on-change pin or In-Circuit Debugger pin. Serial programming data.

PORTC is a bi-directional I/O port.

RC0/T1OSO/T1CKI 11 11 I/O ST RC0 can also be the Timer1 oscillator output or Timer1 clock input.

RC1/T1OSI/CCP2 12 12 I/O ST RC1 can also be the Timer1 oscillator input or Capture2 input/Compare2 output/PWM2 output.

RC2/CCP1 13 13 I/O ST RC2 can also be the Capture1 input/Compare1 output/PWM1 output.

RC3/SCK/SCL 14 14 I/O ST RC3 can also be the synchronous serial clock input/output for both SPI and I2C modes.

RC4/SDI/SDA 15 15 I/O ST RC4 can also be the SPI Data In (SPI mode) or data I/O (I2C mode).

RC5/SDO 16 16 I/O ST RC5 can also be the SPI Data Out (SPI mode).

RC6/TX/CK 17 17 I/O ST RC6 can also be the USART Asynchronous Transmit or Synchronous Clock.

RC7/RX/DT 18 18 I/O ST RC7 can also be the USART Asynchronous Receive or Synchronous Data.

VSS 8, 19 8, 19 P — Ground reference for logic and I/O pins.

VDD 20 20 P — Positive supply for logic and I/O pins.

Legend: I = input O = output I/O = input/output P = power— = Not used TTL = TTL input ST = Schmitt Trigger input

Note 1: This buffer is a Schmitt Trigger input when configured as the external interrupt.2: This buffer is a Schmitt Trigger input when used in Serial Programming mode.3: This buffer is a Schmitt Trigger input when configured in RC oscillator mode and a CMOS input otherwise.

Page 75: LFR Report

2001 Microchip Technology Inc. DS30292C-page 47

PIC16F87X

5.0 TIMER0 MODULE

The Timer0 module timer/counter has the following fea-tures:

• 8-bit timer/counter

• Readable and writable• 8-bit software programmable prescaler• Internal or external clock select

• Interrupt on overflow from FFh to 00h• Edge select for external clock

Figure 5-1 is a block diagram of the Timer0 module andthe prescaler shared with the WDT.

Additional information on the Timer0 module is avail-able in the PICmicro™ Mid-Range MCU Family Refer-ence Manual (DS33023).

Timer mode is selected by clearing bit T0CS(OPTION_REG<5>). In Timer mode, the Timer0 mod-ule will increment every instruction cycle (without pres-caler). If the TMR0 register is written, the increment isinhibited for the following two instruction cycles. Theuser can work around this by writing an adjusted valueto the TMR0 register.

Counter mode is selected by setting bit T0CS(OPTION_REG<5>). In Counter mode, Timer0 willincrement either on every rising, or falling edge of pinRA4/T0CKI. The incrementing edge is determined bythe Timer0 Source Edge Select bit, T0SE(OPTION_REG<4>). Clearing bit T0SE selects the ris-ing edge. Restrictions on the external clock input arediscussed in detail in Section 5.2.

The prescaler is mutually exclusively shared betweenthe Timer0 module and the Watchdog Timer. The pres-caler is not readable or writable. Section 5.3 details theoperation of the prescaler.

5.1 Timer0 Interrupt

The TMR0 interrupt is generated when the TMR0 reg-ister overflows from FFh to 00h. This overflow sets bitT0IF (INTCON<2>). The interrupt can be masked byclearing bit T0IE (INTCON<5>). Bit T0IF must becleared in software by the Timer0 module Interrupt Ser-vice Routine before re-enabling this interrupt. TheTMR0 interrupt cannot awaken the processor fromSLEEP, since the timer is shut-off during SLEEP.

FIGURE 5-1: BLOCK DIAGRAM OF THE TIMER0/WDT PRESCALER

RA4/T0CKI

T0SE

pin

MUX

CLKOUT (= FOSC/4)

SYNC2

CyclesTMR0 Reg

8-bit Prescaler

8 - to - 1MUX

MUX

M U X

WatchdogTimer

PSA

0 1

0

1

WDTTime-out

PS2:PS0

8

Note: T0CS, T0SE, PSA, PS2:PS0 are (OPTION_REG<5:0>).

PSA

WDT Enable bit

MUX

0

1 0

1

Data Bus

Set Flag Bit T0IFon Overflow

8

PSAT0CS

PRESCALER

Page 76: LFR Report

PIC16F87X

DS30292C-page 48 2001 Microchip Technology Inc.

5.2 Using Timer0 with an External Clock

When no prescaler is used, the external clock input isthe same as the prescaler output. The synchronizationof T0CKI with the internal phase clocks is accom-plished by sampling the prescaler output on the Q2 andQ4 cycles of the internal phase clocks. Therefore, it isnecessary for T0CKI to be high for at least 2Tosc (anda small RC delay of 20 ns) and low for at least 2Tosc(and a small RC delay of 20 ns). Refer to the electricalspecification of the desired device.

5.3 Prescaler

There is only one prescaler available, which is mutuallyexclusively shared between the Timer0 module and theWatchdog Timer. A prescaler assignment for the

Timer0 module means that there is no prescaler for theWatchdog Timer, and vice-versa. This prescaler is notreadable or writable (see Figure 5-1).

The PSA and PS2:PS0 bits (OPTION_REG<3:0>)determine the prescaler assignment and prescale ratio.

When assigned to the Timer0 module, all instructionswriting to the TMR0 register (e.g. CLRF 1, MOVWF 1,

BSF 1,x....etc.) will clear the prescaler. When assignedto WDT, a CLRWDT instruction will clear the prescaleralong with the Watchdog Timer. The prescaler is notreadable or writable.

REGISTER 5-1: OPTION_REG REGISTER

Note: Writing to TMR0, when the prescaler isassigned to Timer0, will clear the prescalercount, but will not change the prescalerassignment.

R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1 R/W-1

RBPU INTEDG T0CS T0SE PSA PS2 PS1 PS0

bit 7 bit 0

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

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

000

001

010

011

100

101

110

111

1 : 21 : 41 : 81 : 161 : 321 : 641 : 1281 : 256

1 : 11 : 21 : 41 : 81 : 161 : 321 : 641 : 128

Bit Value TMR0 Rate WDT Rate

Note: To avoid an unintended device RESET, the instruction sequence shown in the PICmicro™ Mid-Range MCUFamily Reference Manual (DS33023) must be executed when changing the prescaler assignment fromTimer0 to the WDT. This sequence must be followed even if the WDT is disabled.

Page 77: LFR Report

2001 Microchip Technology Inc. DS30292C-page 55

PIC16F87X

7.0 TIMER2 MODULE

Timer2 is an 8-bit timer with a prescaler and apostscaler. It can be used as the PWM time-base forthe PWM mode of the CCP module(s). The TMR2 reg-ister is readable and writable, and is cleared on anydevice RESET.

The input clock (FOSC/4) has a prescale option of 1:1,1:4, or 1:16, selected by control bitsT2CKPS1:T2CKPS0 (T2CON<1:0>).

The Timer2 module has an 8-bit period register, PR2.Timer2 increments from 00h until it matches PR2 andthen resets to 00h on the next increment cycle. PR2 isa readable and writable register. The PR2 register isinitialized to FFh upon RESET.

The match output of TMR2 goes through a 4-bitpostscaler (which gives a 1:1 to 1:16 scaling inclusive)to generate a TMR2 interrupt (latched in flag bitTMR2IF, (PIR1<1>)).

Timer2 can be shut-off by clearing control bit TMR2ON(T2CON<2>), to minimize power consumption.

Register 7-1 shows the Timer2 control register.

Additional information on timer modules is available inthe PICmicro™ Mid-Range MCU Family ReferenceManual (DS33023).

FIGURE 7-1: TIMER2 BLOCK DIAGRAM

REGISTER 7-1: T2CON: TIMER2 CONTROL REGISTER (ADDRESS 12h)

Comparator

TMR2Sets Flag

TMR2 Reg

Output(1)

RESET

Postscaler

Prescaler

PR2 Reg

2

FOSC/4

1:1 1:16

1:1, 1:4, 1:16

EQ

4

bit TMR2IF

Note 1: TMR2 register output can be software selected by theSSP module as a baud clock.

to

T2OUTPS3:T2OUTPS0

T2CKPS1:T2CKPS0

U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0

— TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0

bit 7 bit 0

bit 7 Unimplemented: Read as '0'

bit 6-3 TOUTPS3:TOUTPS0: Timer2 Output Postscale Select bits0000 = 1:1 Postscale0001 = 1:2 Postscale0010 = 1:3 Postscale•••1111 = 1:16 Postscale

bit 2 TMR2ON: Timer2 On bit

1 = Timer2 is on0 = Timer2 is off

bit 1-0 T2CKPS1:T2CKPS0: Timer2 Clock Prescale Select bits00 = Prescaler is 101 = Prescaler is 41x = Prescaler is 16

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

Page 78: LFR Report

PIC16F87X

DS30292C-page 56 2001 Microchip Technology Inc.

7.1 Timer2 Prescaler and Postscaler

The prescaler and postscaler counters are clearedwhen any of the following occurs:

• a write to the TMR2 register• a write to the T2CON register

• any device RESET (POR, MCLR Reset, WDT Reset, or BOR)

TMR2 is not cleared when T2CON is written.

7.2 Output of TMR2

The output of TMR2 (before the postscaler) is fed to theSSP module, which optionally uses it to generate shiftclock.

TABLE 7-1: REGISTERS ASSOCIATED WITH TIMER2 AS A TIMER/COUNTER

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on:

POR,BOR

Value on all other RESETS

0Bh,8Bh,10Bh,18Bh

INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u

0Ch PIR1 PSPIF(1) ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF 0000 0000 0000 0000

8Ch PIE1 PSPIE(1) ADIE RCIE TXIE SSPIE CCP1IE TMR2IE TMR1IE 0000 0000 0000 0000

11h TMR2 Timer2 Module’s Register 0000 0000 0000 0000

12h T2CON — TOUTPS3 TOUTPS2 TOUTPS1 TOUTPS0 TMR2ON T2CKPS1 T2CKPS0 -000 0000 -000 0000

92h PR2 Timer2 Period Register 1111 1111 1111 1111

Legend: x = unknown, u = unchanged, - = unimplemented, read as '0'. Shaded cells are not used by the Timer2 module.Note 1: Bits PSPIE and PSPIF are reserved on the PIC16F873/876; always maintain these bits clear.

Page 79: LFR Report

2001 Microchip Technology Inc. DS30292C-page 57

PIC16F87X

8.0 CAPTURE/COMPARE/PWM MODULES

Each Capture/Compare/PWM (CCP) module containsa 16-bit register which can operate as a:

• 16-bit Capture register• 16-bit Compare register

• PWM Master/Slave Duty Cycle register

Both the CCP1 and CCP2 modules are identical inoperation, with the exception being the operation of thespecial event trigger. Table 8-1 and Table 8-2 show theresources and interactions of the CCP module(s). Inthe following sections, the operation of a CCP moduleis described with respect to CCP1. CCP2 operates thesame as CCP1, except where noted.

CCP1 Module:

Capture/Compare/PWM Register1 (CCPR1) is com-prised of two 8-bit registers: CCPR1L (low byte) andCCPR1H (high byte). The CCP1CON register controlsthe operation of CCP1. The special event trigger isgenerated by a compare match and will reset Timer1.

CCP2 Module:

Capture/Compare/PWM Register2 (CCPR2) is com-prised of two 8-bit registers: CCPR2L (low byte) andCCPR2H (high byte). The CCP2CON register controlsthe operation of CCP2. The special event trigger isgenerated by a compare match and will reset Timer1and start an A/D conversion (if the A/D module isenabled).

Additional information on CCP modules is available inthe PICmicro™ Mid-Range MCU Family ReferenceManual (DS33023) and in application note AN594,“Using the CCP Modules” (DS00594).

TABLE 8-1: CCP MODE - TIMER RESOURCES REQUIRED

TABLE 8-2: INTERACTION OF TWO CCP MODULES

CCP Mode Timer Resource

CaptureCompare

PWM

Timer1Timer1Timer2

CCPx Mode CCPy Mode Interaction

Capture Capture Same TMR1 time-base

Capture Compare The compare should be configured for the special event trigger, which clears TMR1

Compare Compare The compare(s) should be configured for the special event trigger, which clears TMR1

PWM PWM The PWMs will have the same frequency and update rate (TMR2 interrupt)

PWM Capture None

PWM Compare None

Page 80: LFR Report

PIC16F87X

DS30292C-page 58 2001 Microchip Technology Inc.

REGISTER 8-1: CCP1CON REGISTER/CCP2CON REGISTER (ADDRESS: 17h/1Dh)

U-0 U-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0 R/W-0

— — CCPxX CCPxY CCPxM3 CCPxM2 CCPxM1 CCPxM0

bit 7 bit 0

bit 7-6 Unimplemented: Read as '0'

bit 5-4 CCPxX:CCPxY: PWM Least Significant bitsCapture mode: UnusedCompare mode: UnusedPWM mode: These bits are the two LSbs of the PWM duty cycle. The eight MSbs are found in CCPRxL.

bit 3-0 CCPxM3:CCPxM0: CCPx Mode Select bits0000 = Capture/Compare/PWM disabled (resets CCPx module)0100 = Capture mode, every falling edge0101 = Capture mode, every rising edge0110 = Capture mode, every 4th rising edge0111 = Capture mode, every 16th rising edge1000 = Compare mode, set output on match (CCPxIF bit is set)1001 = Compare mode, clear output on match (CCPxIF bit is set)1010 = Compare mode, generate software interrupt on match (CCPxIF bit is set, CCPx pin is

unaffected)1011 = Compare mode, trigger special event (CCPxIF bit is set, CCPx pin is unaffected); CCP1

resets TMR1; CCP2 resets TMR1 and starts an A/D conversion (if A/D module is enabled)

11xx = PWM mode

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

Page 81: LFR Report

2001 Microchip Technology Inc. DS30292C-page 61

PIC16F87X

8.3 PWM Mode (PWM)

In Pulse Width Modulation mode, the CCPx pin pro-duces up to a 10-bit resolution PWM output. Since theCCP1 pin is multiplexed with the PORTC data latch,the TRISC<2> bit must be cleared to make the CCP1pin an output.

Figure 8-3 shows a simplified block diagram of theCCP module in PWM mode.

For a step-by-step procedure on how to set up the CCPmodule for PWM operation, see Section 8.3.3.

FIGURE 8-3: SIMPLIFIED PWM BLOCK DIAGRAM

A PWM output (Figure 8-4) has a time-base (period)and a time that the output stays high (duty cycle). Thefrequency of the PWM is the inverse of the period(1/period).

FIGURE 8-4: PWM OUTPUT

8.3.1 PWM PERIOD

The PWM period is specified by writing to the PR2 reg-ister. The PWM period can be calculated using the fol-lowing formula:

PWM period = [(PR2) + 1] • 4 • TOSC •(TMR2 prescale value)

PWM frequency is defined as 1 / [PWM period].

When TMR2 is equal to PR2, the following three eventsoccur on the next increment cycle:

• TMR2 is cleared• The CCP1 pin is set (exception: if PWM duty

cycle = 0%, the CCP1 pin will not be set)• The PWM duty cycle is latched from CCPR1L into

CCPR1H

8.3.2 PWM DUTY CYCLE

The PWM duty cycle is specified by writing to theCCPR1L register and to the CCP1CON<5:4> bits. Upto 10-bit resolution is available. The CCPR1L containsthe eight MSbs and the CCP1CON<5:4> contains thetwo LSbs. This 10-bit value is represented byCCPR1L:CCP1CON<5:4>. The following equation isused to calculate the PWM duty cycle in time:

PWM duty cycle =(CCPR1L:CCP1CON<5:4>) • TOSC • (TMR2 prescale value)

CCPR1L and CCP1CON<5:4> can be written to at anytime, but the duty cycle value is not latched intoCCPR1H until after a match between PR2 and TMR2occurs (i.e., the period is complete). In PWM mode,CCPR1H is a read-only register.

The CCPR1H register and a 2-bit internal latch areused to double buffer the PWM duty cycle. This doublebuffering is essential for glitch-free PWM operation.

When the CCPR1H and 2-bit latch match TMR2, con-catenated with an internal 2-bit Q clock, or 2 bits of theTMR2 prescaler, the CCP1 pin is cleared.

The maximum PWM resolution (bits) for a given PWMfrequency is given by the formula:

Note: Clearing the CCP1CON register will forcethe CCP1 PWM output latch to the defaultlow level. This is not the PORTC I/O datalatch.

CCPR1L

CCPR1H (Slave)

Comparator

TMR2

Comparator

PR2

(Note 1)

R Q

S

Duty Cycle Registers CCP1CON<5:4>

Clear Timer,CCP1 pin and latch D.C.

TRISC<2>

RC2/CCP1

Note 1: The 8-bit timer is concatenated with 2-bit internal Qclock, or 2 bits of the prescaler, to create 10-bit time-base.

Period

Duty Cycle

TMR2 = PR2

TMR2 = Duty Cycle

TMR2 = PR2

Note: The Timer2 postscaler (see Section 7.1) isnot used in the determination of the PWMfrequency. The postscaler could be usedto have a servo update rate at a differentfrequency than the PWM output.

Note: If the PWM duty cycle value is longer thanthe PWM period, the CCP1 pin will not becleared.

log(FPWM

log(2)

FOSC )bits=Resolution

Page 82: LFR Report

PIC16F87X

DS30292C-page 62 2001 Microchip Technology Inc.

8.3.3 SETUP FOR PWM OPERATION

The following steps should be taken when configuringthe CCP module for PWM operation:

1. Set the PWM period by writing to the PR2 register.

2. Set the PWM duty cycle by writing to theCCPR1L register and CCP1CON<5:4> bits.

3. Make the CCP1 pin an output by clearing theTRISC<2> bit.

4. Set the TMR2 prescale value and enable Timer2by writing to T2CON.

5. Configure the CCP1 module for PWM operation.

TABLE 8-3: EXAMPLE PWM FREQUENCIES AND RESOLUTIONS AT 20 MHz

TABLE 8-4: REGISTERS ASSOCIATED WITH CAPTURE, COMPARE, AND TIMER1

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

Address Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0Value on:

POR,BOR

Value onall otherRESETS

0Bh,8Bh,10Bh, 18Bh

INTCON GIE PEIE T0IE INTE RBIE T0IF INTF RBIF 0000 000x 0000 000u

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.

Page 83: LFR Report

PIC16F87X

DS30292C-page 136 2001 Microchip Technology Inc.

TABLE 13-2: PIC16F87X INSTRUCTION SET

Mnemonic,Operands

Description Cycles14-Bit Opcode Status

AffectedNotes

MSb LSb

BYTE-ORIENTED FILE REGISTER OPERATIONS

ADDWFANDWFCLRFCLRWCOMFDECFDECFSZINCFINCFSZIORWFMOVFMOVWFNOPRLFRRFSUBWFSWAPFXORWF

f, df, d

f-

f, df, df, df, df, df, df, d

f-

f, df, df, df, df, d

Add W and fAND W with fClear fClear WComplement fDecrement fDecrement f, Skip if 0Increment fIncrement f, Skip if 0Inclusive OR W with fMove fMove W to fNo OperationRotate Left f through CarryRotate Right f through CarrySubtract W from fSwap nibbles in fExclusive OR W with f

111111

1(2)1

1(2)111111111

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

00

0111

0101

0001

0001

1001

0011

1011

1010

1111

0100

1000

0000

0000

1101

1100

0010

1110

0110

dfff

dfff

lfff

0xxx

dfff

dfff

dfff

dfff

dfff

dfff

dfff

lfff

0xx0

dfff

dfff

dfff

dfff

dfff

ffff

ffff

ffff

xxxx

ffff

ffff

ffff

ffff

ffff

ffff

ffff

ffff

0000

ffff

ffff

ffff

ffff

ffff

C,DC,ZZZZZZ

Z

ZZ

CC

C,DC,Z

Z

1,21,22

1,21,2

1,2,31,2

1,2,31,21,2

1,21,21,21,21,2

BIT-ORIENTED FILE REGISTER OPERATIONS

BCFBSFBTFSCBTFSS

f, bf, bf, bf, b

Bit Clear fBit Set fBit Test f, Skip if ClearBit Test f, Skip if Set

11

1 (2)1 (2)

01

01

01

01

00bb

01bb

10bb

11bb

bfff

bfff

bfff

bfff

ffff

ffff

ffff

ffff

1,21,233

LITERAL AND CONTROL OPERATIONS

ADDLWANDLWCALLCLRWDTGOTOIORLWMOVLWRETFIERETLWRETURNSLEEPSUBLWXORLW

kkk-kkk-k--kk

Add literal and WAND literal with WCall subroutineClear Watchdog TimerGo to addressInclusive OR literal with WMove literal to WReturn from interruptReturn with literal in W Return from SubroutineGo into standby modeSubtract W from literalExclusive OR literal with W

1121211222111

11

11

10

00

10

11

11

00

11

00

00

11

11

111x

1001

0kkk

0000

1kkk

1000

00xx

0000

01xx

0000

0000

110x

1010

kkkk

kkkk

kkkk

0110

kkkk

kkkk

kkkk

0000

kkkk

0000

0110

kkkk

kkkk

kkkk

kkkk

kkkk

0100

kkkk

kkkk

kkkk

1001

kkkk

1000

0011

kkkk

kkkk

C,DC,ZZ

TO,PD

Z

TO,PDC,DC,Z

Z

Note 1: When an I/O register is modified as a function of itself ( e.g., MOVF PORTB, 1), the value used will be that value present on the pins themselves. For example, if the data latch is ’1’ for a pin configured as input and is driven low by an external device, the data will be written back with a ’0’.

2: If this instruction is executed on the TMR0 register (and, where applicable, d = 1), the prescaler will be cleared if assigned to the Timer0 module.

3: If Program Counter (PC) is modified, or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.

Note: Additional information on the mid-range instruction set is available in the PICmicro™ Mid-Range MCUFamily Reference Manual (DS33023).

Page 84: LFR Report

L293DL293DD

PUSH-PULL FOUR CHANNEL DRIVER WITH DIODES

600mA OUTPUT CURRENT CAPABILITYPER CHANNEL1.2A PEAK OUTPUT CURRENT (non repeti-tive) PER CHANNELENABLE FACILITYOVERTEMPERATURE PROTECTIONLOGICAL ”0” INPUT VOLTAGE UP TO 1.5 V(HIGH NOISE IMMUNITY)INTERNAL CLAMP DIODES

DESCRIPTIONThe Device is a monolithic integrated high volt-age, high current four channel driver designed toaccept standard DTL or TTL logic levels and driveinductive loads (such as relays solenoides, DCand 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 separatesupply input is provided for the logic, allowing op-eration at a lower voltage and internal clamp di-odes are included.This device is suitable for use in switching appli-cations at frequencies up to 5 kHz.

The L293D is assembled in a 16 lead plasticpackaage which has 4 center pins connected to-gether and used for heatsinkingThe L293DD is assembled in a 20 lead surfacemount which has 8 center pins connected to-gether and used for heatsinking.

June 1996

BLOCK DIAGRAM

SO(12+4+4) Powerdip (12+2+2)

ORDERING NUMBERS:

L293DD L293D

1/7

Page 85: LFR Report

ABSOLUTE MAXIMUM RATINGS

Symbol Parameter Value Unit

VS Supply Voltage 36 V

VSS Logic Supply Voltage 36 V

Vi Input Voltage 7 V

Ven Enable Voltage 7 V

Io Peak Output Current (100 µs non repetitive) 1.2 A

Ptot Total Power Dissipation at Tpins = 90 °C 4 W

Tstg, Tj Storage and Junction Temperature – 40 to 150 °C

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.

PIN CONNECTIONS (Top view)

SO(12+4+4) Powerdip(12+2+2)

L293D - L293DD

2/7

Page 86: LFR Report

Aiv'lIiJIKA. TRADING CO.,,4nnexeto Ambika No. loa, Shankara Park,

Bangalore . 560 004.Telefax: 6613337, 6602160

e.mail: [email protected]

.'''''- GearSeries(533 & (528 ~Spur Reduction Gearhead

DesignGear series C533 &C528 contains Brassgears and steel pinions to ensurelonger life and better wear and tear properties. The gears are fixed onhardened steel spindles polished to a mirror finish.These spindles rotatebetween bronze plates which ensures silent running. The output shaftrotates in a sintered bushing. The whole assembly is covered with aplastic ring. All the bearings are permanently lubricated and thereforerequires no maintenance. The motor is screwed to the gear box frominside. Any small standard motor can be used in combination with thegear box. However the most popular ones are mentioned in the tablebelow. .

3 IStandard small DC motor Dia 33 availiable in 6 V,9 Vor 12VDC

" anyposition150

." 25

'1 54.00,4.76,5.00,6.00,6.35 &7.00 (others on request)-15...+55 . . .,...,... .

Standard Data

GearTorqueCombination motor

MountingWeightAxial thrust

Radial torque

Lateral torque

Output shafts

Ambient' temperature operation

kg-cm

gm"C'" kg

kgkg-cm

eJ.C

Transmission ratios

Motor Data

"'.

/ I~nos.8 Bp,.tappingsOn17PCD

\4 nos. 8BA \

On 17.0PCD

- ---~'-- J -~O~O~~.~~J--GEAr~.~~AD (533(5:;;:.

_--nn__---

.,mm,I .---~ o.

- ._d~ ~., ,--"---

25 I 28.1 i! n-I :i 2J~L---i

'"a.

"0---(5:;;:

MOTOR DC 25 GEAR HEAD (528,

01"I -'-, Q G'

'-..1

----

I

.29.L._. JI

ji

-,_..1

26.1

47.9

""-,, '0.. .,.

Motor Voltage ' '. Direction Speed Torque. .D03 6 CW or ACW 2400 30 gm-cm

D03 6 I Reversible 2400 30 gm-cm

D03 12 CW or ACW 2400 50 gm.cm

003 12 Reversible 7500 25 gm-cm

DC25 2.5 Reversible 2200 3.2 gm-cm

DC25 6 Reversible 8500 4.0 gm-cm

Page 87: LFR Report

Semiconductor Components Industries, LLC, 2004

July, 2004 − Rev. 13Publication Order Number:

LM339/D1

LM339, LM239, LM2901,LM2901V, NCV2901,MC3302

Single Supply QuadComparators

These comparators are designed for use in level detection, low−levelsensing and memory applications in consumer, automotive, andindustrial electronic applications.

Features

• Pb−Free Packages are Available*

• Single or Split Supply Operation• Low Input Bias Current: 25 nA (Typ)• Low Input Offset Current: ±5.0 nA (Typ)• Low Input Offset Voltage• Input Common Mode Voltage Range to GND• Low Output Saturation Voltage: 130 mV (Typ) @ 4.0 mA• TTL and CMOS Compatible• ESD Clamps on the Inputs Increase Reliability without Affecting

Device Operation

*For additional information on our Pb−Free strategy and soldering details, pleasedownload the ON Semiconductor Soldering and Mounting TechniquesReference Manual, SOLDERRM/D.

PDIP−14N, P SUFFIXCASE 646

1

14

SOIC−14D SUFFIX

CASE 751A1

14

PIN CONNECTIONS

32

1�

1

2

3

4

5

6

7

14

8

9

10

11

12

13

Output 2

− Input 1

Output 1

Output 3

Output 4

+ Input 1

− Input 2

+ Input 2

+ Input 4

− Input 4

+ Input 3

− Input 3

VCC GND

4

(Top View)

See detailed ordering and shipping information in the packagedimensions section on page 7 of this data sheet.

ORDERING INFORMATION

See general marking information in the device markingsection on page 8 of this data sheet.

DEVICE MARKING INFORMATION

http://onsemi.com

TSSOP−14DTB SUFFIXCASE 948G

1

14

Page 88: LFR Report

December 1990 3

Philips Semiconductors Product specification

Triple 3-input NOR gate 74HC/HCT27

PIN DESCRIPTION

PIN NO. SYMBOL NAME AND FUNCTION

1, 3, 9 1A to 3A data inputs

2, 4, 10 1B to 3B data inputs

13, 5, 11 1C to 3C data inputs

7 GND ground (0 V)

12, 6, 8 1Y to 3Y data outputs

14 VCC positive supply voltage

Fig.1 Pin configuration. Fig.2 Logic symbol. Fig.3 IEC logic symbol.

Fig.4 Functional diagram. Fig.5 Logic diagram (one gate).

FUNCTION TABLE

Notes

1. H = HIGH voltage levelL = LOW voltage levelX = don’t care

INPUTS OUTPUT

nA nB nC nY

LXXH

LXHX

LHXX

HLLL

Page 89: LFR Report

© 2001 Fairchild Semiconductor Corporation DS009390 www.fairchildsemi.com

October 1987

Revised September 2001

MM

74HC

148 8-3 Lin

e Prio

rity En

cod

er

MM74HC1488-3 Line Priority Encoder

General DescriptionThe MM74HC148 priority encoder utilizes advanced sili-con-gate CMOS technology. It has the high noise immunityand low power consumption typical of CMOS circuits, aswell as the speeds and output drive similar to LB-TTL.

This priority encoder accepts 8 input request lines 0–7 andoutputs 3 lines A0–A2. The priority encoding ensures thatonly the highest order data line is encoded. Cascading cir-cuitry (enable input EI and enable output EO) has beenprovided to allow octal expansion without the need forexternal circuitry. All data inputs and outputs are active atthe low logic level.

All inputs are protected from damage due to static dis-charge by internal diode clamps to VCC and ground.

Features■ Typical propagation delay: 13 ns

■ Wide supply voltage range: 2V–6V

Ordering Code:

Connection Diagram Truth Table

H = HIGHL = LOWX = Irrelevant

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

Inputs Outputs

EI 0 1 2 3 4 5 6 7 A2 A1 A0 GS EO

H X X X X X X X X H H H H H

L H H H H H H H H H H H H L

L X X X X X X X L L L L L H

L X X X X X X L H L L H L H

L X X X X X L H H L H L L H

L X X X X L H H H L H H L H

L X X X L H H H H H L L L H

L X X L H H H H H H L H L H

L X L H H H H H H H H L L H

L L H H H H H H H H H H L H

Page 90: LFR Report

2003 Jul 23 4

Philips Semiconductors Product specification

Hex inverter 74HC04; 74HCT04

handbook, halfpage

1 14

GND(1)

1A VCC

7

2

3

4

5

6

1Y

2A

2Y

3A

3Y

13

12

11

10

9

6A

6Y

5A

5Y

4A

8

GNDTop view 4YMBL760

Fig.2 Pin configuration DHVQFN14.

(1) The die substrate is attached to this pad using conductive dieattach material. It can not be used as a supply pin or input.

Fig.3 Logic symbol.

handbook, halfpage

MNA342

1A 1Y1 2

2A 2Y3 4

3A 3Y5 6

4A 4Y9 8

5A 5Y11 10

6A 6Y13 12

handbook, halfpage1

12

MNA343

31

4

51

6

91

8

111

10

131

12

Fig.4 IEC logic symbol. Fig.5 Logic diagram (one inverter).

handbook, halfpage

MNA341

A Y

Page 91: LFR Report

LM78XXSeries Voltage RegulatorsGeneral DescriptionThe LM78XX series of three terminal regulators is availablewith several fixed output voltages making them useful in awide range of applications. One of these is local on cardregulation, eliminating the distribution problems associatedwith single point regulation. The voltages available allowthese regulators to be used in logic systems, instrumenta-tion, HiFi, and other solid state electronic equipment. Al-though designed primarily as fixed voltage regulators thesedevices can be used with external components to obtain ad-justable voltages and currents.

The LM78XX series is available in an aluminum TO-3 pack-age which will allow over 1.0A load current if adequate heatsinking is provided. Current limiting is included to limit thepeak output current to a safe value. Safe area protection forthe output transistor is provided to limit internal power dissi-pation. If internal power dissipation becomes too high for theheat sinking provided, the thermal shutdown circuit takesover preventing the IC from overheating.

Considerable effort was expanded to make the LM78XX se-ries of regulators easy to use and minimize the number ofexternal components. It is not necessary to bypass the out-

put, although this does improve transient response. Input by-passing is needed only if the regulator is located far from thefilter capacitor of the power supply.

For output voltage other than 5V, 12V and 15V the LM117series provides an output voltage range from 1.2V to 57V.

Featuresn Output current in excess of 1An Internal thermal overload protectionn No external components requiredn Output transistor safe area protectionn Internal short circuit current limitn Available in the aluminum TO-3 package

Voltage RangeLM7805C 5V

LM7812C 12V

LM7815C 15V

Connection Diagrams

Metal Can PackageTO-3 (K)

Aluminum

DS007746-2

Bottom ViewOrder Number LM7805CK,LM7812CK or LM7815CK

See NS Package Number KC02A

Plastic PackageTO-220 (T)

DS007746-3

Top ViewOrder Number LM7805CT,LM7812CT or LM7815CT

See NS Package Number T03B

May 2000LM

78XX

Series

VoltageR

egulators

© 2000 National Semiconductor Corporation DS007746 www.national.com