H-bridge, Control circuit - thingy.

Discussion in 'The Projects Forum' started by Roos, Jan 29, 2011.

  1. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    Hello everyone! :)

    I'm in the process of trying to create a vehicle that can drive around using 2 motors, thus changing the direction of the motors to turn corners.

    I use an ATMega16 to control the vehicle- to control each H-bridge 2 signals will be delivered.

    where i'm stuck is, that I an uncertain how I should connect these 2 signal to the h-bridge so that it will work as intended. I have drawn a basic Diagram which I hope will clarify what i'm asking

    I think I might be able to somehow hook up an ekstra pair of transistors so that (Q2, Q3) and (Q1, Q4) opens and closes as pairs.

    Not completely sure how to proceed though, also, I imagin i'll be making a small circuit using discreete logic to make sure the invalid input will never reach the bridge.(incase that will have an effect on the solution)

    I hope my question is clear (And has not been asked before)

    - Roos
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    See the attached schematic and simulation.

    You're going to lose anywhere between 0.7v and 1.6v per Darlington depending on your motor's load.
     
    Roos likes this.
  3. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Since the ATMEGA16 has 36 IO lines (provided you use a crystal), You may find it worthwhile to consider allocating 4 lines rather than 2 lines to the H-bridge. The added flexibility will prove useful. For example, you can implement dynamic braking by turning on both upper or both lower legs of the H-bridge.

    hgmjr
     
    Roos likes this.
  4. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    @SGTWookie
    In the setup you've made, my input signals (A,B) will only activate the lower part of the H-Bridge, but I see the upper part is connected to the collector.

    What will happen when for example A = 1 and B = 0, so that Q1 opens up for a current, will this cause Q4 to open up as well?

    (Sorry for the "stupid" question, i'm kinda new to transistors.)


    @hgmjr

    What you are suggesting sounds quiet interesting - However, as I had understood turning on all transistors will burn off the H-bridge?

    how would this dynamic braking work, if you care to elaborate?

    Thanks in advance :)
     
  5. arthur92710

    Active Member

    Jun 25, 2007
    307
    1
    By turning on both Q3 and Q4, the motor is 'shorted'. While spinning on its own it produces a voltage. The voltage then tries to spin the motor in the opposite the direction. It will slow down faster then just opening the transistors.

    You might use if if the robot stops on an incline...
     
    Roos likes this.
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    The PNP Darlington bases are wired to the opposite side NPN Darlington collectors.

    In the case of A=1 (5v), B=0 (0v):
    Q1 is turned ON, and starts sinking current via its collector to its emitter. There is a wire connecting the collector of Q1 to the right side of R6, which limits base current for Q4, the PNP on the upper right side, turning it on. Current begins flowing from the emitter through the collector of Q4, through L1 (the motor), then down through Q1 to ground.
    Q2 remains OFF; if it turned on then there would be a dead short from Q4 through Q2 to ground.

    You may find that R1 through R4 are a bit too large in value if your motor current is heavy. You could reduce them to 10k or so with little penalty.


    Not a stupid question at all. ;)


    You'd need to add a couple of NPN transistors to pull down the bases of the PNP transistors to get the braking functionality.

    Basically, if both high-side transistors are OFF and both low-side transistors are ON, you get a current path through the lower transistors and the motors. But, the same kind of thing happens with the diodes in the middle of the bridge.

    The TIP120 and TIP125 transistors both have integral body diodes, but it's a good idea to have fast-recovery external diodes like you've shown.

    Do a search for their datasheets to see what the electrical connections inside are.
     
  7. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    You can obtain the same braking action by turning on Q1 and Q2 at the same time with Q3 and Q4 turned off.

    hgmjr
     
    Last edited: Jan 29, 2011
  8. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    It should be noted that this braking action is only available if you provide individual controls to all four transistor switches in the H-bridge from the microcontroller.

    hgmjr
     
  9. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    alright, I think I get it now, most of it anyway ;)

    Does that mean, the Diodes I have (Which I added to make sure the inductive current had a place to go when the robot stops) will give the same functionality as controlling all the transistors?

    What was meant here is to have the abilllity to turn on the 2 lower transistors also, while the two top ones stay turned off, right?
    Would the same function then be achieved if it was reversed so that the 2 top ones was on and the 2 lower ones was off?
     
  10. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    The diodes will give you a measure of braking. The ability to turn on both bottom or both top transistors in the H-bridge provide a more aggressive braking control.

    yes.

    hgmjr
     
  11. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    Awesome, I think I got everything I need now to nail this down (Or rather Solder I guess ;) )

    Thank you everyone - Much appreciated. :D Have a nice weekend.

    Oh and btw, the abillity to control all 4 Transistors should be able to be done with 2 signals, if I mess around with some logic gates, I imagin. I'll have to play around with those "bricks".
     
  12. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    I have done a lot of programming with AVR micros and ATMEGA16 in particular. When you are ready to code be sure to come back and gives us a chance to assist you.

    Which programmer have you chosen?

    Are you using the free software development tools AVRSTUDIO4 and WINAVR?


    hgmjr
     
  13. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    I am using the Codevision C-compiler, and I guess to some extend the AVRStudio (mostly if I need to write some code in Assembly)

    I don't know what is best for it, I mostly use it because we use it in my school so it's close to what I use in my everyday life ;)

    If you want to see my code, I actually have a little test code snipet, maybe you can tell me if my basic Idea works?

    Code ( (Unknown Language)):
    1.  
    2. #include <mega16.h>
    3. #include <stdio.h>
    4.  
    5. void main()
    6.  {
    7.     unsigned int x;
    8.     DDRA = 1; // PortA is set as Output
    9.     DDRB = 0; // PORTB is set as Input
    10.    
    11.     while(1)
    12.     {
    13.         x = PORTB.0;
    14.        
    15.        
    16.         while(x == 0) // x is 0 when no object is in front of the robot
    17.         {
    18.         // Motor1 drives forward
    19.             PORTA.0 = 1;
    20.             PORTA.1 = 0;
    21.         // Motor2 drives forward
    22.         PORTA.2 = 1;
    23.         PORTA.3 = 0;
    24.         }
    25.         // if x is 1, an object should be infront on the robot
    26.         PORTA.0 = 0; // motor1 stopped
    27.         PORTA.2 = 0; // motor2 stopped    
    28.     }
    29.  }
    30.  
    It's extremely simple so far, and is mostly meant to prototype my circuits, when I get them build, to PORTB.0 I was hoping to hook up this nifty little thing: GP2Y0D805Z0F

    So to start off with the thing would be able to sense something infront of it and stop all motors (is the theory).
     
  14. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    In your initialization sequence, make certain that PORTA.0 = 0;
    PORTA.1 = 0;
    and that PORTA is set to OUTPUT.
     
  15. Roos

    Thread Starter New Member

    Jan 29, 2011
    6
    0
    ah yes of course, I better initialize all the H-bridge bits to 0, so that I am certain the robot will not run random in the beginning.

    The command "DDRA = 1;" should set alle pins in portA as output. :)

    Know anything about the Sensor thing, or maybe better / cheaper solutions than the one I have found?
     
  16. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    Without a schematic, it is not entirely certain that you have taken care of all of the housekeeping chores that need to be addressed.

    hgmjr
     
Loading...