Vous êtes sur la page 1sur 14

A

PRACTICAL TRAINING REPORT

ON

LINE FOLLOWER ROBOT


Submitted in partial fulfillment Of Bachelor of Engineering Degree
RAJASTHAN TECHNICAL UNIVERSITY

SESSION: 2010-2011
Submitted To Submitted By
Mrs. ISHA DHINGRA AJIT KUMAR
C. ID:-07ME004
(B.TECH. VII Semester)
BRANCH: -E.C.E

DEPARTMENT OF ELECTRONICS & COMMUNICATION

BALDEV RAM MIRDHA INSTITUTE OF


TECHNOLOGY
ACKNOWLEDGEMENT

I express my heartfelt thanks to the management of


ROBOSAPIENS INDIA PVT.LTD. For providing me
the opportunity to do Summer project at their
organization. I was provided with the ample
opportunities to explore the area of my discretion
and to interact with professors at all levels. More
over all my queries were duly sorted after.

I am deeply in debt to Mr. Pradeep Kumar for


giving his sincere guidance and moral support and
making it a wholesome learning experience.

I would like to convey my gratefulness to


Mr.Aman Sethi, Toshendra Sharma and Malay
Bisht without whom this training was impossible.

I express my heartiest gratitude to the faculty


Shailabh Suman and Suren Kunar for their help in
making my project meaningful and giving me the
basic fundamentals in robotics and embedded
systems in the right direction.
Date: 12 june-2010
PREFACE

Don't undertake a project unless it is manifestly important and nearly


