AVR Programming for DC Motor Interfacing (1)

Embed Size (px)

Citation preview

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    1/7

    DC Motor interfacing with Microcontrollers tutorial: Introduction

    Introduction

    Whenever a robotics hobbyist talk about making a robot, the first thing comes

    to his mind is making the robot move on the ground. And there are always twooptions in front of the designer whether to use a DC motor or a stepper motor.When it comes to speed, weight, size, cost... DC motors are always preffered

    over stepper motors. There are many things which you can do with yourDC

    motor when interfaced with a microcontroller. For example you can control the

    speed of motor, you can control the direction of rotation, you can also doencoding of the rotation made by DC motor i.e. keeping track of how many

    turns are made by your motors etc. So you can see DC motors are no less than

    a stepper motor.

    In this part of tutorial we will learn to interfacing a DC motor with a

    microcontroller. Usually H-bridge is preffered way of interfacing a DC motor.These days many IC manufacturers have H-bridge motordrivers available in the

    market like L293D is most used H-Bridge driver IC. H-bridge can also be madewith the help of trasistors and MOSFETs etc. rather of being cheap, they only

    increase the size of the design board, which is somtimes not required so using

    a small 16 pin IC is preffered for this purpose.

    Working Theory of H-Bridge

    The name "H-Bridge" is derived from the actual shape of the switching circuit

    which control the motoion of the motor. It is also known as "Full Bridge".

    Basically there are four switching elements in the H-Bridge as shown in thefigure below.

    As you can see in the figure above there are four switching elements named as

    "High side left", "High side right", "Low side right", "Low side left". Whenthese switches are turned on in pairs motor changes its direction accordingly.

    Like, if we switch on High side left and Low side right then motor rotate in

    forward direction, as current flows from Power supply through the motor coil

    goes to ground via switch low side right. This is shown in the figure below.

    Similarly, when you switch on low side left and high side right, the current

    flows in opposite direction and motor rotates in backward direction. This is the

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    2/7

    basic working of H-Bridge. We can also make a small truth table according to

    the switching of H-Bridge explained above.

    Truth Table

    High Left High Right Low Left Low Right Description

    On Off Off On Motor runs clockwise

    Off On On Off Motor runs anti-clockwise

    On On Off Off Motor stops or decelerates

    Off Off On On Motor stops or decelerates

    As already said, H-bridge can be made with the help of trasistors as well as

    MOSFETs, the only thing is the power handling capacity of the circuit. If

    motors are needed to run with high current then lot of dissipation is there. Sohead sinks are needed to cool the circuit.

    Now you might be thinkin why i did not discuss the cases like High side lefton and Low side left on or high side right on and low side right on. Clearlyseen in the diagra, you don't want to burn your power supply by shorting them.

    So that is why those combinations are not discussed in the truth table.

    So we have seen that using simple switching elements we can make our own

    H-Bridge, or other option we have is using an IC based H-bridge driver. Both

    of them are discussed in the next section of the tutorial.

    Previous Page | Next Page

    DC Motor Tutorial IndexDC Motor Introduction Interfacing L293D

    BJT Based H-Bridge Programming for DC Motor

    Google Search for Microcontrollers!

    Enter your search terms Submit search

    formSearch

    Web 8051projects.net

    This work is licensed under a

    Creative Commons Attribution-Noncommercial 2.5 India License.

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    3/7

    Rickey's World Disclaimer

    DC Motor

    interfacing with Microcontrollers tutorial: BJT Based H-Bridge for DC motors

    BJT H-Bridge

    A simple H-bridge can be made with the help of Power BJTs like TIP31 and TIP32. An example

    and a working demo of this circuit is shown in the figure below.

    BJT H-Bridge Demo

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    4/7

    DC Mot

    L293

    L293D i

    can be c

    fix direc

    motors.

    Moreove

    output s

    for DC

    A simple

    C pr

    CODE:#i ncl umot or #def i n#def i n

    r interfacin

    D Dual H

    a dual H-B

    ntrolled in

    ion of moti

    293D has

    r for protec

    pply (VCC

    otordriver.

    schematic

    grammin

    de #d

    B P2_1E P2_2

    Previous

    controllers

    otor Drive

    driver, So wi

    ise and cou

    an make use

    t of 600mA

    t from back

    range fro

    g a DC mo

    ef i ne L2

    //

    Page | Next

    tutorial: L2

    r

    th one IC w

    ter clockwi

    of all the f

    and peak o

    EMF oupu

    4.5V to 36

    or using L2

    93D_A P

    / Negat i/ Enabl e

    age

    3D H-Brid

    e can interf

    se direction

    ur I/Os to c

    tput curren

    diodes are

    V, which ha

    93D is sho

    _0

    e of motof L293

    ge interfaci

    ce two DC

    and if you

    onnect up t

    t of 1.2A pe

    ncluded wi

    s made L29

    n below.

    / / P o

    or

    g

    otors whi

    ave motor wi

    four DC

    r channel.

    hin the IC.

    3D a best c

    i t i ve o

    h

    th

    he

    oice

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    5/7

    // Function Prototypesvoi d rotate_f( voi d) ; //Forward run funtionvoi d rotate_b( voi d) ; //Backward run functionvoi d br eaks( voi d) ; //Motor stop function

    voi d del ay( voi d) ;//Some delay

    voi d mai n( ) { //Our main functionwhi l e( 1) { //Infinite loop

    rotate_f( ) ; //Run forwarddel ay( ) ; //Some delaybr eaks( ) ; //Stopdel ay( ) ; //Some delayrotate_b( ) ; //Run Backwardsdel ay( ) ; //Some delaybr eaks( ) ; //Stopdel ay( ) ; //Some delay

    } //Do this infinitely}

    voi d rotate_f( ) {L293D_A = 1; //Make positive of motor 1L293D_B = 0; //Make negative of motor 0L293D_E = 1; //Enable L293D

    }

    voi d rotate_b( ) {L293D_A = 0; //Make positive of motor 0

    L293D_B = 1; //Make negative of motor 1L293D_E = 1; //Enable L293D

    }

    voi d br eaks( ) {L293D_A = 0; //Make positive of motor 0L293D_B = 0; //Make negative of motor 0L293D_E = 0; //Disable L293D

    }

    voi d del ay( ) { //Some delay...

    unsi gned char i , j , k;f or ( i =0; i

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    6/7

    As you can see in the circuit, three pins are needed for interfacing a DCmotor (A, B, Enable). If you want the o/p to be enabled completely then

    you can connect Enable to VCC and only 2 pins needed from controller

    to make the motor work.

    As per the truth mentioned in the image above its fairly simple toprogram the microcontroller. Its also clear from the truth table of BJT

    circuit and L293D the programming will be same for both of them, just

    keeping in mind the allowed combinations of A and B. We will discuss

    about programming in C as well as assembly for running motor withthe help of a microcontroller.

  • 7/28/2019 AVR Programming for DC Motor Interfacing (1)

    7/7