Académique Documents
Professionnel Documents
Culture Documents
ON
SESSION: 2010-2011
Submitted To Submitted By
Mrs. ISHA DHINGRA AJIT KUMAR
C. ID:-07ME004
(B.TECH. VII Semester)
BRANCH: -E.C.E
Line Following
http://www.avrbeginners.net/
External
Rsensor / (SRAM
R3.sensor
Overviewsize
+ R1).
move(L,0,195+12*ldev); :0
Data
Again, Stack Evaluation
size
if(rdev==ldev)
Practical3.1.
// Port Da initialization
good assembler
sensorBlockBoards:
//circuit
applications : STK200,
Diagram
Func7=In 256
should aand
ofFunc6=In
line STK500
Architectural
givefollower
Func5=Outfrom Kanda
Overview
: Automated
Func4=OutSystems
cars runningfor
Func3=In on roads
Func2=In with embedded
Func1=In Func0=In //
Shops: AVR move(FWD,0,200); tutorial Tutorial
}at point for learning assembly language the AVR-Single-
State7=T magnets;
UCSRA=0x00;
maximum State6=T 3.2.
change State5=0
The
in potential State4=0
Algorithm
guidance system State3=T
for industrial
‘2’ State2=T
robots State1=T
moving State0=T
on shop floor etc.
1 Chip-Processors
If all sensors readAT90Sxxxx 1 go to stepfrom
*****************************************************/ 3, else, ATMELIf L>Rwith Move practical
Left If examples.
L<R
UCSRB=0x18;
for no-light Motors:
-http://www.atmel.com/products/avr/
and bright-light conditions.
Move Right If L=R Move Forward Goto step 4
Robot
UCSRC=0x86;
PORTD=0x00;
This is especially
Prerequisites:
//#define
UBRRH=0x00;
DDRD=0x30;
else
4.
1.
debug 1 important
Mechtex
Implementation
Knowledge -Mulund,
http://www.avr-asm-tutorial.net/
{ for(i=0,dirl=0;i<MAX;i++)
if you
of basic plan to
Mumbai
digital and analog electronics. (A course on Digital Design and
{ if(history[i]==L)
use
2 an
Electronic
#include ADC Apart
2.
Move
<mega16.h>4.1.
Devices
Servoform Sensor
& this Circuit
Circuits
almost
Electronics
Clockwise {rotpow=160;} would all be
AVRs
-Lamington
if line was last seen helpful) onCRight
support
road, Programming
Block Diagram
In System
Mumbai Move Sheer interest, an
Programming
Phone:56346573
Counter innovative
(ISP) i.e. you can
UBRRL=0x07;
{dirl++;} } if(rotpow<160)
brain
#include
Clockwiseand perseverance!
reprogram
<delay.h>
3.if line4.2.
Bombay Motorit
#ifdef without
Interface
Electronics removing
and it
Control
-Lamington from the
Circuit
Road, circuit.
3 tillMumbai This comes very handy when prototyping a
if(rotpow<255) One
// Timer/Counter
#endif
in place of the4.3. 0was
{rotpow++;}
ofcomparator
the bestlast seenAVR
sites
initialization //onClock
Left Repeat step
sitessource: line is found.
debug
The robot
System Clock design
#include
uses IRor upgrading
Source
<stdio.h>
sensors Code
to a
sense
// Clock value: Timer 0 Stopped // built-up
the line,system.
an array Alsoof the
8 IR programmer
LEDs (Tx) andused for
sensors ISP
(Rx),is easier
facing to
thebuild
#endif
http://www.avrfreaks.net
ground
3
Mode:
// compared
has
Goto
Normal been
Electronics:
Timer(s)/Counter(s) step used
top=FFh to
1. the
in parallel
this setup.
// OC0 output:
Interrupt(s) programmer
The output
initialization of required
the sensorsfor many
is an old
analog uCs. Most
signal AVR
which chips
depends also
on the
amount
Disconnected
TIMSK=0x00; of light
support reflected
Boot
5. Possible Improvements back,
Loaders this analog
which takesignal
the is
ideagiven
of to
In the
Systemcomparator
Programmingto produceto a 0s
newand 1s
level.which
Features
are 1. toVisha
WinAVR
thenafed AnElectronics
open source -Lamington
C compilerroad, Mumbai [Programmer
I the uC.
2
ToBackground:
get like
good
for AVR
for C8051,
bus
voltage interface
swing
PIC and, themake
AVR adding
value of R1
available] external
must
Phone: bedevices
carefully
23862650 a cakewalk.
chosen.
/ IfWhile
Rsensor most
= a popular
when nouCs light
#define
// FWD
TCCR0=0x00;
Analog 0xAA #define
Comparator initialization // Analog Comparator: Offcrystal,
// robot
Analog Comparator Input
falls on 6.
it References
require
and R at
I least
started
sensor = andba Resources
few
with
when external
building
light components
a
falls parallel
on it. port
The like
based
difference in caps
which
the and
two pull-up
could be
potentials resistors,
controlled
is: with AVR
manually by a
REV
Capture 0x55
TCNT0=0x00;by
23862622
http://sourceforge.net/projects/winavr
#define
Timer/CounterR 0x22 1: Off
if(dirl>HMAX)
#define the
L 0x88 number
keyboard.
6.1. Books
On
#define CW can the be
and as
robot
Linkslow
side as zero!
was an arrangement of relays connected to parallel port pins via opto-
OCR0=0x00; {move(CW,0,rotpow);}
couplers.
6.2. Tools ofLeft
the Center
trade Internal Schematic of L298 }
0x99 #define CCW 0x66 Right Sensor V {Array
* Mumbai
a/(a+R1) -b/(b+R1)
ACSR=0x80; 2. else Electronics
PonyProgGala A widely used-Lamington
programmer. road,ccSupport for newer chips is added periodically. Can
#define STOP 6.3.
0x00TheElectronic
next
#define
also{move(CCW,0,rotpow);}
program PICsB shops
version
and// EEPROMSwas a true computer controlled line follower. It had sensors connected to
SFIOR=0x00;
// Timer/Counter 1 initialization Clock source:
0xFF #define the RSPEED
System Clock3. }status
6.4.
Chip Parts
// Clock
pins and
of the
Components Prices
value: 921.600
parallel port. A program
-Lamington
kHz // Mode: road, Mumbai runningTelephone:
on the computer polled the status register of
OCR1AL
Starting #define
the
Cost:
from parallel
AVR
the LSPEED
port
=
center, PIC hundreds
the > 8051
sensors of times
(by
on 8051
the every
left I second
mean
are the
named and
8051
L1, sent control
family)
L2, L3, signals
L4 and those accordingly
on the right through the
are named
Fast PWM top=00FFh
56390468 //
while (1){http://www.lancos.com/prog.html
}; OC1A
/ 56587005output: Non-Inv. //
OCR1BLdata #define pins. SPEED0
The 255
drawbacks of using a personal computer were soon clear – It’s difficult to control
R1, R2,output:
OC1B R3, R4. Let us //assume
Non-Inv. that whenOff
Noise Canceler: a sensor
// is on the line it reads 0 and when it is off the line it
#define SPEED1 0 motors
#defineAs cable length increases signal strength decreases and latency increases. A long
Input
#ifdef 1 speed
readsCapture
debug onofFalling
if(rep<255)
Availability: Edge
rep++; if(prev!
AVR0 = PIC <8051
SPEED2 Basic 0 #define SPEED3
Electronics
=PINA)
Parts and
#define {multi
MAX Prices:
3
core
prev=PINA;
void move
#define
cable for parallel data transfer is expensive. The robot is not portable if you use a
printf("%u\r",rep);
(unsigned
HMAX char dir,unsigned char delay,unsigned char power) {
http://www.kpsec.freeuk.com/
desktop
for(i=0;i<8;i++) PC.
printf("%u\t",
1The uC decides PORTC=dir
the next move according to the algorithm given below which tries to position the robot
Speed:
(prev>>i)&0x01);
;if(dir==L || dir==R) AVR
rep=0;> }PIC > 8051
such thatWilliamson
L1
Part and R1 both
Labsread Nice0 animated
and the rest read 1.articles and
tutorials, Approximate Price in Indian Rupees
{TCCR1A=0xA1;
hcount=(hcount+1)%MAX;
Visible
project
Built-inideas.
history[hcount]=dir;
TCCR1B=0x0A; Light
} Leds
Peripherals: White L4 one
This or Bicoloured
L3 is difficult
L2 L1to answer R1 1.00 R2 5.00R3
since all uC R4families offer comparable
TCNT1H=0x00; IR LED IR Sensor
http://www.williamson-labs.com/home.htm 3.00 7.00
features in their different chips. For a just comparison, I would rather say that for a given price
The 8 sensors
TCNT1L=0x00; CapacitorareThe
LSPEED=RSPEED=255;//power; connected
obvious
(small to
next
values) PORTA.
step was to(large
Capacitor build an onboard 0.25control
to 2.00circuit;
2.00 tothe 20.00 options – a hardwired
Or more
AVR = PIC > 8051.
ICR1H=0x00; logic circuit
valuesRobot
//delay_ms(delay); or a
/ electrolytic) uC. Since I had no knowledge of uC at that time, I implemented a hardwired logic
Small Sensors Left Center Right Desired State L1=R1=0, and Rest=1
}void
You move
need
ICR1L=0x00; (unsigned
circuit
not using
connect char dir,unsigned
multiplexers.
anything to It
AVCC char delay,unsigned
basically
and mapped
AREF, it ischar
input power);
from
required four
only unsigned
sensors
if ADC char
to
is four
used. outputs for the motor
Resistors (1/4 W) Variable Resistor (Preset)
http://www.andrew.cmu.edu/user/rjg/websensors/robot_sensors2.html 0.25 2.50 8.00
i,rdev,ldev,ip,delay,dir,power,dirl,history[MAX],hcount=0,rotpow;
OCR1AH=0x00;
#endif driver
Tools according
and Resources: to a truth8051 table.
has Though
been it
around workedfrom fine,
many it could
years show
now, no intelligence
consequently – likeare
there
Variable Resistor (Pot)
OCR1AL=0xFF;
The L298morecoming
Motor back
tools
Driver
Microcontrollers on
available line after
hasAT89C2051
4 inputs losing
for working it,
to control
(8051 or
with doing
Core) something
theit.motion
Being of a40part
the special
of many
motors
to 450 when
40 60and say
engineering
two120
150 the line ended.
enable courses, To get
there
inputs which is a
are
Robotics India Anrep=0,prev=0;
Indian sitesome
devoted tofeatures, using
By,
#ifdef debug
OCR1BH=0x00;around
huge
if(PINA!=255){
used for switching
unsigned
AT89C51 this
communitiy
rotpow=255;
#endif robotics. Must see
OCR1BL=0xFF;
the
char
problem
(8051motors and
ofon
Core) add
people thatTo
and off.
AT89S52 cool
can help
control
(8051 you
Core) out with
the speed a microcontroller
of the8051;
motorssame was
with books
a PWM the best
waveform option.
and online
with
ldev=rdev=0; resources.
variable duty cycle isInapplied
spiteCore)oftobeing new the
the enable pins.AVR has aswitching
Rapidly neat toolthe chain (Seebetween
voltage ‘References Vs andandGND
Possible
Priyank Improvements:
PIC16F84A
gives an effective
Resources‘). voltage
(PIC
Patil Department of Information
http://www.roboticsindia.com/ between Vs
Availability of and
online GND whose value
resources and booksdepends on the
is fast duty cycleHere,
increasing. of PWM.
8051100%
> AVR
// Timer/Counter 2 initialization // Clock
equalsource:
Technology
duty
void
System
cycle=
main(void)
are usedClock
corresponds
PIC
Seattle
to
{Robotics
// Clock
if(PINA.3==0)
prevent back
to voltage
value: Timer
Society
EMF of the
to Vs, 50 % corresponds
2 Stopped
motors from // Page 16 to 17
of 0.5Vs and so on. The 1N4004 diodes
disturbing the remaining circuit. Many circuits use
Mode: -Use
Normal motordifferential
of
top=FFh
rdev=1; // OC2 steering
output: with
as gradual change in wheel of speeds.
2A per -Use of Hysteresis in sensorto
K. J. Somaiya College of Engineering
L293D for
Disconnected
Relative
0.6
http://www.seattlerobotics.org/
circuit
A @ voltage
control,
using
if(PINA.2==0)
36 V of swing
a L293D.LM339
I chose
= Actual -Use
L293D’s
L298
of
Voltage ADC
package
it has current
Swingso that the
capacity
exact
/ Vccsuitable
is not = Vcc *for position of the
channel
line can
@ 45V compared
be interpolated
{ attaching a good heat sink, practically you
// Input/Output Ports initialization or //three
Portwheel
A initialization // Func7=In Func6=In Func5=In Func4=InlikeFunc3=In
Mumbai, India
a/(a+R1)
can’t
Func2=Inuse
ASSR=0x00;
-Use
it above
Func1=In
using
of
rdev=2;
-b/(b+R1) Wheel
16V} / V
Func0=In
Chair
cc = a/(a+R1) -b/(b+R1)
a low dropout voltage regulator, lighter chassis etc
if(PINA.1==0)
drive to reduce traction. -General improvements
rdev=3;
TCCR2=0x00;
Page 10 ofTruth
17
Table for controlling the direction of motion of a DC motor
ATmega8 (AVR Core) 90
ATmega16 (AVR Core) 150
ATmega32 (AVR Core) 300
ATmega128 (AVR Core) 425
Transistors Low power Eg: BC547 Power 1.50 to 15 or more 1.50 15.00
Transistor Eg: TIP31C
Connectors 1.00 per pin
Optocoupler (MCT2E) 8.00
Common Tools
Soldering Iron 150 (typical) to 400
Solder metal 25.00
Solder Flux 5.00
Desoldering Wick 5.00
Breadboard 80.00 to 100.00
Wire Stripper 25.00
Common ICs
Voltage Regulators (78XX), LM324,IC555 5.00
etc
MAX232 20.00
ULN 2003 / ULN 2803 14.50
TSOP17XX 17.00
L298, L293, L293D 70.00
IC Programmers
Homemade (Support fewer devices, support 20.00 to 80.00
only serial programming, not as rugged)
Eg: PonyProg ( http://www.lancos.com ) 2500 to 25000
Readymade (Support many chips, support
parallel programming, easy to use, rugged)
Wireless Modules 700.00
Parallel Port / Serial Port Add on Card for PC 500.00
Universal PCB 10.00 to 50.00
倀愀最攀. ....
TRANSISTORS
This section aims at the introduction of the Bipolar Junction Transistors
(BJT) that includes NPN and PNP transistors. Both the majority carriers
and the minority carriers play a major role in the operation of the
transistor. That is why it is named so. A BJT is widely used in the
discrete circuits, IC design, both analog and digital. The N-type material
has a surplus of electrons (hence the negative charge) and the P-type
material is deficient in electrons (hence the positive charge). The
principle of operation of operation of both the types of transistors is
exactly the same, the only difference being in the biasing (base current)
and the polarity of the power supply for each type.
Most bipolar transistors used today are NPN, because electron mobility
is higher than the hole mobility in semiconductors, allowing greater
currents and faster operation. NPN transistors consist of a layer of P-
doped semiconductor (the "base") between two N-doped layers. This
can be better illustrated from the figure shown below:
N-doped
layers
An ideal op-amp by itself is not a very useful device, since any finite non-
zero input signal would result in infinite output. However, by connecting
external components to the ideal op-amp, we can construct useful
amplifier circuits.
AVR MICROCONTROLLERS
To understand quickly, I define a microcontroller as a single chip
computer. It is a full blown computer in its own. It has a C.P.U, RAM,
some amount of EEPROM (for secondary storage, i.e. permanent
storage without power), many on-chip peripherals (Timers, Serial
communication, Analog to Digital Converters etc.). But here we will be
focusing on Atmel’s AVR series of microcontrollers that are being used
globally now a days and gaining attention. For understanding the AVR
better, we will choose ATMEGA 16 out of the various microcontrollers
available in the market.
ATMEGA 16
The ATmega16 is a low-power CMOS 8-bit microcontroller based on the
AVR enhanced RISC architecture. By executing powerful instructions in
a single clock cycle, the ATmega16 achieves throughputs approaching 1
MIPS per MHz allowing the system designer to optimize power
consumption versus processing speed.
The ATMEGA 16 has four I/O ports. They are named as and designated
as:
In addition the other pins are for oscillator, reset.VCC, GND, AREF
(reference voltage for port A), AVCC and RESET.
DDR REGISTERS: It stands for Data Direction registers. They are used
for setting the direction, i.e. input or output. For example:
DDRA = 0X00 => PORT A is configured input.
DDRA = 0XFF => PORT A is configured output.
PORT REGISTER: After we have set the pins to output, we can control
them with the register values. What values we write here will be visible
on the related pins of the MCU. For example:
//Make PORT D – 0 high
PORTD =0B00000001;
//Make it low
PORTD = 0b00000000;
PIN REGISTER: When we set any port pin as input, we can read its
status using this register. For example:
If (PIND & 0B00000001)
{
DO THIS;
}
Else
{
DO THIS;
}
This example shows how to take input from the real world, as in a line
follower from sensors.
TIMERS IN AVR
A timer in simplest term is a register. Timers generally have a resolution
of 8 or 16 bits. So an 8-bit timer is 8 bits wide capable of holding values
from 0-255. But this register has a magical property! Its value increases
or decreases automatically at a predefined rate, supplied by the user.
This is the timer clock and it doesn’t need CPU’s intervention. Since a
timer works independently of CPU, it can be used to measure time
accurately. Timers upon certain conditions take some actions
automatically or inform the CPU. One of the basic conditions is the
situation when timer OVERFLOWS i.e. it is counted up to its maximum
value (0-255 for 8-bit timers), and then again rolled back to 0. In this
situation a timer can issue an interrupt and we must write an ISR
(Interrupt Service Routine) to handle the event.
THE PRESCALER
The prescaler is a mechanism for generating clock for timer by the CPU
clock. For studying the prescaler more efficiently, we will go through the
timer 0 register.
TCCR0 TIMER COUNTER CONTROL REGISTER
This register is used to configure the timer using the prescaler. The
various bits of this register are: