How a timer makes PWM
The prescaler divides the timer clock by PSC + 1. The counter then counts these ticks from 0 up to ARR and starts again, so one PWM period is ARR + 1 ticks:
fPWM = fclock / ((PSC + 1) × (ARR + 1))
The output switches when the counter passes the compare value CCR, so the duty cycle is CCR / (ARR + 1). With a 72 MHz clock, PSC = 71 and ARR = 999 the counter runs at 1 MHz and the PWM at 1 kHz; CCR = 250 gives 25% duty.
In center-aligned mode the counter goes up to ARR and back down, so a period is 2 × ARR ticks: fPWM = fclock / ((PSC + 1) × 2 × ARR), and the duty cycle is CCR / ARR.
Frequency or resolution
For a given clock, a higher PWM frequency leaves fewer steps per period. ARR + 1 is the number of duty cycle steps, so PSC = 0 gives the finest control. The second panel puts that setting first, then lists settings that land closer to the target, if any, at the cost of resolution.
| Clock | PWM | PSC | ARR | Steps |
|---|---|---|---|---|
| 72 MHz | 1 kHz | 1 | 35999 | 36,000 |
| 72 MHz | 20 kHz | 0 | 3599 | 3,600 |
| 72 MHz | 50 Hz (servo) | 23 | 59999 | 60,000 |
| 16 MHz | 1 kHz | 0 | 15999 | 16,000 |
| 48 MHz | 25 kHz (PC fan) | 0 | 1919 | 1,920 |
| 170 MHz | 100 kHz | 0 | 1699 | 1,700 |
Frequently asked questions
Why PSC + 1 and ARR + 1?
Both registers count from 0. PSC = 0 divides by 1, and ARR = 999 gives the 1000 counts 0 to 999. This is also why a 16-bit ARR of 65535 gives 65,536 steps.
Which clock does my STM32 timer use?
Timers run from their APB bus clock. When the APB prescaler is more than 1, most STM32 parts run the timers at twice the APB clock, so on an STM32F103 at 72 MHz with APB1 at 36 MHz, TIM2 to TIM4 still see 72 MHz. Check the clock tree in your reference manual or CubeMX.
Does this work for AVR and Arduino?
Yes. In AVR fast PWM, f = fclock / (N × (1 + TOP)), so choose “AVR prescaler N” as the prescaler type, pick N from the list and enter TOP as ARR. For 8-bit Timer0 and Timer2, choose the 8-bit timer. Phase-correct PWM matches the center-aligned formula. The Arduino Uno’s default PWM on pins 5 and 6 is 16 MHz / (64 × 256) ≈ 977 Hz.
What PWM frequency should I use?
LED dimming is usually a few hundred Hz to a few kHz, high enough to avoid visible flicker. Motors are often driven at 20 kHz or more so the switching can’t be heard. Hobby servos expect 50 Hz with a 1 to 2 ms pulse.