Part of Premium. It runs in your browser: nothing to install.
The example, worked out
Given
Timer clock
16 MHz
Counter width
16 bits
Prescaler
Pick for me (finest)
I want
A frequency
Frequency
1 kHz
Working
ticks per period
the counter goes from 0 to ARR, that is N ticks
what you really get
Results
Prescaler÷ 1
Reload (top) value15,999
Frequency you get1 kHz
Period you get1 ms
Error+0 %
PWM resolution here14 bits
Longest period, this prescaler4.1 ms
The formulas
N = fclk / (P × f)ticks per period
ARR = round(N) − 1the counter runs from 0 to ARR
PWM bits = log2(ARR + 1)the duty resolution at that frequency
The usual traps
Writing the prescaler without the minus one.
A small count weighs one tick heavily: pick the smallest prescaler that fits.
Questions
How do I set the prescaler and reload of a microcontroller timer?
N = fclk / (P × f): ticks per period. ARR = round(N) − 1: the counter runs from 0 to ARR. PWM bits = log2(ARR + 1): the duty resolution at that frequency.
What does it give for typical values?
÷ 1, reload 15999 for 1 kHz on 16 MHz (0 % off). Prescaler: ÷ 1; Reload (top) value: 15,999.
What are the usual mistakes?
Writing the prescaler without the minus one. A small count weighs one tick heavily: pick the smallest prescaler that fits.
In the app
Your circuit, drawn live
Change a value: the schematic redraws with your numbers on the parts.
The part you can buy
Results rounded to standard values (E12, E24, E96) and power ratings.
The working, shown
Every step written out. Try it first by hand, then check.
Into your notebook
One click puts the circuit on a sheet of your project.
Open the calculatorOpens in the app on 1 December, with Circuit Notebook 1.0
Also in Embedded
ADC resolutionThe size of one step, the ideal SNR, what a measured SNR is worth in bits.
555 timerAstable frequency and duty, or the pulse of a monostable.