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 regDividerARR / TOPCCRActual HzError %Resolution
0/14199210020000.000.0000%12.04 bit
1/22099105020000.000.0000%11.04 bit
2/3139970020000.000.0000%10.45 bit
3/4104952520000.000.0000%10.04 bit
4/583942020000.000.0000%9.71 bit
5/669935020000.000.0000%9.45 bit
6/759930020000.000.0000%9.23 bit
7/852426320000.000.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

QuestionAnswer
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.