EN

Servo motors

From the angle to the pulse width and from the pulse to the timer registers

Calculator

Servo
°
µs
µs
°
°
ms
Microcontroller timer
MHz
Power
A
A

Pulse widths of 1000 to 2000 µs are the standard, but many servos accept 500 to 2500 µs for a wider travel; check it gradually so as not to force the mechanical stops. Indicative currents for a small SG90-type servo; an MG996R can exceed 2 A when stalled.

How a servo works

A hobby servo combines in one housing a DC motor, a gearbox, a potentiometer attached to the output shaft and a small control circuit. The circuit compares the position measured by the potentiometer with the one requested by the signal and drives the motor until they match: it is a closed position loop. That is why a servo holds its angle even when pushed, up to the limit of its torque.

The control signal

The position is set with a pulse repeated every 20 ms (50 Hz). What matters is its width, not the duty cycle: 1 ms takes the shaft to one end, 1.5 ms to the centre and 2 ms to the other end. The period can vary somewhat without the servo noticing.

\[ t_{pulse} = t_{min} + \frac{\theta - \theta_{min}}{\theta_{max} - \theta_{min}}\,(t_{max} - t_{min}) \]

In a microcontroller, the pulse is generated with a timer in PWM mode: the period sets the maximum count (TOP) and the width, the compare value. A 16-bit timer gives resolutions of hundredths of a degree. An 8-bit PWM at 50 Hz, on the other hand, has only about 13 useful steps between 1 and 2 ms: the servo moves in jumps of more than 10°. That is why servo libraries use 16-bit timers or generate the pulse with interrupts.

Wiring and power

Servo types

TypeCharacteristics
AnalogRefreshes the position with each pulse, at 50 Hz; cheaper, with some buzz and play
DigitalInternal microcontroller at several hundred Hz: more holding torque and accuracy, more consumption
Continuous rotationNo stop and no position feedback: the pulse sets speed and direction; 1.5 ms is stopped
Industrial servo motorAC or brushless motor with an encoder and a servo drive; position, speed and torque control for machines

If the servo vibrates or jitters at rest, the usual causes are supply noise, an unstable pulse (generated in software with interrupts) or a load that forces it to correct continuously.

Related: PWM calculator, stepper motors, DC motors with an H-bridge and state machines.