Don’t get me wrong, serial servo controllers are great, but sometimes you just want a simple way to flex a servo (like, say, if you knew that your Robix servo gripper was out on a truck to be delivered to you later today). Something that doesn’t require sending serial bytes or finding two charged battery packs for an RF transmitter and receiver would be really nice right about now, so I’ve been doing a little searching.
You can spend about $150 on a fancy digital servo tester, like this one from Hitec, which is so expensive because it also serves as the programmer for their digital programmable servos. Looking at ServoCity, For $100 you can get a two-axis servo joystick, or for $40 you can lay your hands on a rotary potentiometer controlled dual servo driver. Convenient, but for that price I can get TWO Pololu micro serial servo controllers (my favorites!), and probably cover shipping (sorry ServoCity, nice try).
There are also these little guys which are ubiquitous on E-Bay:
You can “buy it now” for $4, or get one from an auction starting at $0.99, but you’ll have to pay another $9 for shipping from Hong Kong! It would almost be worth getting one to try out, but it turns out they only produce pulses in the standard 1ms-2ms range. Similar hobby kits abound, but they all seem to have the same limited range. I wanted something that could go far outside the standard servo pulse width, to push my servos to their limits.
An ATTiny25 could easily handle reading a pot and generating the pulses, but for something so basic I decided to try an analog solution instead. With a little searching you can find ~20 variations on how to use a 555 timer to generate servo pulses. They vary in complexity and part count, most use a transistor as an output inverter, and some even use two timers (the first as a one-shot to generate the actual pulses, and a second as a timer to trigger the first, keeping the period precisely constant…whatever!). By far the best one I found was in a document called Hobby Servo Fundamentals by Darren Sawicz (page 7):
Note: If you’re using Firefox, and your browser window isn’t huge enough, check the whole circuit.
It’s probably the simplest one out there, and that tricky diode makes all the difference. It uses only one capacitor, no transistors, and if you don’t already have all the parts lying around you can get them at Radio Shack for under $8.
With the given component values, this circuit has the standard 1ms-2ms pulse range, with a slightly long (but still totally usable) ~40ms low pulse in between. Kindly Mr. Sawicz also provides the equations that govern the high pulse range and low pulse time of his design (remember, 1ohm*1farad=1second):
THIGH = 0.693(R1 + R2)C
TLOW = 0.693(R3)C
Basically, you can pick out a nice pot for R2, and size the capacitor C1 to control the range of the pulse widths you want to produce. R1 then adds the minimum pulse width offset, and R3 controls the off time in between pulses. Darren also notes that you might want to use a trim-pot for R1, so you can tweak the center of your pulse range to perfection (probably a good idea, since variations of individual components can changes the signal characteristics).
For the R2 I used a nice 10Kohm slide potentiometer, but I only connected the wiper and one pole, rather than the self-parallel arrangement from the schematic. I figure this way if it gets grimy and looses contact, the circuit will just stop outputting pulses, rather than producing extreme pulses which will unexpectedly run the servo into its mechanical stop.
For C1 I ended up using three 0.1uf capacitors in parallel (what I had around), for what should have been a 2ms variable pulse width range. Looking at it on the scope though I had more like 3ms of range, so I eliminated R1 all together (again, good to use a trim-pot here, you can always adjust it down to nothing). That left me with a period adjustable from 0.1ms up to about 3ms, which is even more than I originally wanted.
I initially chose a 100Kohm resistor for R3, which should have given me about 20ms of low time, but ended up giving me more like 30ms. Servos worked with it just fine, so I wouldn’t have known the difference without a scope. I ended up using an 82Kohm resistor instead, which gave me the ~20ms low period I wanted. I’m not sure why the actual timing didn’t agree with the formulate, but I suspect the three little capacitors I dug up aren’t very tightly toleranced.
Once it worked on a breadboard I threw it all together on a 20-pin DIP prototyping board. In hindsight maybe I should have thought a little more about the layout before I started soldering components on, but I did get it done just in time for the UPS truck to pull up:
The rest of Hobby Servo Fundamentals was a nice read, and I think it would make a good primer for someone not familiar with the electromechanical workings of hobby servos or the PWM protocol that controls them (although I think the part on page 5 about the FCC mandated 40ms PPM period for radio transmitters is out of date, I know my Hitec Optic6 has a 22.5ms period). It also covers continuous rotation servo modification (page 9), although I prefer using a trim-pot or the original potentiometer to fine-tune the deadband location, rather than relying on the tolerance of a pair of fixed resistors.
Darren also offers a true electrical engineer’s solution to reversing the direction a servo rotates. His signal reverser circuit (page 8) uses a one-shot timer triggered by a servo control signal pulse to produce a parallel 3ms pulse, and an XOR gate to subtract the original pulse from it. Very slick, but I can offer a competing mechanical engineer’s solution: open up the servo and reverse the potentiometer poles and the motor leads. It takes all kinds I guess.