Servo Control tutorial
We have reached the most important and interesting section of this tutorial: Servo Control.
Controlling a servo as discussed before involves sending a modulated square-wave pulse which is known as pulse-Width-Modulation (PWM) or Pulse-Duration-Modulation (PDM). If signal voltage from peak to peak (amplitude) is taken care as per the datasheet (which is generally 3V to 5V), then there two other main factors to be considered while sending a PWM signal to servo; “Frequency” and “Duty cycle”.
Servo expects continuous pulses to move or hold its position. Frequency (or repetition time, or cycle time) is the number of times a positive pulse is fed to servo in a unit time (which is generally measured in seconds); for analog servos, frequency is generally 50 times a second (50Hz) and for digital servos it is 300 times a second (300Hz).
50Hz = Positive pulse 50 times a second; i.e. 1/50 = 0.02 seconds = 20ms (timeout period). This means every 20 milliseconds servo expects a pulse to retain its corresponding angular position.
300Hz = Positive pulse 300 times a second; i.e. 1/300 = 0.0033 seconds = 3.33ms (timeout period). This means every ~3 milliseconds servo expects a pulse to retain its corresponding angular position.
If servo does not receive a pulse before the timeout period, then servo releases its hold and can move to any forced position.
Note: Required pulse frequency for few servos may be less, or more depending on the particular model and manufacturer.
“Duty cycle” is the width of positive pulse (square wave) and a deciding factor for servo’s angular position. For example, if you have a servo with 180° turn, then 90° is the center position of the servo with 0° being minimum, and 180°, being the maximum. Now, if a positive pulse of 1.5ms is sent, then the servo stays at 90° (servo center) as long as it receives the same pulse. If another pulse of 1ms is sent, the circuit tries to move the shaft to 0°, and a pulse of 2ms tries to move the output shaft to 180°. This means, a pulse shorter than 1.5ms moves the servo in one direction and wider than 1.5ms moves it in another direction.
Different servo models have different minimum and maximum pulse requirements. For example, a Hextronik servo I have has a minimum pulse requirement of 0.5ms to move to 0° and maximum pulse duration of 2.5ms to move to 180°. Sending a pulse of 1ms moves it to 45° and 2ms moves it to 135°. Another servo requires 1ms pulse to move to 0°, 1.5ms to move to 45° and 2ms to move to 90° and maximum angular rotation being 90°. The de-facto standard is 1ms for minimal angle, 1.5ms for servo center and 2ms for maximum angle. Servo center is almost always 1.5ms and minimum and maximum should be verified in product’s datasheet.