The Lion is scratching in smooth motions now, thanks to a servo from Expert Electronics (supplied by the local HobbyTown) and a Rabbit 4000. A few items were learned in the process of trying to get this to work with a Rabbit 4000 processor.
First, an overview of the rabbit. The Rabbit 4100 I own has four PWM channels. Frequency is set on the whole PWM subsystem (not on a per-channel basis) through the pwm_init(int hertz) call. Out of the box, the lowest frequency the rabbit will go on the PWM system is 112Hz. There is also a pwm_set(int channel, int duty, int options) function that lets you set the duty cycle and options for a particular channel.
Now a brief servo overview. From seeing all the attention given to servos I had yet to find what made them so special. The magic of the servo, it turns out, is two fold: 1) they have a great amount of power output for their size (thanks to gearing), and 2) they can be positioned precisely almost without effort from the user. The positioning magic is handeled by some circuitry within the servo. Typically servos make use of a potentiometer and hence have a fixed range – typically 180 degrees. The user selects the servo position by sending a pulse, where the width of the pulse varies from 1ms to 2ms. Most sites I found said to allow for at least 20ms between pulses.
Ok, now to mix the two: servos and pwm controllers. Given that servos want a pulse from 1 to 2 ms, we can calculate the maximum frequency as 1/period = 1/.002 = 500Hz. Assuming we use this frequency, we now need to vary our duty cycle between 100 and 50%. Then, the trick comes in: how to wait after a pulse. Turns out the rabbit has a cycle suppression option as part of the pwm_set function. With this, one can supress 7/8, 3/4, or 1/2 cycles. Since we want about 20 ms, it makes since to use the highest setting – 7/8 – yielding 14 ms of dead time between cycles.
Turns out this is about all you need to know. Just make sure, that if you are using two separate supplies (one for rabbit, one for servo) that their grounds are tied together. Also, we chose initially to operate at 112Hz… then we also decided to wait 7/8 cycles. The result is that our line shook like a crack addict – really jerky movement. Why? A helpful site told us that if we let the servo wait more than, say, 45 or 50 ms, the control circuit in it would go to sleep. In other words, the off time between cycles should be from 10 ms to about 30 ms – within those bounds. Because of our frequency, we were waiting 50ms. When we switched the suppression to one in two, everything worked smooth as silk! Going to a higher frequency should allow for finer grained control, since the duty cycle field is an int going from 0 to 1024 (100%).