PWM Servo Calculator
Calculate PWM pulse width, duty cycle, and the resulting servo angle for hobby servos and microcontroller projects. Free, instant.
Last updated:
Period = 20000 µs (1/50 Hz)
Was this tool useful?
Use the tool above and you can rate it here.
How the PWM Servo Calculator works
The PWM servo calculator converts between servo angle (0°–180°), pulse width (1–2 ms), and duty cycle for the standard 50 Hz servo control frequency. It also computes the timer compare register value (CCR) for STM32 timers and the analogWrite or microsecond values for Arduino and ESP32 — eliminating manual PWM calculations during RC robot, gimbal, and CNC project development.
Standard servo PWM protocol
RC servos are controlled by a 50 Hz PWM signal (20 ms period). The pulse width encodes position: 1 ms (1,000 µs) corresponds to 0° (full left), 1.5 ms (1,500 µs) to 90° (centre), and 2 ms (2,000 µs) to 180° (full right). Some servos accept a wider range of 0.5–2.5 ms for extended travel. The calculator allows customisation of the minimum and maximum pulse widths to match the specific servo's datasheet range.
Duty cycle calculation
At 50 Hz, the period is 20 ms. A 1 ms pulse gives a duty cycle of 1/20 = 5%. A 2 ms pulse gives 10% duty cycle. The Arduino Servo library handles these conversions internally via writeMicroseconds() — but if you are using raw PWM (analogWrite on a 490 Hz or 980 Hz channel), the duty cycle values differ significantly and the calculator provides the corrected values for both 8-bit (0–255) and 16-bit (0–65535) timer resolutions.
STM32 timer CCR values
On STM32 microcontrollers, servo PWM is generated using a timer channel in PWM mode, as detailed in the STM32F1 reference manual. The ARR (auto-reload register) sets the period; CCR (capture-compare register) sets the pulse width. For a 72 MHz clock with prescaler 71 (1 MHz timer clock) and ARR = 19999 (50 Hz), a 1 ms pulse requires CCR = 999 and a 2 ms pulse CCR = 1999. The calculator outputs CCR values for any timer clock frequency and target angle.
ESC calibration for brushless motors
Electronic speed controllers (ESCs) for brushless motors use the same 50 Hz PWM protocol as servos but interpret the pulse range differently — 1 ms is minimum throttle (stop), 2 ms is maximum throttle (full speed). ESC calibration requires sending a 2 ms pulse at power-on (arming), then a 1 ms pulse to complete calibration. The calculator's ESC mode provides the exact microsecond values and Arduino code snippet for the full calibration sequence.
Frequently asked questions
- What PWM frequency do servos use?
- Standard analog RC servos use a 50 Hz PWM signal with a 20 ms period. The pulse width within each period — from 500 µs to 2500 µs — controls the servo shaft angle from 0 to 180 degrees. Some digital servos support higher update frequencies up to 333 Hz for faster response and more precise position holding, but require a compatible controller.
- What is the standard servo pulse range?
- Most hobby and RC servos use 1000 µs to 2000 µs (1 ms to 2 ms) as their safe working pulse range, with 1500 µs representing the center position at 90 degrees. Many servos physically accept the wider range of 500 µs to 2500 µs for an extended angle range, but exceeding the servo's mechanical limits can damage the gears. Always check your specific servo's datasheet.
- How do I calculate the 16-bit timer compare value?
- For a 16-bit hardware timer configured for 50 Hz output, the compare register value is: compare value = (pulse width in µs / 20000 µs) × 65535. For example, for a center position pulse of 1500 µs at 50 Hz: (1500 / 20000) × 65535 = 4915. Load this value into the timer's OCR (Output Compare Register) to produce the correct pulse width.
Related tools
- Embedded Number Converter
Convert numbers between hex, decimal, binary, and octal instantly — built for embedded and firmware development. Free, no sign-up.
- ESP32 Pinout Reference
Complete ESP32 WROOM-32 pinout reference with GPIO, ADC, SPI, I2C, and UART pins clearly labelled for every board revision. Free.
- Arduino Pinout Reference
Complete Arduino Uno R3 pinout reference with digital, analog, and PWM pins clearly labelled for quick lookup. Free, no sign-up.
- Raspberry Pi GPIO Pinout
Complete Raspberry Pi 40-pin GPIO reference showing power, ground, and every numbered pin for any model. Free, instant, no sign-up.
- Resistor Color Code Calculator — 4, 5 & 6 Band Decoder
Decode 4, 5 and 6-band resistor color codes, or enter a resistance to get the bands. Shows tolerance and the nearest E12/E24 value.