Trying to make an H-bridge

Discussion in 'The Projects Forum' started by cremaster, Jul 19, 2010.

  1. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    I want to create an H-bridge to power a 5 volt DC motor. Here are my components:

    1. a 5 volt power adapter
    2. four toggle switches

    I will connect the components in the same way as is represented on this page:
    http://en.wikipedia.org/wiki/H-bridge

    And I will flip the switches manually.
    Will that work? Do I need anything else?

    I think it will work, but I have very little experience and it seems too simple to be true.
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Sure, that will work. However, if you use four SPST switches it will be very easy to accidentally turn on both the high-side and low-side switches, causing a dead short across the power supply. This often results in lots of smoke.

    If you used a pair of SPDT switches, with the common terminals connected to opposite ends of the motor, you would prevent such an accident from happening.

    In the image below, just imagine that the supply is 5v instead of 10v.

    [​IMG]
     
  3. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    DP3T is the minimum I would use for an H bridge.

    That gives you forward and reverse with a center motor off position.

    Doing the job with transistors is even better.
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Well, our OP stated that they have very little experience.

    There are many ways to skin the proverbial cat. I wanted to keep things simple for them, to minimize any possibility of confusion - while making it reasonably "goof proof".

    If wired correctly, the circuit I posted will allow full speed in either direction, and braking.

    The DP3T is widely used for DC motor reversal. However, a single DP3T switch does not provide for braking action in the center off position.

    The L293 has been around for years, and is convenient to use. However, that would be somewhat bewildering for a n00b.
     
  5. Potato Pudding

    Well-Known Member

    Jun 11, 2010
    684
    92
    True enough. I am not certain if freewheeling would be an issue but it certainly could be and so could sparking from the motor. It is not enough to say DP3T without explaining how the center off position needs to be wired.

    Using 2 SPDT switches should simplify things and it will get the job done.

    It does make the controls a bit tricky was my concern. Pick a switch - one will be for forwards and one will be for reverse, and there are two off states with each off state changing which switch will switch into which direction. It is not that tricky because putting the switch into the right position is always the same. I would advise that they be wired with both switches up for forward and both switches down for reverse.
     
    Last edited: Jul 19, 2010
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Freewheeling diodes would be a good addition; it would reduce/eliminate the arcing that will occur when the switches are in transition from a motor "run" state. However, I wanted to have our OP take just one step at a time.

    Adding four diodes to the schematic would have made it harder to understand, and perhaps a bit intimidating. Just getting a pair of switches connected to a motor and power source can be challenging for a newbie.

    I hope they come back and report success with the initial configuration, which should be reasonably easy to understand. Then they can learn about the freewheeling diodes, and try adding them in.

    Just in case they come back and want to try adding the diodes, here's an updated schematic:

    [​IMG]

    The diodes could be any standard rectifier diodes. A 1N4001 thru 1N4007 diode assortment pack are available at Radio Shack in a 25-pack for a dollar or two. Diodes have a band on one end that is a different color than the rest of the body. 1N4001-1N4007 diodes typically have black bodies with a white band. The end with the band is the cathode end, the other end is the anode. In the schematic, the cathodes are oriented towards the top of the schematic.
     
  7. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    Hi again,
    I wired it up and it all worked perfectly. Thank you all for your help and good suggestions. I did end up using 4 SPST switches because its all I had and I was eager to get it working.

    I have a few diodes I could use too. Ive read a little bit about back EMF, in this scenario what might be at risk? I assume it to be quite a small risk, could the switches be burnt out, or the adapter?

    Now I am wondering about using transistors. If I replaced the four switches with transistors, could I then control the motor via four pins of my parallel port?
     
  8. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    605
    24
    I wouldn't worry too much about burning out the switches. I would suggest that if you are thinking of using transistor to think about using MOSFETS. Much better option or even a special purpose IC like the L293 or L298 already suggested. There is another IC LMD18200 which is a bit more expensive but can drive bigger motors.
     
  9. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    That's fine; glad you got it working. Building something that works is important. :) Keep in mind the caution I mentioned in my first reply; turning on the high and low switches on one leg will short out the supply, likely resulting in smoke. :eek:

    The back-EMF occurs when the path for coil current through the switch is broken; and the magnetic field around the coil collapses. The voltage polarity across the coil swaps as the coil tries to maintain the current flow. The peak EMF voltage spike can be very high. This causes arcing across the switch contacts until the power is dissipated.

    If the motor is low power, the arcing/pitting of the switch contacts will be minor, but will accelerate wear if the circuit is to be in use for an extended period of time. You don't HAVE to use the diodes, but it'll make the switches last quite a bit longer, as there will be very little if any arcing going on.

    Depending on the current the motor requires, you might look at the L293D, or L297/L298 combination like has already been suggested; you would need to use a higher supply voltage (9v minimum, 12v or higher preferred) for the L297/L298 combination. These ICs are everywhere; they have been industry standard parts for quite a while. They are rather "long in the tooth", as they use bipolar junction transistors internally rather than MOSFETs.
     
  10. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    Is there anything I need to know if I were to try using discrete transistors instead of an IC to replace the four switches?

    I could then have four pins of my parallel port drive the motor via those transistors, right?

    I assume in this scenario back EMF is worthy of much more attention, so I would add diodes to be safe.
     
  11. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Driving transistors via the parallel port is risky. If you make a mistake, or if the transistors happen to short out, you may wind up overloading and burning out your port. If it's built into the motherboard, guess what you'll have to do to fix it?

    Replace the motherboard.

    If you want to experiment with using the LPT port to drive a stepper, you'll have a hard time if you're using a version of Windows later than Win98. From Win2k on, it gets rather tricky to wrest control of the parallel port from Windows. You should also use an add-on multi-IO card instead of your mobo's LPT port. In case you fry the card, you won't have to replace your mobo.
     
  12. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    I certainly do not want to replace my motherboard. I had surprisingly little trouble however gaining control of the parallel port using C#. I used a .dll called inpout32 for interfacing with the LPT and it worked like a charm.

    I'll most likely use an older PC to experiment with control via parallel port. Motherboard concerns aside though, is it as simple as replacing those four switches with four discrete transistors in order to drive the current with pin voltage? I would add diodes to the mix, but is there anything else I need to replicate the switch functionality using transistors?

    The reason I want to avoid an IC for the moment is because I'd like to start with the most basic components and work my way up so that when I do use an IC I'll have an exact idea of whats going on inside.

    Thank you for the help!
     
  13. windoze killa

    AAC Fanatic!

    Feb 23, 2006
    605
    24
    If you are planning on doing a bit of project related stuff with a PC I would recommend you building some sort of optocoupler board. Just use it for proof of design and once you prove it works you can remove it. I have one and it has saved my PC (even if it is an old boat anchor) on many occassions.
     
  14. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    Can someone help: is it as simple as replacing the four switches with four discrete transistors of the correct variety?

    Or is there something else I need to consider?
     
  15. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You're going to have to figure out a good way to drive the bases of transistors (if you go the BJT route) or the gates of MOSFETs (if you go that route).

    For logic level N-ch MOSFETs, the lower half of the H-bridge is a piece of cake. If you're going to be operating at low speed, you can drive them directly from TTL.

    The high-side MOSFETs are not so easy. It's best to use N-channel MOSFETs all the way around, but then you need a high-side driver; either a pre-made IC or out of discrete components.

    If you use P-channel MOSFETs on the high side, and your supply voltage is 10v or more, then the control becomes more easy. However, P-channel MOSFETs are considerably slower than their N-channel counterparts. The gate for the complementary P-ch is much larger (more than twice as large), so it takes more time to charge/discharge the gate.

    Shoot-through is a big problem for n00bs working on H-bridges. You must provide "dead time", where both the high and low side MOSFETS are OFF for a period of time, before turning on one or the other. If both are ever on simultaneously, even for a brief period of time, you will create a dead short across the power supply, and something is going to break - usually the MOSFETs get burned to a crisp.

    What is the motor's current and voltage rating? You'd mentioned 5v before, but never the current requirement, and I'm not certain that you're talking about the same motor now.
     
    Last edited: Jul 29, 2010
  16. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  17. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
  18. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    You should use 2N2222 (npn) and 2N2907 (pnp) transistors. Your motor will draw quite a bit more current if it's starting from a stop or with a load on it.

    Yep.

    Ahh, they're identical, but shown in mirror image.
    The upper transistors are PNP, the lower transistors are NPN.

    Motors draw current according to their load, and the voltage applied.
    If the motor's rotor is locked, it will draw considerably more current than if it were allowed to spin freely with no load attached.

    Note that the circuit you are considering should also have a capacitor across the motor, somewhere between 100nF (0.1uF) and 1uF, inclusive.

    It should also have the four diodes I mentioned previously.
     
  19. cremaster

    Thread Starter New Member

    Jun 30, 2010
    19
    0
    I have a few questions of clarification about the circuit shown here:
    http://www.solarbotics.net/library/circuits/driver_4varHbridge.html

    1. The two voltage inputs at the top and the two grounds at the bottom; does this mean there must be two sources of electricity? When I ran the motor previously via the four micro switch H-bridge I used a wall adapter for 4.5 Volts and 300mA. Would I need two adapters for this circuit?

    2. The boxes with an S shape on them immediately below A and B in the circuit; what are those?

    3. Ive added some diodes to the image according to my best idea of where they should be located and have attached the result:
    H.jpg

    4. In an image you attached previously (SgtWookie), http://forum.allaboutcircuits.com/attachment.php?attachmentid=21210&d=1279569607
    the orientation of the diodes is confusing to me, I dont understand why there should be diodes where there was no connection to begin with.

    Forgive me if Ive been ignorant of some fundamentally important things. Im off to the library today or tomorrow to pick up a textbook and start filling the gaps in my knowledge.
     
  20. masked

    Member

    Jul 1, 2010
    48
    1
    Hi Cremaster,

    1: No you don't need two voltage sources. You can connect the left & right ground on both halves to the same ground, and both positives to the same +V source. (You can consider them wired in parallel, but only one side will have current flowing through it at a given time.)

    2: Those are inverters (see http://www.electronics-tutorials.ws/logic/logic_9.html ). If you read his 5th bullet point below the image, you'll see that he mentions them. Basically when you use transistors in a 10v circuit instead of manual switches, you need to supply them with a small signal rather than frying them with 10v.

    3 & 4: You need to change the diodes in your picture. to match Wookie's drawing. Normally, a diode is installed the way you drew them... but in this case you will need to install them backwards with the cathode toward the positive side. You also need them connected to your voltage source rather than in series with the motor. The reason is because when a motor is stopped, the windings create a small spike of current in the opposite direction, so the "backwards" (or reverse biased) diodes will allow for that reverse spike to flow back out to the circuit rather than backwards through your transistors.


    I was a total newbie a few weeks ago and, though the one project i've been working on is similar to yours, you may want to take my input with a grain of salt.

    -masked
     
Loading...