Professional Documents
Culture Documents
L293D
Developed by:
Krishna Nand Gupta
Prashant Agrawal
Mayur Agarwal
o.
co
DCMotor
Wheneveraroboticshobbyisttalkaboutmakingarobot,thefirstthingcomesto hismindis
making the robot move on the ground. And there are always two options in front of the
designerwhethertouseaDCmotororasteppermotor.Whenitcomestospeed,weight,size,
cost...DCmotorsarealwayspreferredoversteppermotors.Therearemanythingswhichyou
can do with your DC motor when interfaced with a microcontroller. For example you can
controlthespeedofmotor;youcancontrolthedirectionofrotation.
In this part of tutorial we will learn to interface and control of a DC motor with a
microcontroller.UsuallyHbridgeispreferredwayofinterfacingaDCmotor.Thesedaysmany
ICmanufacturershaveHbridgemotordriveravailableinthemarketlikeL293DismostusedH
Bridge driver IC. Hbridge can also be made with the help of transistors and MOSFETs etc.
ratherofbeingcheap,theyonlyincreasethesizeofthedesignboard,whichissometimesnot
requiredsousingasmall16pinICispreferredforthispurpose.
LeftMotor
Straight
Stop
Reverse
Straight
Straight
Reverse
.V
is
io
n
R
ob
Differentialdrive
Byusingtwomotorswecanmoveourrobotinanydirection.Thissteeringmechanismofrobot
iscalledasdifferentialdrive.
Letscheckhowitworks
RightMotor
Straight
Straight
Straight
Stop
Reverse
Reverse
~1~
RobotMovement
Straight
Left
Sharpleft
Right
SharpRight
Reverse
DCMotorwithGear
co
TheDCmotorsdonthaveenoughtorquetodrivearobotdirectlybyconnectingwheelsinit.
Gearsareusedtoincreasethetorqueofdcmotorontheexpenseofitsspeed.
Mathematicalinterpretation:
Rotationalpower(Pr)isgivenby:
Pr=Torque(T)*RotationalSpeed()
Thus
R
ob
o.
PrisconstantforDCmotorforaconstantinputelectricalpower.Thustorque(T)isinversely
proportionalspeed().
.V
is
io
n
Thustoincreasethevalueoftorquewehavetoloosespeed.
Note:
Intoycar,thereisagearboxthatcontainsseveralcombinationsofgears.
Gearedmotorhasgearsboxatitsfront.
WorkingTheoryofHBridge
The name "HBridge" is derived from the actual shape of the switching circuit which
controls the motion of the motor. It is also known as "Full Bridge". Basically there are four
switchingelementsintheHBridgeasshowninthefigurebelow.
~2~
.V
is
io
n
R
ob
o.
co
Asyoucanseeinthefigureabovetherearefour
switchingelementsnamedas"Highsideleft","High
sideright","Lowsideright","Lowsideleft".When
theseswitchesareturnedoninpairsmotorchanges
itsdirectionaccordingly.Like,ifweswitchonHigh
sideleftandLowsiderightthenmotorrotatein
forwarddirection,ascurrentflowsfromP\power
supplythroughthemotorcoilgoestogroundvia
switchlowsideright.Thisisshowninthefigure
below.
TruthTable
HighRight
LowLeft
LowRight
Description
On
Off
Off
On
Motorrunsclockwise
Off
On
On
Off
Motorrunsanticlockwise
On
On
Off
Off
Motorstopsordecelerates
Off
Off
On
On
Motorstopsordecelerates
HighLeft
~3~
Similarly,whenyouswitchonlowside
leftandhighsideright,thecurrent
flowsinoppositedirectionandmotor
rotatesinbackwarddirection.Thisis
thebasicworkingofHBridge.Wecan
alsomakeasmalltruthtableaccording
totheswitchingofHBridgeexplained
above.
co
Asalreadysaid,HbridgecanbemadewiththehelpoftransistorsaswellasMOSFETs;theonly
thing is the power handling capacity of the circuit. If motors are needed to run with high
current then lot of dissipation is there. So head sinks are needed to cool the circuit.
NowyoumightbethinkingwhyIdidnotdiscussthecaseslikeHighsideleftonandLowside
leftonorhighsiderightonandlowsiderighton.Clearlyseeninthediagram,youdon'twantto
burnyourpowersupplybyshortingthem.Sothatiswhythosecombinationsarenotdiscussed
inthetruthtable.
o.
SowehaveseenthatusingsimpleswitchingelementswecanmakeourownHBridge,orother
optionwehaveisusinganICbasedHbridgedriver.
R
ob
L293DDualHBridgeMotorDriver
.V
is
io
n
~4~
.V
is
io
n
R
ob
o.
co
AsimpleschematicforinterfacingaDCmotorusingL293Disshownbelow.
Asyoucanseeinthecircuit,threepinsareneededforinterfacingaDCmotor(A,B,Enable).If
youwanttheo/ptobeenabledcompletelythenyoucanconnectEnabletoVCCandonly2pins
neededfromcontrollertomakethemotorwork.
Asperthetruthmentionedintheimageaboveitsfairlysimpletoprogramthemicrocontroller.
ItsalsoclearfromthetruthtableofBJTcircuitandL293D theprogrammingwillbesamefor
bothofthem,justkeepinginmindtheallowedcombinationsofAandB.
~5~
R
ob
o.
co
InterfaceL293DwithAVR
FromHereItalkspecificallywithrespecttoourrobottocontrolamotorusingAVRwe
needtocontrol3pinsasshowninaboveA,Bandcorrespondingenable.Connectionsofmotor
toATmega8areasshownbelow.
.V
is
io
n
Soifyouwanttorunamotorinforwarddirectionyourcodewillbe
#include<avr/io.h>
intmain()
{
Step1Setpin2(PD0)andpin3(PD1)asoutputpin;
Step1Setpin15(PB1)asoutputpin;
Step2Send0atPD0and1atPD1;
Step3Send1atPB1;
While(1)
{
//doanyjobhere
}
Return0;
}
All4stepshererelatedtoinputoutputpinconfigurationofAVRsoIwillwritecodedirectlyfor
detailcheckI/Otutorial
~6~
.V
is
io
n
R
ob
o.
co
#include<avr/io.h>
intmain()
{
DDRD|=((1<<PORTD0)|(1<<PORTD1));
DDRB|=(1<<PORTB1);
PORTD|=1<<PORTD1;
PORTD&=~(1<<PORTD0);
PORTB|=(1<<PORTB1);
While(1)
{
//doanyjobhere
}
Return0;
}
Whatifyouwanttooscillatorymotion2secondforwardthento2secondreversethen2
secondbreak
#include<avr/io.h>
#include<avr/delay.h>
intmain()
{
DDRD|=((1<<PORTD0)|(1<<PORTD1));
DDRB|=(1<<PORTB1);
PORTB|=(1<<PORTB1);
uint8_ti;
While(1)
{//Forward
PORTD|=1<<PORTD1;
PORTD&=~(1<<PORTD0);
_delay_ms(100);
//reverse
PORTD|=1<<PORTD0;
PORTD&=~(1<<PORTD1);
_delay_ms(100);
//stop
PORTD&=~((1<<PORTD0)|(1<<PORTD1));
_delay_ms(100);
}
Return0;
}
~7~
MotorspeedcontrolusingPWM
co
IfandonlyifyouhavegonethoughPWMtutorialproceedfurther.Supposeyouwantto
runmotorbyhalfoftheitsratingspeedthensend50%dutycyclesquarewaveatenablepin
effectivelyyouwillget50%ontinebutduetohighfrequencyandinertiamotorseemstorun
continuouslysocodewillbe
#include<avr/io.h>
o.
intmain()
DDRD|=((1<<PORTD0)|(1<<PORTD1));
DDRB|=(1<<PORTB1);
PORTD|=((0<<PORTD0)|(1<<PORTD1));
//########################PWMcodetoget50%dutycyclesquarewaveat
enable(PB1)
TCCR1A=0xA1;
OCR1A=128;
TCCR1B=0x04;
//#########################
While(1)
{
//doanyjobhere
}
Return0;
}
.V
is
io
n
R
ob
HAPPYMOTORCONTROL
~8~