| Prescaler (PSC) | Period (ARR) (ARR) | Actual Frequency | Error |
|---|
Find the best prescaler (PSC) and auto-reload (ARR) values for your MCU timer to achieve a target frequency with minimal error.
| Prescaler (PSC) | Period (ARR) (ARR) | Actual Frequency | Error |
|---|
An MCU timer counts clock pulses. The prescaler divides the input clock before it reaches the counter, and the auto-reload (ARR) value determines when the counter overflows. Together, PSC and ARR control the timer's output frequency: f_timer = f_clk / (PSC+1) / (ARR+1). Choosing values that produce zero error means the timer hits the target frequency exactly.
Prefer smaller prescaler values when you need finer frequency resolution. For PWM, a larger ARR gives more duty-cycle steps. When exact frequency isn't possible, check whether the error percentage is acceptable for your application — under 0.1% is usually fine for most use cases. Some MCUs (e.g. STM32) multiply the APB bus clock before it reaches the timer, so verify f_clk in your reference manual.
A prescaler is a clock divider that reduces the counting frequency of an MCU timer. Setting PSC to N means the timer increments once every N+1 clock cycles, slowing down the effective count rate.
Compute f_clk / f_target to get the total divisor. Then factorize it into (PSC+1) × (ARR+1) where both values fit in the counter width. If the total divisor is prime or too large, an exact match may not exist and you'll need to accept a small error.