PWM Calculator — frequency, resolution and register values
The frequency-versus-resolution trade-off made explicit, with register values for your MCU and duty-cycle counts.
Example: 1 kHz PWM from a 16 MHz clock needs TOP = 15999 with a ÷1 prescaler, giving 14 bits of duty resolution.
Check it against real silicon
Chiprun runs your firmware on an emulated microcontroller and hands back the UART output, so you can confirm these numbers rather than trusting them.
Formula
f_pwm = f_clk / (prescaler × (TOP + 1))Worked example
1 kHz PWM from a 16 MHz clock needs TOP = 15999 with a ÷1 prescaler, giving 14 bits of duty resolution.
steps = f_clk / (prescaler × f_pwm)
steps = 16 MHz / (1 × 1 kHz)
steps = 16000
TOP = steps − 1
TOP = 16000 − 1
TOP = 15999
The counter includes zero, so a period of N steps means TOP = N − 1.
compare = duty × steps
compare = 0.5 × 16000
compare = 8000 (50%)
resolution = log₂(steps)
log₂(16000)
13.97 bits
Frequency and resolution trade against each other — both come out of the same counter.
Frequently asked questions
Why does higher PWM frequency reduce resolution?
Both come out of the same counter. At a 16 MHz clock, a 1 kHz PWM period is 16,000 counter steps — about 14 bits of duty resolution. Push to 100 kHz and only 160 steps remain, around 7 bits. Raising the timer clock is the only way to get both.
What PWM frequency should I use for a motor?
Above 20 kHz if you want it silent, since that is beyond human hearing — audible whine from a motor is almost always the PWM frequency. Below that, higher frequencies mean smoother current but more switching loss in the driver.
What frequency do hobby servos need?
50 Hz, with a pulse between roughly 1 ms and 2 ms. Note that the duty cycle is tiny — 1 to 2 ms out of a 20 ms period is 5–10% — so you need good resolution at low duty, which usually means a large counter value.
Why is my duty cycle slightly off what I asked for?
The compare register is an integer, so achievable duty cycles are multiples of one counter step. With 200 steps the finest adjustment is 0.5%, and anything between lands on the nearest step. The tool shows both the requested and the actual value.
Related tools
Timer & Prescaler Calculator
Every valid prescaler and reload pair for a target frequency on AVR, STM32, PIC and RP2040 — ranked by error, with C you can paste.
Firmware
555 Timer Calculator
Design astable, monostable and 50%-duty 555 circuits. Get the schematic, the waveform, and a bill of materials in stock E24 values.
Circuits
LED Resistor Calculator
Size the current-limiting resistor for any LED, with forward-voltage presets per colour and support for series and parallel arrays.
Components
MOSFET Gate Drive Calculator
Gate charge, drive current, switching loss and conduction loss for a MOSFET at your switching frequency.
Circuits
H-Bridge & Motor Driver Calculator
Motor current, dead-time and driver dissipation for an H-bridge stage.
Circuits
Hex, Binary & Decimal Converter
Convert between hex, binary, decimal, octal and ASCII, with width-aware bit grids and endianness swapping.
Firmware