Servo pulse to PWM converter

Radio-controlled cars, boats, airplanes, etc use servos to control steering and other functions. The interface is well defined and the servos are quite affordable, so they are also used for robotics and other clever purposes.
The servo positions itself based on the width of positive pulses fed to it. The rate at which pulses are sent to the servo is relatively unimportant(40 per second seems pretty typical). A pulse width of 1.5 milliseconds positions the servo at its center, with 1 millisecond and 2 milliseconds being the accepted limits to either side.

The Parallax Basic Stamp has a command called "pulsout" that is handy to control servos. This circuit can be driven from a radio receiver or a Basic Stamp.

Steering and wiggling are not the only things a car, boat, or robot need to do. Locomotion is important, too, so controlling something like a DC motor would be nice. A circuit called an "H-bridge" can supply the switching and control the current needed to operate a motor forward and backwards, but something more is required to interface between servo pulses and an H-bridge. Variable speed would be another good feature to have. That’s what this circuit does, interface between a radio receiver and an H-bridge.

The circuit presented on this page attemps to be an interface to convert pulses such as provided by a Basic Stamp or R/C receiver to a dual PWM(Pulse Width Modulation) signal required by an H-bridge. The simplest circuit would use a small microcontroller like a PIC. This circuit takes a more traditional approach. Many experimenters will have all the parts already. Total parts cost should be equal to a simple espresso drink, although I have stopped drinking coffee I still remember how much it costs :-)

I've done a printed circuit board layout for those of you able to etch a single-sided board. Point-to-point wiring on perfboard might be a little tiresome unless you are very good.

Please note that nothing here is for sale. I do not sell circuit boards or kits.

Please also note that this information is presented for private non-commercial use only.

Furthermore, there is no liability expressed or implied. If your fighting robot decides to stop fighting, or goes AWOL and kills something, that’s your problem. Get a better radio.

sv2pwmsc.gif Schematic in GIF format
sv2pwmsc.pdf Schematic in PDF format
sv2pwmpc.gif PC board foil layout in GIF format. Not to scale.
sv2pwmpc.pdf PC board foil layout in PDF format. Print your transfer with this.
sv2pwmst.gif Parts stuffing diagram in GIF format. Not to scale.
sv2pwmst.pdf Parts stuffing diagram in PDF format.
sv2pwmpl.txt Parts list in plain text format.

Typical input/output characteristics

About the circuit:
Attach J1 to a source of 5 volts and a pulse signal with 1.5 millisecond null.

The input pulses are buffered by U1A, and capacitors C2,3 charge at a rate set by trimmer resistor R2. At the end of each pulse the sample-and-hold capacitors C8,9 are updated with the voltage on C2,3.

The sampled voltage is always compared by opamps U2A,C to a scaled up or scaled down voltage of triangle-wave oscillator U2D, producing opposite PWM signals.

The scaling of resistors R9,10,11,12 makes only only one PWM channel active at any time.

The PWM signals pass through analog switches U3B,C and are buffered by U1D,E. If there is a lack of incoming pulses, U1C as controlled by C7 and R4 will shut off the output. This has the effect of shutting off your motor if your Basic Stamp goes crazy or your radio signal disappears.

Attach the PWM outputs at J2 to your H-bridge.

Adjustments, comments and modifications:
The zero adjust potentiometer R2 should be adjusted when a null signal(1.5 milliseconds) is being fed in. Either monitor the output with an oscilloscope or attach an H-bridge and motor and adjust for no activity.

The circuit is neither fantastic nor crap. It is mediocre, and adequate for most experimenter uses. The use of doubled capacitors in three stages allows it to operate even with poor quality power, which is good. The high input bias current of the low quality LM324 causes significant drift to occur if pulses are not fed to the circuit at least 10 per second. At that low repetition rate, varying the rate will change the PWM duty cycle(resulting in a slight motor "throbbing"). This could happen if you produce the pulses from software whose total loop time varies.

Build the circuit as shown, and modify it if you see a need.

PWM frequency is approximately 3khz, which is very efficient through most H-bridges but is a little noisy. Change C5 and C6 for a big change in frequency, and change R3 to make minor changes in frequency.

To change the sensitivity to pulse width, change the value of R5. Currently 1 millisecond will cause full-on of one output, and 2 milliseconds will cause full-on of the other output.

R10 and R11 set the size of the deadband, where both outputs are off. If you want to adjust the deadband, increase the value(to 33k perhaps) of R10 and R11, and put a trimmer potentiometer(say 100k) from U2 pins 3 and 9.

If you are the type who has lots of power and likes to heat up motors in order to attain absolute fine control, you can modify it for overlapping outputs. In that case, you might want to shorten the timeout so you can shut off the outputs and save power, simply by ceasing to send pulses to the circuit. Reducing the value of R4 will reduce the timeout. The default value of 4.7 megohm gives a 2.5 second timeout. Changing R4 to 470k sets the timeout to 0.25 second.

Fighting Robot Modifications:
Two of these circuits can be used effectively in a “fighting robot” with two motors and two H-bridges. The following was used in a couple of different robots, each using two 18-volt cordless electric drills for motivation. Actually most setups using radio control receivers benefit from this modification
R5 - was 220K, now 470K.
R10 - was 15K, now 22K.
C5 and C6 - were .01uF, now .1uF.

Using with a Basic Stamp:
Operation from a Basic Stamp is very simple. Simply send a "pulsout" whenever you want the change the motor speed/direction, and resend the pulsout every so often. Here is a sample piece of Basic Stamp 2 code that will ramp the motor speed up and down and reverse direction. The example expects the circuit to be connected to port pin P15.

i var word
i = 750
pulsout 15,i
pause 25
i = i + 1
if i = 1000 then downloop
goto uploop
pulsout 15,i
pause 25
i = i - 1
if i = 500 then uploop
goto downloop

Pulsout values from 500 to 1000 on the Basic Stamp 2 correspond with 100 to 200 on the Basic Stamp 1.

Frequently asked questions:


I don’t want to build it because you say it’s mediocre.


There’s nothing wrong with it except the LM324 is just a lousy opamp, but it doesn’t cost much.




The motors are noisy, can I make the circuit run 20KHz to get rid of the noise?


No, the LM324 barely runs at 3KHz. Try going down in frequency, see the fighting robot section.




Can I use a two channel radio with one channel motion, the other steering?


I haven’t done it, but it could be done by cross-connecting two boards near R9,10,11,12.




I built the circuit and it works great except the motor doesn’t go fast enough.


If you are using a radio receiver you should do the “fighting robot” modifications.




My receiver quits when I connect it to this circuit.


Most receivers have + as the middle pin, you have to make the cable to adapt. Sorry.




[Home] [Services] [TechRef] [Weekend] [Legal] [Contact]



Copyright © 1995-2002 Bob Blick. All Rights Reserved.
Designated trademarks and brands are the property of their respective owners.