8051 and H-Bridge <newbie question>

Discussion in 'Embedded Systems and Microcontrollers' started by sandraos, Jun 28, 2009.

  1. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    [electronics and microcontroller newbie]

    Hi all,
    I'm trying to get a DC motor to spin backwards and forwards.
    I'm getting ~ -39 mA and ~ +44 mA to the motor. Source is a 9V battery.
    Obviously it's not getting the necessary amps. It just clicks back and forth but doesn't rotate.
    Any ideas? What am I doing wrong? It needs at least 100 mA for decent rotation.
    But please don't ask me to use "such and such doo-hickey". I'm into the electronics hobby to learn about electronics. I don't want to just plug in IC's.
    I included the program and schematics.
    Thanks for everything,
    Salim
    //------------------------------------------------------------
    sfr at 0x90 P1;
    sfr at 0x89 TMOD;

    sbit at 0x8C TR0;
    sbit at 0x8D TF0;

    void forward(void);
    void reverse(void);
    int overFlowCounter = 0;

    void main(void)
    {
    TMOD = 0x01; // 16-bit timer. No gate, no C/T
    TR0 = 1; // run timer0

    while (1)
    {
    if (TF0)
    overFlowCounter++;
    if (overFlowCounter < 2550) // Leads to approx. 1.5 secs with 11.059200 Mhz crystal.
    forward();
    else
    reverse(); // ...and 1.5 secs in reverse.

    if (overFlowCounter > 5100) // crude but gets the job done for now
    overFlowCounter = 0;
    }
    }
    void forward(void)
    {
    P1 = 0x01;
    }
    void reverse(void)
    {
    P1 = 0x02;
    }
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    According to your drawing, you are trying to run this whole system from a 9 volt source. If that is a battery, then that is a problem. A 9 volt battery is capable of current on the order of 15 ma for reasonable periods. You may have to use a more substantial power source, like a wall transformer.

    Another potential problem is driving those 2N3906's straight from a uC pin. Once a transistor has enough voltage across the B-E junction to go into conduction, it has no means of current limiting. You must use resistors between the base of each transistor and the drive pin to hold current down. One absolute limit is the rating for the uC's high level output. If current exceeds that level then the uC will be permanently damaged.

    The H-bridge transistors probably need 5 - 10 ma current in the base to saturate strongly enough to run the motor.

    It's a good idea to insure the hardware will work before proceeding in a project.
     
  3. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    Hi there beenthere,
    "A 9 volt battery is capable of current on the order of 15 ma for reasonable periods. You may have to use a more substantial power source, like a wall transformer."
    Can't use a wall transformer. The circuit is going into a little toy car.
    When I measure the amps on the battery by itself, I get 8.77 V and ~3.8 Amps. Where are the amps going? Could you elaborate on that please.


    "You must use resistors between the base of each transistor and the drive pin to hold current down."
    Is the drive pin the pin that leads to the motor? If so, connect it from the base to that pin? Also what value resistors am I looking at? Or just use values to bring down transistor current to 10 mA?


    And thanks again. This forum has been a great help!
     
  4. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    You may be able to obtain several amps briefly with an ammeter (like placing a dead short across the terminals), but 9 volt batteries are not up for more than a few mills - http://www.techlib.com/reference/batteries.html

    As far as controlling transistor base current goes, the resistors go in series with each transistor base and the uC drive pin. Check the specs on the uC to see the amount of current the device can safely sink per pin.

    The uC switches between 0 and 5 volts. Each transistor will drop about .7 volts when in conduction. To choose a resistor, subtract the .7 volts from 5 (4.3 volts), and use the formula R = E/I. R is resistance, I is current, and E is voltage (4.3). Don't allow more current than the uC can handle.
     
  5. sandraos

    Thread Starter Member

    Jun 8, 2009
    12
    0
    Wow now that's detailed!!! Thanks a lot Beens
     
  6. millwood

    Guest

    the schematic is largely correct: you may need some base resistors to prevent shooting out the transistors, and you also need some kick-back diodes to protect the transistors against the motor.

    with a 9v battery, the voltage applied to the motor is about 9v-0.2(typical mcu voltage loss) - 0.7*2 (Vbe lose on two b-e junctions)=7.5v. if you are getting 40ma without the motor moving, its DC resistance is about 7.5/40ma=200ohm.

    that is high for a 12v motor so you can either find a motor rated for lower voltage, or you can increase the drive voltage on the h-bridge. doing that would require a redesign of the driver circuitry.
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    The transistors are wired as emitter followers. Because of this, the maximum voltage you'll see on the upper transistors' emitters is the high output voltage of the 8051 (perhaps as much as 5v) less around 0.7v for the Vbe drop, for a total of around 4.3v tops.

    At the same time, the lower transistors' minimum voltage on the emitter will be the low output voltage of the 8051 (perhaps as low as 0v) plus around 0.7v for the Vbe drop.

    This gives a maximum possible voltage across the motor of 4.3v - 0.7v = 3.6v.
    [eta]
    See the attached simulation to view the difference you'd get if you built your bridge differently. An equivalent to your circuit is on the right. Transistors used in the simulation were PN2222 and PN2907. Note that in your version of the circuit, the voltages across the motor are much lower than the circuit on the left.
     
    Last edited: Jul 5, 2009
Loading...