Home / Learn Embedded C / PWM for Servo Control
PWM for Servo Control
Using specially-timed PWM pulses to command a hobby servo motor's exact angle.
The idea, explained simply
What it is
A hobby servo is controlled not by varying duty cycle in the usual sense, but by the exact WIDTH of a pulse repeated roughly every 20ms — typically ~1ms for one extreme angle, ~1.5ms for center, ~2ms for the other extreme.
Why it matters
Servos are used throughout robotics and remote-control projects for precise angular positioning — understanding that servo PWM timing differs from LED/motor PWM is essential to driving one correctly.
Mechanically speaking
Unlike LED/motor PWM (where only the percentage matters), servo control is sensitive to the ABSOLUTE pulse width in time (microseconds), not a 0-255 style duty value — a subtle but important distinction.
Shows up in
- Robotics joints/actuators
- RC vehicle steering
- Camera gimbals
Try it
A real servo driver uses a hardware timer's output-compare feature (covered next) to generate these exact pulse widths repeatedly, without CPU intervention each cycle.
Try it: mapping an angle in degrees to a pulse width
Real servo libraries perform exactly this kind of linear mapping from a requested angle to the microsecond pulse width the servo expects.
Check yourself
1. What determines a hobby servo's commanded angle?
Servo control pulses are read by their exact width in microseconds — around 1-2ms, repeated roughly every 20ms — which the servo interprets as a target angle.