Let's Make Robots!

Making a FET "H" bridge (revised)

Drives motors
AttachmentSize
Ammeters_and_shunts.pdf137.75 KB
heatsink.pdf135.15 KB
24V_H_bridge_Schematic.jpg795.28 KB

One thing most robots need is the ability to control motors. This circuit will work from 7.2V to 15V with PWM frequencies up to 25KHz and drive motors with a stall current of 20A. Features include not only speed and direction but it also has electronic braking, fuse protection and current sensing. Click on the schematic for a larger image. I have now attached some files with information on current shunts and heatsink calculations.

This circuit was my own exercise to teach myself about "H" bridges. It cannot work at high PWM frequencies, it works perfectly with Arduino's default PWM frequencies. In most cases I suggest you buy a ready made "H" bridge.

As this schematic has been updated you may need to reset your browser cache to see the new schematic. For Firefox users this is done by pressing [Ctrl] + [F5]. This circuit is now smoke proof.

I finally had time to build and test this circuit thoroughly using a DSO (Digital Sampling Oscilloscope) to check that it all worked properly. I have replaced the LM324 with an LM339. The outputs of the LM339 change a lot faster than the LM324 making it better suited for higher frequencies but they are open collector outputs so they need a pullup resistor to work properly.

The current sensing part of the circuit was discussed in detail in a previous walkthrough where it was suggested that a fuse could be used as the "Shunt resistor". I have used that in this circuit and included a LED to indicate if the fuse has blown. Although not as precise as a proper Shunt resistor the fuse is a lot cheaper and performs a vital service. I have added a 200K pot for adjusting the gain allowing this circuit to work with any shunt resistor.

The fuse should be a "slow blow" fuse with a rating less than your stall current. If your software is working well it will detect the stall current and shutdown the motors before the fuse blows. If something goes wrong then the fuse will do it's job.

Note that suitably heavy wire should be used between the batteries, the motor controller and the motor to get maximum power to your motors and to ensure the fuse does it's job. With the 20A circuit shown I would use at least 1.5mm² stranded copper wire.

I have shown IRF540 Nch and IRF9540 Pch FETs in this circuit as used by Jip in his robot "Tiny Tim" because they are relatively cheap and will handle stall currents of 20A. Other FETs could be used in their place depending on the requirements of your robot.

The maximum Vgs of the FETs shown is +/- 20V. I recommend not using batteries higher than 14.4V (12 x NiMh) as the peak voltage of the batteries during charging and just after charging can be a fair bit higher.

No "Flyback" diodes have been included in this circuit because in most cases the FET's internal "Body Diode" is usually sufficient. Additional diodes may be added if required.

The comparators perform 2 functions, they translate the logic level outputs of your microcontroller to the higher voltages needed to drive the FETs and they prevent your FETs from aciddently turning on in such a way as to short out your battery.

The voltage translation is done by comparing your logic level inputs with voltages derived from your 5V supply. The input is compared to 1V and 4V levels generated with a voltage divider. If your microcontrollers output is higher than 4V then the appropriate Nch FET will turn on. Lower than 1V will turn on the Pch FET. Voltages in between 1V and 4V will turn off both FETs preventing any possible Short circuit.

Because the outputs of your microcontroller can change state so quickly I have added 10nF capacitors and 100Ω resistors in series with inputs A and B. As the capacitors must charge and discharge via the 100Ω resistors this slows down the inputs rate of change enough to guarantee that both Nch and Pch FETs have time to turn off during transistions.

Below is a screen shot from the DSO. This shows the LM339 outputs to the Nch and Pch FETs when input A is PWM at 50% duty cycle @ 16KHz with a battery voltage of 15V. Input B is tied high. As shown on the truth table this is alternating between 50% brake and 50% reverse. The yellow signal goes to the Nch FET while the Cyan signal goes to the Pch FET.

When both signals are high, the Nch FET is on and the Pch FET is off. When both signals are low then the Nch is off and the Pch is on. During switching, you can see the Nch turns off before the Pch turns on and that the Pch turns off before the Nch turns on.

Each input has a diode and transistor on it. This strange setup is known as MML (Mickey Mouse Logic) which is basically logic gates cobbled together from resistors, diodes and transistors.This MML generates open circuit outputs when both inputs are low but allows all other combinations to pass through allowing both "brake" and "no power" states as shown in the truth table.

