Let's Make Robots!

H-Bridge Motor Control for DIY Servo

I'm building a DIY servo for steering Yard Gnome. I'm testing some things out while I wait for the 24VDC 30 rpm 41 in-lbs gearmotor I ordered to arrive.

I'd like some advice on my controller.


I'm designing a fairly straightforward H-bridge like the one Weiss posted here. I'll be using two TIP127 PNP transistors and two TIP120 NPN transistors for the main H-bridge. For interacing to the drive signals, I'll using a pair of PN2222A NPN transistors, because I have a bunch of them. My test circuit right now is using 1N4004 diodes like in Weiss' design, but I will substitute some 3A 1N5402 transistors for the final implementation.

(click for larger image)

I have successfully tested the H-bridge running at 16VDC (the limit of my bench power supply) driven by 6V from 4xAA batteries.

I'm hoping this H-Bridge will have plenty of current handling capacity at the nominal 24VDC from the batteries to drive the motor mentioned above, I don't have the motor stall current specs, but I'll take some measurements when it arrives.

Servo Controller

My biggest question right now is how to drive the H-bridge above from the servo controller. I was planning to either buy a controller that is designed to work with a standard DC motor and potentiometer, or rip a controller out of an existing servo. The key point is that I need the high current and 24V capabilities of the H-bridge to interface between the motor and the servo controller. My question is, how do hook them up?

If I use a servo controller out of an existing servo, can I simply disconnect the servo's own motor, and use those leads to drive the H-bridge above? 

(click for larger image)

Update 2010-06-05

I decided to go ahead and try driving the H-bridge from a servo. It worked! I desoldered the servo motor and hooked the leads to the two input signals for the H-bridge. Now if I either manually move the potentiometer on the servo, or use my R/C controller to tell the servo to move, it drives the motor through my H-bridge.

However, when the motor is not moving, it continuously jitters. I'v'e tried slightly adjusting the servo potentiometer and using the trim controls on the R/C transmitter, but nothing helps. Maybe some capacitors on the driven motor will smooth things out.

I posted a video so you can see what I'm talking about.

YG_H-Bridge1.jpg24.55 KB
YG_Servo_Controller1.jpg14.87 KB

Comment viewing options

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

the same as without them.

My optocouplers came in yesterday. I tried replacing the PN2222A transistors that drive the H-bridge in the schematic above with optocouplers. The good news, it works. The bad news, the motor still has a major case of the delirium tremens.

I may keep the optocouplers in the design, since I still haven't tried the circuit at the nominal 24VDC from the batteries. However, jittery motor remains a problem. Grrrrr.

After some further experimentation with the servo and h-bridge, I think I'm going to try a slightly different approach.

I tried running the original servo motor, but with my H-bridge circuit in between. My thought was that the servo controller was tuned for this motor. Unfortunately, I saw similar behavior to the other motor: too much jitter. 

Since my new 24V motor had arrived. I replaced the temporary gear motor I was using with the new 24V one. I had similar results. Actually, I think the jittering was even worse.

Now the coils for my new motor measure at 70 ohms. So I figure the stall current at various voltages:

  • @ 6V: 6 / 70 = 85.7 mA
  • @ 24V: 24 / 70 = 342.8 mA
  • @ 28V (maximum battery voltage): 28 / 70 =400 mA 

By comparison, the original motor from the servo has a coil measuring 17 ohms:

  • @ 6V: 6 / 17 = 352.9 mA

Based on this, I decided it would be safe to try to drive the new motor directly from the servo controller, without my H-bridge in between.  The motor ran fine, but far too slowly. Since the motor is rated at 30 rpm at 24V, it is very slow at 6V. The good news is I learned the servo controller could drive this motor without jitter.

So I think I will abandon the idea of an H-bridge in between the servo controller and the motor. I had originally thought about placing some optocouplers in between the controller output and the H-bridge to eliminate any interference. Since I have already ordered the optocouplers, I think I will try using them to interface to the new motor, only with no H-bridge.

Servo controller -> Optocouplers -> High voltage transistor (possibly) -> Motor

My thinking is that with an open collector optocoupler, I can simply translate the output of the internal servo controller's H-bridge to a higher voltage to drive the motor. As long as I can source 400 mA (the motor's stall current at 28V), I think this may work. Hopefully the simplicity of this design will allow the servo controller to drive the new motor with enough speed and torque, and without introducing the jitter.

It is possible the jitter will return when I drive the motor at higher voltages. Only time will tell.

This could be my problem. The servo controller is not tuned for this motor, so the position is always slighly wrong. Consequently the motor twitches because the controller is trying to correct the position slightly.

There are three different factors to set when tuning the servo motor: its called a PID algorithm, or something like that. This is an acronym for Proportional, Integral, and Derivative gain. You might try googling PID loop and check out some of the articles that come up.

By carefully adjusting each of these three parameters, you can observe the effect that this has on the controller's control of the servo motor.

The "I" and "D" factors control the resetting and damping of the controller servo loop. It helps to "calm down" the harshest responses that are technically possible, as the controller monitors the encoder position and tries to make it obey the "prime directive", which is always to have a difference of zero between the commanded and actual encoder position.

Imagine an example: the encoder is only one count off of commanded position: should the controller command a huge current to move the motor that last count, or should it be a small current? It depends on the load. That's why the tuning has to be done in real life, on the real load, so that it can be judged when the controller response is adequately proportioned. This keeps the motor from getting into a "buzzy state" where it continuously overshoots both directions from zero, because the applied minimum correction is too large.

From CNCZone website forum question How do Servo Motors Work?

I'm posting some of my reasearch here for my own reference. Hopefully it will be helpful to others as well.

The potentiometer is the feedback device and often the first thing to fail in servos. If it gets dirty, or the contacts get oxidized, the servo will fail to work properly, sometimes by "jittering or hunting" since the feedback is inaccurate, or turning completely to one side and drawing lots of current since the servo doesn't know where its output shaft is pointing. More expensive servos have "sealed" potentiometers, cheaper ones do not. 

From PC in Control tutorial on Servo Control


According to your circuit diagram the TIP127s are connected with the Collector and Emitter reversed, might want to double check that one =)

Good catch, TeleFox. I have corrected the diagram. Thankfully my circuit building is more accurate than my drawing. ; j

 Any thoughts on the cause of my problem?

Hmm, the only things I can think of are that your power supply isn't enough to handle the current drawn by your motor, or that there's some shoot-through happening on one or both sides of the driver bridge.
Maybe you should disconnect the servo controller and test the driver with one input turned on to check that current is only flowing through the motor as it should.

Hmm, indeed. I don't think the h-bridge itself is the issue. I've already tested it in isolation and it seems to work fine.

In theory, I shouldn't be getting any shoot through. Unless the servo board is trying to switch the motor between forward and backward so quickly that I'm briefly seeing both legs of the H turn on at the same time. That is something I had not considered. Is there any reason a servo controller board would apply +V to both motor leads at the same time?

I just had another thought. Maybe the servo electronics are so nicely matched to the motor they are designed to work with that it doesn't work so well with another? I could try connecting the output of the H-bridge to the original servo motor. Like so:

Servo Controller (including internal h-bridge) -> External H-bridge -> Servo motor

Thanks for giving me some fuel for thought.

Can't say I know too much about servo controller standards, but there's a possibility both outputs would be active at the same time.
Do you have a logic analyser, oscilloscope, or anything similar you could use to check out the signals?

Unfortunately, no. I really would love to have an o-scope one day.

I'll do some research on how servo controllers work. Maybe I'll find some answers.