The Basic MOSFET H-Bridge
Here is a basic mosfet h-bridge. Q1 and Q2 are P-Channel mosfets, while Q3 and Q4 are N-Channel mosfets. (Other configurations are possible, but are out of the scope of this article.)
The circuit is the same as the simple h-bridge discussed on page 2, but with the switches replaced by Mosfets, which are like electronic switches.
You will notice that there are diodes placed across the mosfets. Usually mosfets have internal diodes, but it is a good idea to add external diodes, just to be safe. These diodes should be high speed schotky diodes, with an appropriate current rating. When motors rapidly change direction, the back EMF generated inside the motor can damage mosfets. These diodes are in place to absorb the back EMF, and to keep the mosfets safe. Do not ignore these diodes, as they are necessary to keep your H-Bridge from being destroyed.
When choosing mosfets, it is important that they will be able to handle the maximum current required by your motors. This is the stall current. If the mosfets you chose are insufficient, it can cause your motor driver to go up in smoke if your motors approach stall.
Choosing the correct mosfet can be tricky, especially when higher currents are involved. You need to take thermal and power limits into account. Chuck McManis does an excellent job of describing it on his website: http://www.mcmanis.com/chuck/robotics/projects/esc2/FET-power.html
One point that needs to be hammered across is that it is of the utmost importance that Q1 and Q3 (or Q2 and Q4) must NEVER be on at the same time. Not even for a split second. It will cause bad things to happen!!!
An Easier Way to Control It
So now that we have a basic h-bridge circuit, how do we use it?
It is possible to take all four input lines and control them from a micro controller, but for a variety of reasons this is not a good idea. If you are controlling each mosfet separately, you need to take care not to accidentally switch on the wrong combination of mosfets at the same time. Further, if your micro controller locks up for some reason or another, random signals may appear on the output pins, causing bad combinations of mosfets to activate which can lead to shoot-through.
Update: A reader previously pointed out that this circuit doesn’t actually help prevent shoot-through by itself. I’m leaving the text here, but if using this circuit, you’ll need to address shoot-through by other means, for example by using a half-bridge gate driver which protects the user from shoot-through between this circuit and the FETs.
I like to use the following simple circuit so that I don’t have to worry about accidentally turning on the wrong mosfets , as well for some other reasons to be discussed below. This circuit ties together the input of Q1 to that of Q3, and the input of Q2 to that of Q4. As a result, both Q1 and Q3 or Q2 and Q4 will never be on at the same time, since the N-Mos and P-Mos devices are active for opposite polarity signals (I.e. if ground is applied, the P-Mos will be active while the N-Mos will be off) The addition of the 2 and gates allows for a PWM signal to control speed. It is set up such that the PWM signal will only be applied to the N-Channel (Q3 and Q4). The reason for this is because for similar N and P channel mosfets , the N channel mosfet will usually have a smaller gate capacitance, and will turn on and off quicker than the P channel mosfet . It is more efficient to leave one mosfet active, while toggling the other with a PWM signal. To have the motor always on at full speed, set the PWM input to a steady 1. For the And gates, a high speed chip such as the 74F08 is desirable. If you are not concerned with speed control, you can get rid of the AND gates and tie the gate of Q1 to the gate of Q3 and the gate of Q2 to the gate of Q4 directly. Turning either A or B high will cause the motor to rotate in one direction or the other. If they are both high or both low at the same time, then the motor will actively bake. If you do not need active braking in the circuit, you can connect wire B to wire A via an inverter, so that B will always be the opposite of A. You then only need to toggle A for direction control, and the PWM line for speed.
When changing the speed of the motor, it is good idea to ramp it, as sudden changes can cause a lot of back EMF and noise to be produced. Ramping means to slowly increase the speed, by slowly changing the duty cycle of the PWM signal. Slow is a relative term, and often a ramp time of half a second is more than enough for small motors. This will depend on your motors and robot, as you will need to consider the rotational inertia of the motor, and how much current will be drawn for rapid changes in motor speed.
When changing direction of a motor it is a good idea to turn the motor off for one, two, or ten, or more milliseconds before turning it on again in the other direction. This will allow time for the back EMF to dissipate in the circuit, and will prevent any associated problems.