Running RC servos

From Mech
Jump to: navigation, search

Don't confuse RC servos with servomotors. RC servos were developed for remote controlled model airplanes. They contain a whole position-control system which can be used for instance to set a rudder angle. An RC servo receives a coded signal which informs it of the desired output angle, and its internal electronics strives to bring the output shaft of the RC servo to that angle.

It's useful to be able to generate the coded signals to control a bunch of RC servos. RCservoSoft.c does that using interrupts in a tricky way. It handles up to five RC servos.

The RC signaling code works like this. There is an underlying 50Hz repetition rate. During each 20mS period, there is a logic high period of between 300uS and 2500uS, corresponding to ends of the position control range, typically 135 degrees.

For RCservoSoft.c the desired logic high time for the servos is expressed in multiples of 0.8uS, thus values of 375 to 3125, stored in an array RCservo[0 to 4].

RCservoSoft.c works by using the 1KHz ISR based on Timer 2 that we use for other purposes as well. Let's consider just one RC servo, number 0. Every 20th interrupt, the digital output to the RC servo (pin D0 in our example) is set low. 16mS later, Timer 3 is initiated with its own interrupt, and Timer 3's ISR when it occurs turns pin D0 high. The delay from the 16mS mark to the moment of the Timer 3 interrupt is chosen so that the remaining logic high time is the desired value. This is rather tricky C code; good luck.

The control signal for an RC Servo is a digital pulse train that looks something like this:

555 control.jpg

Here, the width of the “high” pulse, t, determines the angle of the rotor. The width, measured in time, will be in the range of

0.3 ms \leq t \leq 2.5 ms

And the frequency of the pulses, given by

f = \frac{1}{T},

is around 40-50Hz (T ≈ 20ms).

Personal tools