impossible. 
- Edwin Land
More briefly, emergent computation is the study of how high-level
representation and processing of information can emerge from the
interactions of large numbers of simple processors.
Purpose of this report is to endow ourselves with the basic knowledge
of ROBOTICS and the various important peripherals and electronic
components used in the various robotic circuits. Also, this project
discusses the ways to learn programming in EMBEDDED and
ROBOTICS using AVR microcontrollers.
CONTENTS
Algorithm:
without frying
Line Follower
it. L298 on
ROBOT
the State4=T
otherAward hand winner
works from happily VingPeaw
atState1=T
16V without
Competitiona heat2543,
sink, thethough
robotit built
is always
with
References
Summary
Overview
Implementation
Source Code
TCNT2=0x00;
// State7=T
better
OCR2=0x00;
PORTA=0x00;
The
and Resources
to use
sensor 2051,
State6=T
if(PINA.0==0)
one.
Irdev=4;
used L293D,
State5=T
had aand = 930 four K IR andsensors.
State3=T
b = 36 K. Simple
State2=T
If wecircuit
plot a and
curve
State0=T
platform, quick tracking
of the voltage swing over andaEasy
rangetoof
Introduction
DDRA=0x00;
values
The
1. L=AVR ofunderstand
R1
leftmost we can program
microcontroller:
sensor seewhich using
that reads
the 0;CR=
maximum language.swing issensor
rightmost obtainedwhichat R1=
reads150 K no
0. If (use calculus for an accurate
sensor
Sensor
Books:
// External
value).
on Left Circuit:
There
(or Interrupt(s)
if(PINA.4==0)
Right)is a catch
is 0 initialization
though,
then L (or with
R)// equals
INT0:
such high Off
0; //resistance,
Ex: INT1: Off the current is very small and hence susceptible to
Theldev=1;
purpose ofFunc7=In this document
/*****************************************************
// is toFunc5=In
help youFunc4=In
build a Line Following
Project Line Robot.
: Func2=In
beINT2:
Port B Off
distortedinitialization
by noise.//The
Programming andsolution Func6=In
Customizing
http://www.kmitl.ac.th/~kswichit/LFrobot/LFrobot.htm the AVR
is to strike Microcontroller
a balance between Func3=In
– Dhananjay
sensitivity V.Func1=In
and noise Gadre Func0=In
Parallel
immunity. //
I chose
Follower
What is aVersion
1. Summary
line follower? Atmel's
:“Date : Line AVR®
2/19/2006 L4
follower microcontrollers
L3is L2 L1 have
R1 a follow
RISC
R2 core
R3 running
R4 path single
can cycle instructions
State7=T
The
valueresistance
of R1 if(PINA.5==0)
State6=T
PortasCompleteof K.
60 State5=T
theYoursensor
– Jan State4=T
decreases
Axelson
choice wouldwhen depend on the ‘a’ and ‘b’ values ofThe
State3=Ta machine
State2=T that can
State1=T a path.
State0=T your sensor. be visible like a
black line and
Starting a white
onldev=2;
aon well-defined I/O structure that
or itlimits the need for external
covercomponents. Internal
IR light falls it.with
Asurface
an overview
good (or vice-versa)
sensor of the
will have system canthebedocument
invisible would
like a magnetic implementation
field. details
Tools:
PORTB=0x00;
MCUCR=0x00; AVR
oscillators,
like
2. Studio
circuits
if(PINA.6==0)
Introduction For
timers,
and writing
UART,
algorithms, code SPI,in
followedassembly
pull-up by and
some simulation
resistors, pulse
suggestions of code.
width
on Current
modulation,
improving theversions
ADC,
design. has AVR-
analog
near
Links: zero resistance in presence of light and
GCC
Author plug-in
comparatorto
ldev=3;
: Priyank write code
and in C.
watch-dog timers are some of the features you will find in AVR devices.
aMCUCSR=0x00;
DDRB=0x00;
very large 2.1. What in
resistance isLeft
aabsence
lineCenter
follower?
of theofAVR
Right
light.Here L=3 R=0
Company Atmel : Home Corp. Makers
if(PINA.7==0)
2.2. Why build a line follower?
We
Whyhave build usedaldev=4;
line this
microcontroller propertySensing
follower? of the sensora line and to maneuvering the robot to stay on course, while constantly
Comments:
If youadebug
found this part //confusing, use a 10K resistor
// Port
#ifdef
correcting
form C initialization
The wrong
potential 2.3.
‘Reference
Background
moves
divider. Func7=In
and
using
The Func6=In
Resources’
feedback
potential Func5=In
page
mechanism
at has straightaway,
Func4=In
aforms
list ofa relevant
simple as yet
Func3=In long
books,as you
Func2=In are
websites,
effective using
Func1=In
closed a Func0=In
electronic
loop shops
system. // a
As
Chip
// type http://www.atmel.com
State7=T
USART
comparator State6=T
initialization
it
Compilers: won’t State5=T
matter
IAR, :State4=T
ATmega16
//opportunity
Communication
much.
Image L4Craft State3=T
L3, Code L2 State2=T
Parameters:
VisionL1 8AVR,State1=T
Data,
R1 1to
Stop,
R2
WinAVR State0=T
No
R3 Parity
R4 // thus giving it a human-like
programmer
point ‘2’type
Program and
is 2.4.commonly
you get an used
Prerequisites parts
: Application & totheir
‘teach’prices.
the robot how follow the line
USART
property
AVR
Receiver: instructions
if(rdev>ldev)
of responding On // USART are
to stimuli.
tuned
Transmitter:to decreaseOn // USARTthe sizeMode:of theAsynchronous
program whether // the code is written in
Clock
USART frequency
PORTC=0x00; C
Baud or 2.5.
rate: The
Assembly.
move(R,0,195+12*rdev);AVR
57600 With :microcontroller
7.372800
on-chip MHz
in-system programmable Flash and EEPROM, the AVR is a
Motor InterfaceAVRbeginners.net
Programmers: and ControlPony: Small Circuit:
Prog, AVR Dude, AVRISP and many more.
Memory
DDRC=0xFF; model if(rdev<ldev)
perfect choice inLeft order Center Right Here
to optimize costL=2 andR=4 get product to the market quickly.”

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

You may drop your feedback at priyank.patil@gmail.com .

Priyank Patil KJ Somaiya CoE – Information


Technology VidyaVihar, Mumbai

倀愀最攀. ....
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.

NPN TRANSISTORS: CONSTRUCTION AND


WORKING

Fig: A figure showing the basic schematic of NPN transistors

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:

P-doped semiconductor (The


Base)

N-doped
layers

Fig: A figure showing the construction of NPN transistors

A small current entering the base in common-emitter mode is amplified


in the collector output. In other words, an NPN transistor is "ON" when
its base is pulled high relative to the emitter. The arrow in the NPN
transistor symbol is towards the emitter leg and points in the direction of
the conventional current flow when the device is in forward active mode,
as shown below:

Fig: A figure showing the direction of conventional current flow in NPN


transistors
PNP TRANSISTORS: CONSTRUCTION AND
WORKING

Fig: A figure showing the basic schematic of PNP transistors

The PNP transistor works essentially the same as the NPN transistor.


However, since the emitter, base, and collector in the PNP transistor are
made of materials that are different from those used in
the NPN transistor, different current carriers flow in the PNP unit. The
majority current carriers in the PNP transistor are holes. This is in
contrast to the NPN transistor where the majority current carriers are
electrons.
Fig: A figure showing a properly biased PNP transistor

NPN transistors consist of a layer of N-doped semiconductor between


two layers of P-doped material. A small current leaving the base in
common-emitter mode is amplified in the collector output. In other words,
a PNP transistor is "ON" when its base is pulled low relative to the
emitter. The arrow in the PNP transistor symbol is on the emitter leg and
points in the direction of the conventional current flow when the device is
in forward active mode, as shown below:

Fig: A figure showing the direction of conventional current flow in PNP


transistors
OPERATIONAL AMPLIFIERS
Operational Amplifiers, commonly known as OP-AMPS are one of the
most basic and foremost components that are used in Robotics and
Embedded Systems. Apart from their most common use as amplifiers
(both inverting and non-inverting), they also find applications as buffers
(load isolators), adders, subtractors, integrators, comparators,
logarithmic amplifiers, impedance converters, filters (low–pass, high-
pass, band- reject or notch), and differential amplifiers. The basic
representation of conventional op- amps is shown below:

Fig: A figure showing the representation of OP-AMPS

CHARACTERISTICS OF IDEAL OP-AMPS


The various useful characteristics of OP-AMPS are discussed below:

An ideal OP-AMP has voltage gain equal to infinity.


An ideal OP-AMP has input impedance equal to infinity.
An ideal OP-AMP has bandwidth equal to infinity.
An ideal OP-AMP has zero-ohm output impedance.

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.

Fig: A Figure showing the basic ATMEGA 16/32 Circuit.


I/O PORTS
Each AVR MCU has several bi-directional input and output ports that
may be used according to our needs. In addition there are various
secondary functionalities that are mentioned in the brackets before the
respective pins of the MCU. This is where these small chips start
showing their power!

The ATMEGA 16 has four I/O ports. They are named as and designated
as:

PORT A: PIN NO.33 TO 40.


PORT B: PIN NO 1 TO 8.
PORT C: PIN NO 22 TO 29.
PORT D: PIN NO 14 TO 21.

In addition the other pins are for oscillator, reset.VCC, GND, AREF
(reference voltage for port A), AVCC and RESET.

PROGRAMMING THE AVR

There are 32 general purpose registers in AVR MCUs. Some of them


are described as follows:
Each port in AVR has three related registers. They are described as
follows:

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.

0 1 2 ….. 255 0 1 2….

Timer initialized CPU notified of overflow

8 BIT TIMERS IN AVR


The ATMEGA 16/32 has three timers, of which the simplest one is the
TIMER0, having the resolution of 8-bit, i.e. it can count from 0-255.

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:

Vous aimerez peut-être aussi