Timers & Motor Control
PWM Timer Prescaler & ARR Calculator
Solve exact PSC, ARR and CCR register values with maximum duty-cycle resolution for STM32, AVR, RP2040 and ESP32 hardware timers.
f_PWM = f_TIM / ((PSC + 1) * (ARR + 1))
50 Hz servo, 20 kHz BLDC/FOC, 100 kHz buck converter
Quick presets:
Best PSC / Divider0Effective divider /1
ARR / TOP4199CCR = 2100 (50%)
Actual Frequency20000.00 HzError +0.0000%
Duty Resolution12.04 bits4200 discrete steps
| PSC reg | Divider | ARR / TOP | CCR | Actual Hz | Error % | Resolution |
|---|---|---|---|---|---|---|
0 | /1 | 4199 | 2100 | 20000.00 | 0.0000% | 12.04 bit |
1 | /2 | 2099 | 1050 | 20000.00 | 0.0000% | 11.04 bit |
2 | /3 | 1399 | 700 | 20000.00 | 0.0000% | 10.45 bit |
3 | /4 | 1049 | 525 | 20000.00 | 0.0000% | 10.04 bit |
4 | /5 | 839 | 420 | 20000.00 | 0.0000% | 9.71 bit |
5 | /6 | 699 | 350 | 20000.00 | 0.0000% | 9.45 bit |
6 | /7 | 599 | 300 | 20000.00 | 0.0000% | 9.23 bit |
7 | /8 | 524 | 263 | 20000.00 | 0.0000% | 9.04 bit |
Timer register formulas
Off-by-one errors in PSC and ARR shift switching frequencies and break closed-loop FOC timing. On STM32, hardware adds one internally to both registers, so a 100-tick period writes 99.
STM32 TIM3 bare-metal PWM setup
TIM3->PSC = psc_reg; /* effective divider = psc_reg + 1 */
TIM3->ARR = arr_reg; /* edge-aligned period = arr_reg + 1 ticks */
TIM3->CCR1 = ccr_reg; /* duty = ccr_reg / (arr_reg + 1) */
TIM3->CCMR1 |= (6U << 4) | TIM_CCMR1_OC1PE; /* PWM mode 1 + preload */
TIM3->CCER |= TIM_CCER_CC1E;
TIM3->CR1 |= TIM_CR1_ARPE | TIM_CR1_CEN;Frequently asked questions
| Question | Answer |
|---|---|
| Why does maximizing ARR instead of PSC improve PWM quality? | Every count in ARR adds one discrete duty-cycle step. Keeping PSC as small as possible maximizes ARR and pushes duty resolution closer to 12 to 16 bits, which matters for motor current loops and LED dimming. |
| How does center-aligned PWM change the frequency formula? | A center-aligned timer counts up from 0 to ARR and back down to 0 each switching cycle. That doubles the period compared to edge-aligned mode, so f_PWM equals f_TIM divided by (2 * (PSC + 1) * ARR). |
| Why is my STM32 PWM frequency twice what I calculated from APB1? | Whenever the APB1 or APB2 prescaler is greater than 1, STM32 multiplies the timer kernel clock by 2. Enter the doubled timer clock here, not the raw APB peripheral clock. |