Need some help with an H-Bridge

Discussion in 'The Projects Forum' started by Carsten Svendsen, Oct 2, 2015.

  1. Carsten Svendsen

    Thread Starter New Member

    Oct 2, 2015
    17
    0
    TL;DR : Need help making a PWM controller for a motor that will run both ways using the same input for forwards and backwards.

    For a LEGO project I'm working on, I have some motors that draw too much power to be properly powered by my NXT unit.
    To fix this I wanted to build an H-bridge to put in-between each motor and the NXT.

    The output signal from the NXT is 9 volts which I want to use as the PWM signal
    The motors require a 12 volts source which I want to connect to a wall outlet for a steady power supply.

    Sometime ago, I had this schematic supplied to me and I simplified it a bit. I was told that I should calculate the resistor values myself using ohms law but as I don't know how the formula for electronic circuits go I just went and got some 1k and 10k resistors.

    [​IMG]

    I put all the stuff on a breadboard and nothing worked. Measuring where the power was didnt' help. I think the transistors might not be working as I'm sure I connected them the right way around.
    I did however put a + on input 1 and a - on input 2 and later I found out that transistors don't like negative voltage or something.

    If this schematic is correct however and using 1k and 10k is fine, then I guess I could try and make a new breadboard setup with new elements.

    This was because I want to not only go forwards but also backwards with the motors. The PWM signal just inverts the + and - signal. I do not know how to achieve this, but I thought maybe adding some diodes to make the power run in only one direction, but then again I don't know where I would put them if I also needed to ground the setup and since ground changes the wire it runs in when the motor is running the other way, I just don't know.
     
  2. Carsten Svendsen

    Thread Starter New Member

    Oct 2, 2015
    17
    0
    If anyone's interested in what I'm building here's a link for your enlightenment.
     
  3. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    If you control your four FETs with four port pins (instead of two), you can freewheel, run CW, run CCW, and even use dynamic braking. Using four port pins is the only way for newbies to make proper 12V H-bridges, because you can put software delays between turning on a PFET and then subsequently turning on the opposite NFET to avoid huge shoot-through currents that blow-up your expensive FETS.

    The Internet is absolutely full of poorly-conceived H-Bridges created by know-nothing newbies. I consider the one you posted as being poorly-conceived...
     
    Last edited: Oct 2, 2015
  4. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    If you insist to use two pins to control the directions then you can refer to the circuit as below.

    [​IMG]
     
  5. Carsten Svendsen

    Thread Starter New Member

    Oct 2, 2015
    17
    0
    Hi, thanks for the replies.
    I don't insist on using two pins only, that was just the diagram I found of a simple H-bridge. If what I want can be better achieved by using four pins, then that's just what I'm going to do instead. Assuming that you could provide a diagram of that for me.

    Soldering and stuff ain't no problem for me, but I would greatly appreciate if you could provide me with the correct resistor values, or at least give me a step-by-step guide to calculate them all. I do know about ohms law and stuff, I am an electrician after all but electronics just isn't my field of expertise.
     
  6. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    1. In 12V circuit that you don't need the zener diode or resistor voltage divider to protect the Vg.
    2. R1, R6 will affecting the turn on speed of Q1, Q2.
    3. R2, R7 will affecting the turn on/off speed of Q1, Q2.
    4. R3, R5, R8, R10 will affecting the turn on/off speed of Fet1~Fet4
    5. R4, R9 are used to protecting the Vg of Fet3, Fet4.
    6. I set the A,B and C,D as two pairs, a pair must be turn on at the same time, so they can they can be run as forward or backward, the other applications you can define by yourself.


    4Vin_H-bridge_Carsten_Svendsen-01_ScottWang.gif
     
    cmartinez likes this.
  7. Carsten Svendsen

    Thread Starter New Member

    Oct 2, 2015
    17
    0
    All right thanks.
    So you are telling me that I don't need R4 and R9 and the zener diodes for this circuit because it's 12v?
     
  8. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    The item 1. In 12V circuit that you don't need the zener diode or resistor voltage divider to protect the Vg, that is to describe the circuit in #4, normally Vgs can be input ±20V, when the input over 12V then using the resistor to do a voltage divider or using a 12V zener diode corss on Vgs to protecting Vg, the R4, R9 in the new circuit are used to protecting some accident when you input a higher voltage to the Vg, if you don't use R4, R9 then the circuit still can works fine, but the suggestion is to add them in.
     
  9. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    Great circuit, Scott

    My text below has the inputs in a different order than Scott drew them. I repeat Scott's schematic with the inputs following the order than matches the verbiage below:

    scott.gif

    Now to drive it:

    A, B, C, and D are all active-high, with pull-downs, which is ideal because while the micro boots-up, the port pins likely default to inputs, and float around. You do not want your H-Bridge going crazy during that time, and the pull-down resistors prevent that.

    In writing the code, the goal is to never, never, have A and C (or B and D) high at the same time!

    If we label the four port pins left to right ABCD, then the never, never, blow-things-up combinations are:
    Code (Text):
    1. abcd
    2. 0101=5   Avoid like the plague
    3. 0111=7
    4. 1010=A
    5. 1011=B
    6. 1101=D
    7. 1110=E
    8. 1111=F
    The useful combinations are:
    Code (Text):
    1. abcd
    2. 0000=0 All off, free-wheel, coast
    3. 0110=6 Run motor CCW
    4. 1001=9 Run motor CW
    5. 0011=3 Brake (quickly stop motor, keep it from freewheeling)
    6. 1100=C Brake (quickly stop motor, keep it from freewheeling)
    The non-useful combinations (but wont hurt anything) are:
    Code (Text):
    1. abcd
    2. 0001=1
    3. 0010=2
    4. 0100=4
    5. 1000=8
    Now the goal is to always:

    Never reverse the motor by going from state 6 directly to state 9 or vice versa. Always go through an intermediate state like state 0 for at least a few ms.

    Transition from state 0 to state 6 when starting the motor CCW

    Transition from state 6 to state 0 when stopping the motor

    Transition from state 0 to state 9 when starting the motor CW

    Transition from state 9 to state 0 when stopping the motor

    Use this sequence if PWMing the motor CCW 0-6-4-6-4-6-4...6-4-o (duty cycle % determined by how long in state 4 vs state 6)

    Use this sequence if PWMing the motor CW 0-9-8-9-8-9-8...9-8-o (duty cycle %)




    ps. Somebody, please proof read what I wrote...
     
    Last edited: Oct 3, 2015
    cmartinez and ScottWang like this.
  10. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    Hi Mike:
    Thanks for more explanation.

    The original I was labeled as you did, but I want to make AB and CD like a pair or group, so whatever the inputs of AB or CD equal to high(11) then they will run CW, CCW, and also let TS to decide to change the label if he likes.

    The CW/CCW conflict problem can be solved by hardware if needed, maybe just use 2 parts or to do some change and using 4 parts and it's done and not harm the circuit.


     
    Last edited: Oct 3, 2015
  11. Carsten Svendsen

    Thread Starter New Member

    Oct 2, 2015
    17
    0
    Hey thanks a lot for your help! I will get back to you once I get some new parts and see how it goes :)
     
  12. InspectorGadget

    Active Member

    Nov 5, 2010
    211
    42
    Just curious, why do people always use a BJT to invert the drive to the high-side P-FETs instead of using an N-FET there?
     
  13. crutschow

    Expert

    Mar 14, 2008
    13,000
    3,229
    Either will work but if your signal is a low-voltage logic level such as from a microprocessor, then you need a logic level MOSFET.
    All BJTs will work at logic level voltages, since the forward base-emitter voltage is only about 0.7V, and they likely are cheaper than logic-level MOSFETs.
     
    cmartinez and InspectorGadget like this.
  14. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    If you want to avoid the high side conflict as they are active at the same time, using the circuit in #6, you can do as this:
    Vg of Fet1 → (-)1N5817(+) → b of Q2
    Vg of Fet2 → (-)1N5817(+) → b of Q1
     
  15. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    I do not see how this avoids damaging conflicts if FET1 gets turned on at the same time as FET3 (or FET2 gets turned on at the same time as FET4). Having FET1 on at the same time as FET2 is not a conflict if neither FET3 nor FET4 are on.
     
    Last edited: Oct 4, 2015
  16. crutschow

    Expert

    Mar 14, 2008
    13,000
    3,229
    Below is an LTspice simulation of my take on a bridge with separate direction and PWM inputs that avoids any possibility of two transistors on the same side of the bridge being simultaneously on during PWM operation.
    To simplify the logic I added an additional P-MOSFET to perform the PWM function and use the bridge only for directional control.
    The simulation is shown with a PWM 50% duty-cycle.

    The Hex Inverter CD4049BC (not UBC) should be powered by the 12V supply (not shown).
    It will switch properly with the 9V input from the NXT.
    I paralleled four of the gates to better drive the PWM transistor gate capacitance.

    In operation it is best to turn off the PWM momentarily (9V logic-high input to U2, U3, U4 and U6) to allow the motors to stop before reversing the direction.
    Also only change the Direction signal when the PWM signal is OFF (high). (Not shown in the simulation).

    Edit: Because of observed high voltage glitches at the CMOS gate outputs, the PWM transistor was changed from an N-MOSFET to a P-MOSFET.

    Bridge.PNG
     
    Last edited: Oct 5, 2015
    cmartinez likes this.
  17. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    It just shown for the high side, if the low side still want to do that then it will need to do some change, the circuit as below that it shown as hint how to do the protection, normally if I want to do the complete protection then I will use some more parts, you can check does this has any mistake, thanks.

    4Vin_H-bridge_Carsten_Svendsen-02_ScottWang.gif
     
  18. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    But that is exactly the problem that started this thread. You either separate the control signals, like I did, (ABCD) and create some combinations that must be avoided, or you try to combine them, like you did, requiring fewer port pins, but eliminating the useful "braking" function in the process.

    Note that your method (as does mine) also requires you to create a "state machine" in the coding inside the controlling microprocessor which allows only certain correct sequences. First thing I did with your .asc file is to change dir with Vpwm low, and that instantly vaporizes the FETs.
    That sequence must be eliminated by restricting how you step between the four states defined by your two port pins..., which is equivalent to doing what I did with the four pins and no intervening logic.
     
  19. MikeML

    AAC Fanatic!

    Oct 2, 2009
    5,450
    1,066
    You missed my point! The problem is that the high-side cannot be treated independently of the low-side, and vice versa. Your diode steering logic does not eliminate the possibility that incorrectly coded sequences of the control bits will not intermittentely pass though a state which momentarily turns on both the PFET and NFET on one side of the bridge, leading to possible huge shoot-through current and/or destruction of the FETs.

    The only way of eliminating that possibility is to create a state machine which only advances from one valid state to the next valid state. That state machine can be coded in the controlling microprocessor, or can be created externally to the micro by using real gates/flip-flops, but it must have flip-flops in it; not just gates or steering diodes (combinatorial logic).
     
  20. ScottWang

    Moderator

    Aug 23, 2012
    4,853
    767
    I'm not missed your point, I just mentioned and drew the high side and let TS to think about the low side, if he no interesting then maybe I won't do it, I did it because you said that I didn't show the protection function, so I drew it, I knew that they can't separated from four mosfets, they must be considering together, the circuit what I drew was to avoid when the inputs code are 1111, it means that the four mosfets have the chance to turn on at the same time, so using the parts to inhibit the function for each other, if one turn on and the other won't turn on, so this way could let the hardware no chance to turn on at the same time that we call dummy prevent.

    A new idea may loss some angle to think of, so if through different members to see the circuit, maybe could find the weakness, I like to check other member's mistake, and I also like other members to check my errors, it just like a mirror to see myself.
     
Loading...