Username:    Password: Remember me
Build a 5A H-bridge motor driver
By Ibrahim Kamal
Last update: 6/6/08


This H-bridge is easy to build, without any critical components. It is based on the famous and cheap TIP122 and TIP127 power transistors. It have been used on many of our robots and proved to be very versatile and robust.

Another major advantage is that it only needs 4 wires for 12V power supply and direction control. Nevertheless, it allows bidirectional control, breaking and freewheeling.

1.The hardware
The schematic can seem a little complicated at the first sight, but, practically, it only consists of 2 logic ICs and a bunch of transistors.

figure 1.a

Q1, Q2, Q3 and Q4 are 2N2222 BJT. They can be replaced with any generic switching transistor.

Resistors R2, R4, R5 and R10 have to be 1 WATT rated, to support high currents, especially if a 24V power supply is used.

The wire connection W1 to W4 are the wires between this H-bridge module and the controller board that provides the 12/24V power supply and the logic signals for direction control.

The wire connection W3 can be connected to a power source from 10V to 24V, without circuit modifications.

The wire connection W1 and W2 are for connecting the H-bridge to a microcontroller or another logic device allowing the control of the motor. A truth table is given below showing the effect of every combination of the logic states of W1 and W2:


Inputs
Result on the connected motor
W1
W2
0
0
Motor is freewheeling (disconnected, High impendence)
0
1
Turn the motor clockwise
1
0
Turn the motor anti-clockwise
1
1
breaking the motor
*(X mean Don't care), 1 = Logic high Voltage (5V), 0 = Logic low voltage (0V).

Diodes D2 to D4 are simple rectifier diodes, with forward current ratings of at least 4A.

LED D1 is only used to signal the presence of power in the circuit.

The whole is assembled in a 5cm X 5cm PCB like in the picture below (figure 1.b). The length of the cable is not critical, it can be up to 1 meter, assuming you're PWM frequency is below 50 KHz. Heatsinks can be added to protect the TIP transistors from overheating. Be careful, the metallic back of the TIP is internally connected the collector, so be careful not to cause short circuits.

Actually, as you can see in figure 1.b, each pair of TIP122 and TIP127 share the same heatsink, without any risk of short circuits, since their collectors are already connected together in the circuit (If the schematic in figure 1.a, Q5 and Q6 have their collector connected together, as well as Q7 and Q8).

figure 1.b


2. Associated motor control algorithm
Here are some example C source codes showing how to control a motor using this H-bridge. The source codes are written for 8051 micro controller under the KEIL IDE, but can be easily modified for any other kind of microcontrollers or compiler.

This first example shows a function that control the direction/state of the motor, without speed variation.
#define w1 P1_0
#define w2 P1_1
#define motor_free 0
#define motor_break 1
#define motor_clockwise 2
#define motor_anti_clockwise 3

drive_motor(state){
   if (state == motor_free){
      w1 = 0;
      w2 = 0;
   }else if(state == motor_break){
      w1 = 1;
      w2 = 1;
   }else if(state == motor_clockwise){
      w1 = 1;
      w2 = 0;
   }else if(state == motor_anti_clockwise){
      w1 = 0;
      w2 = 1;
   }
}


The above function can then be called anytime in your program to change the state of the motor as in the example below:

drive_motor(motor_clockwise); //turn clockwise


The same function can be used in a more complicated code that controls the speed (or breaking torque) of a motor via PWM signals (for more information about PWM signals and speed control, check this article). The following example shows how to use this h-bridge with speed variations via PWM:

//global variables
unsigned char pwm_counter;
//used to count from 0 to max_pwm
unsigned char max_pwm = 100;
//this controls the period of one complete cycle
unsigned char pwm = 50;
//this controls the duty cycle.

void main(){
    while(1){
        pwm_counter++
        if (pwm_counter > max_pwm){ pwm_counter = 0; }
        if (pwm_counter < pwm){
//ON cycle
              drive_motor(motor_clockwise);
//turn clockwise
        }else{
//OFF cycle
              drive_motor(motor_free);
//motor freewheeling
        }
    }
}


The above example drives a motor with a 50% duty cycle PWM signal. It can be integrated in any program without causing any delays or disturbance the other functions.

You can download the PCB and the schematic for that h-bridge though the link below:

Download the zip file for the project.
Containing the full schematic and the PCB designs.
[note: i use ExpressPCB(FREEWARE) to design the schematics and the PCB]



I hope this article was useful. Any comments and further questions are welcome in the forum below.

Discussion (Last 15 posts preview...)
Preview of the last 15 messages discussing this page. Messages are sorted from the newest to the oldest.
Posted by:
tominator
on: 12 Nov 2008
Re: 5A H-Bridge motor controllers
['Quote ]
Hi,

Yesterday I did try the bridge with 5A motors and was running perfectly for several minutes. Then disaster stroke and took my 7805. All the TIPs were cool (no overheating took place) but 7805 almost melted. For what reason I could not tell. Also you could improve the stability of the circuit if you put condensator between output and GND of the 7805. My bridge and motor produced some strange noises occasionally during the run (probably due to the voltage drop across 74 chips and consequently occassional frequency change).

Best regards,
Tom.
Posted by:
User avatar
ikalogic

on: 11 Nov 2008
Re: 5A H-Bridge motor controllers
['Quote ]
Hello,

without heat sinks, any minimal current will get the TIPs hot.

The voltage drop may be probably due to non fully saturated TIPs, but a voltage drop as small as 1 or 2 volts is acceptable, it is due to the VCE voltage of the TIP transistors whish is allready quite high.. look at the datasheet, it's about 1.5 volts... So i would say it's OK.
Posted by:
tominator
on: 11 Nov 2008
Re: 5A H-Bridge motor controllers
['Quote ]
Hi Ibrahim,

I built your 5A H-bridge with little modifications. I used TIP132/TIP137 to drive motor (higher current ratings - hfe and other relevant characteristics are same or almost the same). My motors are 5A each (I use one H-bridge per motor). Supply is 12V and PWM frequency is 40kHz. To test the circuit I used small CPU fan rated at 12V/0.1A aprox. When I use this H-bridge voltage accross motor leads is 1.2-1.5V less than supply voltage (10.5-10.8V, duty cycle is 100%). Fan speed is controlled and it works, but the TIPs which are designed to handle much larger currents get warm (almost hot) after several minutes when I am using low PWM duty cycles (or bring motor to stall). I did not use any heatsink (I believe TIP should disipate power loses easy for this small currents - 0.1A), for final device, of course, I'll use them.

Before I apply this circuit to real motors I wanted to check with you why is this voltage drop I get large like this? I am afraid that 5A current will disipate so much heat that it will destroy circuit in notime. Is ti possible that TIPs are not fully saturated? Is PWM frequency to big? If I use higher rated transistors will heat disipation be lesser? Or it is needed to be cooled whichever transistor I use?

Sorry for such a large post.
Thanks a lot,
Tom.

P.S. I'll send you pictures of my robot when I successfully finish it.
Posted by:
User avatar
ikalogic

on: 04 Oct 2008
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting Roboter: Could someone please tell me which pwm frequency i should use for this circuit?

I can generate PWM Signals between 40Hz and 800Hz.

Thanks in advance


anything between 10KHz and 20KHz would be just perfect!
Posted by:
roboter
on: 04 Oct 2008
5A H-Bridge motor controllers
['Quote ]
Could someone please tell me which pwm frequency i should use for this circuit?

I can generate PWM Signals between 40Hz and 800Hz.

Thanks in advance
Posted by:
sychang
on: 20 Sep 2008
5A H-Bridge motor controllers
['Quote ]
hello,

Just wan to ask can this 5A H-Bridge motor controllers apply in a RC car ?
Also the programing is using which software ?
Posted by:
User avatar
ikalogic

on: 04 Sep 2008
Re: I want to have my DIY CNC controller
['Quote ]

Quoting williamkmcn: I want to build a CNC mill, as I found in the internet, most of them were not "DIY kit" but commercial fully installed set only. Could you give me a good suggestion in motor controlling?


Yes, i can, but what type of motor are you using? What is the power rating? What voltage? What current rating? :)
Posted by:
topdreams
on: 04 Sep 2008
5A H-Bridge motor controllers
['Quote ]
Very good,I think I can make one for my small motor!
Thanks for sharing!
Posted by:
williamkmcn
on: 10 Aug 2008
I want to have my DIY CNC controller
['Quote ]
I want to build a CNC mill, as I found in the internet, most of them were not "DIY kit" but commercial fully installed set only. Could you give me a good suggestion in motor controlling?
Posted by:
kemo0o
on: 12 Jul 2008
Re: 5A H-Bridge motor controllers
['Quote ]
of course we did
i will picture it and post it :wink:
Posted by:
User avatar
ikalogic

on: 12 Jul 2008
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting kemo0o:
Quoting ikalogic:
kemo did you make any of those H-B on your own? can you share some pics?


Do You Mean That i make own design For H-Bridge
Or i make yours ?? :roll:


I mean did you build this H-Bridge? for your own robot? if you did, then i would like to see some pics.
Posted by:
kemo0o
on: 12 Jul 2008
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting ikalogic:
kemo did you make any of those H-B on your own? can you share some pics?


Do You Mean That i make own design For H-Bridge
Or i make yours ?? :roll:
Posted by:
User avatar
ikalogic

on: 11 Jul 2008
Re: 5A H-Bridge motor controllers
['Quote ]

Quoting kemo0o: it isn' the 5th TIP

It is Regulator ( LM 7805 ) :D

About The components , It is shown in the schematic :shock:
just count them :roll:


kemo did you make any of those H-B on your own? can you share some pics?
Posted by:
kemo0o
on: 11 Jul 2008
Re: 5A H-Bridge motor controllers
['Quote ]
it isn' the 5th TIP

It is Regulator ( LM 7805 ) :D

About The components , It is shown in the schematic :shock:
just count them :roll:
Posted by:
irongoat
on: 11 Jul 2008
5A H-Bridge motor controllers
['Quote ]
Another question regarding this circuit :
What is U2? It looks to be a 5th TIP on
the picture, but the schematic does not
include a 5th tip.

PS. Can you post a parts list? It would
greatly simplify construction.

Thanks much,

Charles
You have to be a member to post replies.
Username: Remember me
Register now! it only takes an instant.
Forgot your password?


Unless mentioned, all content is written and designed by Ibrahim Kamal, copying is prohibited and unethical
ikalogic.com: Electronics and Robotics related projects.
All content on this site is provided as is and without any guarantee of any kind. We cannot be held responsible for any errors, omissions, or damages arising out of use of information available on this web site.
Creative Commons License
IMPORTANT COPYRIGHT NOTE: Electronics and Robotics Articles by Ibrahim KAMAL are licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.