You are on page 1of 9

MOTOR DRIVER L293D

Developed by: Krishna Nand Gupta Prashant Agrawal Mayur Agarwal

.V

is io n

R ob
RightMotor Straight Straight Straight Stop Reverse Reverse

Differentialdrive Byusingtwomotorswecanmoveourrobotinanydirection.Thissteeringmechanismofrobot iscalledasdifferentialdrive. Letscheckhowitworks

o.

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.

co
RobotMovement Straight Left Sharpleft Right SharpRight Reverse

LeftMotor Straight Stop Reverse Straight Straight Reverse

~1~

DCMotorwithGear TheDCmotorsdonthaveenoughtorquetodrivearobotdirectlybyconnectingwheelsinit. Gearsareusedtoincreasethetorqueofdcmotorontheexpenseofitsspeed. Mathematicalinterpretation: Rotationalpower(Pr)isgivenby: Pr=Torque(T)*RotationalSpeed() Thus PrisconstantforDCmotorforaconstantinputelectricalpower.Thustorque(T)isinversely proportionalspeed(). Thustoincreasethevalueoftorquewehavetoloosespeed. Note: Intoycar,thereisagearboxthatcontainsseveralcombinationsofgears. Gearedmotorhasgearsboxatitsfront.

.V

is io n w
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.

R ob
~2~

o.

co

is io n .V w
TruthTable LowLeft Off On Off On LowRight On Off Off On

HighLeft On On Off Off

HighRight Off On On Off

R ob

Similarly,whenyouswitchonlowside leftandhighsideright,thecurrent flowsinoppositedirectionandmotor rotatesinbackwarddirection.Thisis thebasicworkingofHBridge.Wecan alsomakeasmalltruthtableaccording totheswitchingofHBridgeexplained above.

~3~

o.
Description

Asyoucanseeinthefigureabovetherearefour switchingelementsnamedas"Highsideleft","High sideright","Lowsideright","Lowsideleft".When theseswitchesareturnedoninpairsmotorchanges itsdirectionaccordingly.Like,ifweswitchonHigh sideleftandLowsiderightthenmotorrotatein forwarddirection,ascurrentflowsfromP\power supplythroughthemotorcoilgoestogroundvia switchlowsideright.Thisisshowninthefigure below.

Motorrunsclockwise Motorrunsanticlockwise Motorstopsordecelerates Motorstopsordecelerates

co

SowehaveseenthatusingsimpleswitchingelementswecanmakeourownHBridge,orother optionwehaveisusinganICbasedHbridgedriver. L293DDualHBridgeMotorDriver

L293D is a dual HBridge motor driver, so with one IC we can interface two DC motors which can be controlled in both clockwise and counter clockwise direction and if you have motor with fix direction of motion. You can make use of all the four I/Os to connect up to four DC motors. L293D has output current of 600mAandpeakoutputcurrentof 1.2A per channel. Moreover for protection of circuit from back EMF output diodes are included within the IC. The output supply (VCC2) hasawide rangefrom 4.5V to 36V, which has made L293DabestchoiceforDCmotordriver.

.V

is io n
~4~

R ob

o.

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.

AsimpleschematicforinterfacingaDCmotorusingL293Disshownbelow.

.V

is io n

Asyoucanseeinthecircuit,threepinsareneededforinterfacingaDCmotor(A,B,Enable).If youwanttheo/ptobeenabledcompletelythenyoucanconnectEnabletoVCCandonly2pins neededfromcontrollertomakethemotorwork. Asperthetruthmentionedintheimageaboveitsfairlysimpletoprogramthemicrocontroller. ItsalsoclearfromthetruthtableofBJTcircuitandL293D theprogrammingwillbesamefor bothofthem,justkeepinginmindtheallowedcombinationsofAandB.

R ob
~5~

o.

co

InterfaceL293DwithAVR FromHereItalkspecificallywithrespecttoourrobottocontrolamotorusingAVRwe needtocontrol3pinsasshowninaboveA,Bandcorrespondingenable.Connectionsofmotor toATmega8areasshownbelow.

R ob
~6~

o.
Soifyouwanttorunamotorinforwarddirectionyourcodewillbe #include<avr/io.h> intmain() { Step1Setpin2(PD0)andpin3(PD1)asoutputpin; Step1Setpin15(PB1)asoutputpin; Step2Send0atPD0and1atPD1; Step3Send1atPB1; While(1) { //doanyjobhere } Return0; } All4stepshererelatedtoinputoutputpinconfigurationofAVRsoIwillwritecodedirectlyfor detailcheckI/Otutorial

.V

is io n

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

.V

is io n
~7~

R ob

o.

co

MotorspeedcontrolusingPWM
IfandonlyifyouhavegonethoughPWMtutorialproceedfurther.Supposeyouwantto runmotorbyhalfoftheitsratingspeedthensend50%dutycyclesquarewaveatenablepin effectivelyyouwillget50%ontinebutduetohighfrequencyandinertiamotorseemstorun continuouslysocodewillbe #include<avr/io.h> intmain() {

HAPPYMOTORCONTROL
~8~

.V

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

is io n

R ob

o.

co

You might also like