When both inputs are low then the diodes block the inputs and the + inputs of the opamps are held at 2.5V via the 4K7 resistors. In this state the transistors on the inputs are both off.

When both inputs are high then the + inputs of the opamps are driven high via the diodes turning the PCh FETs off and the Nch FETs on causing the motor to brake. Both input transistors are off since their base and emitter pins are both high.

When one input is high and one is low then the high input passes through it's diode and the low input passes through it's transistor which is now on.

Speed is controlled by holding one input low and PWM the other input. Electronic braking of the motor can be controlled by PWM both inputs together so that they are both high or both low at the same time.

Although 5V logic is assumed in this circuit it will work with 3.3V logic just as easily. Just replace the 4.7V zener in the current sensing circuit with a 3.3V zener to protect the LM358 input.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The picture is too small and hard to read. Can you link it to a black and white, high resolution image?Combining power traces and Gnd traces should not matter unless you made a major error in which case magic blue smoke would be your result.

Hi oddbot,

since I soldered your h bridge (without the current sensing) onto two boards in order to control 2x2 motors, I just tried to compress the circuit onto one pcb in eagle style (freeware and thus using 80x100mm). I found a cheap online store to prepare the board. Now I´ve got a problem that I on both h bridges the pins for the N-Channel mosfets wont respond. They keep down at 0.07v. The pins for the P-Channel mosfets work perfectly fine on both h bridges.

Now my question is, whether the mistake was that I combined the traces for power and gnd.

I´m wondering whether you can help me, by having a closer look at the schematic. I´m already looking for the problem for 2 days but cannot figure it out.

 

I used all the values you did except that I replaced the transistors with bc547 due to through hole assembly.

 

just asked a stupid question before thinking.

I may just have to put this to use on one of my bots! Thanks for taking the time to put this together!

Your welcome but unless your trying to learn about electronics it is much easier just to buy a motor driver PCB.

Certainly that'd be easier but as irony would have it, I've been thinking about replacing your T'Rex driver board with something else. I have gotten into pcb design and already replaced a couple arduinos with a custom pcb and just finished rev 2.0 of it. I've wanted to make an "all in one" controller and your T'Tex board is waaaay overpowered for what I need it for. All I need is forward/reverse/braking of one DC motor at 12v with 10 amps stall or so and two servos. There are dozens of cheap boards that could do this but I'd really like to have it on my board and although I can design a knock off atmega328 board I dont have knowledge of op amps or many other areas needed to safely design a circuit like this. So once I get around to rev 3.0 I think I'll implement this. It'll be somewhat costly, I tallied up the components yesterday I have and what I'll need and my rough math says it'll cost me about $10 in extra components per board and I'm making an estimate of between 4 and 8 square inches of board space which will cost me around $5 more per board. Unfortunately it's rather high since I buy in such small quantities but the only thing keeping me from adding this to my boards was my lack of knowledge of creating a high voltage h-bridge with the safety of a fuse and such. Should be an intresting adventure once I get around to it!

How can the schematics be modified in order to run 6V motors?

Thanks

Sorin

The circuit will work at 6V although it will be more efficient if you can get logic level FETs. These FET's usually have an "L" suffix in the part number and can work with lower gate voltages. You may also want to reduce the gate pullup resistors to 3K3 instead of 4K7.

Thank you for the reply. I can run the driver itself at 7.2V but the motors are rated all as 6V ( http://www.pololu.com/product/1586 ). Is their any voltage drop on motor output (the blue icon in the schematics)? Maybe I can run it with your original schematics. (Sorry for so many questions I'm a newbie in electronics)

 

Happy Holidays!

The whole reason for using FETs is because we don't want voltage drop. FET's have very low on resistance usually measured in milliohms.

If your motors are rated for 6V then that is a continuous rating. They will work fine at 7.2V. Your robot will not be moving at full speed 100% of the time. Please note that this circuit is not designed for high PWM frequencies. It works best at 1kHz or lower the same as Arduino uses by default. Hight frequencies (above 20kHz) can cause it to short.

You should realise that these days there are many motor control IC's that will work at higher PWM frequencies than this circuit. If you get a dual "H" bridge pre-driver then all it needs is the power FETs and a few other external components to make a high power dual "H" bridge.