Paritian

Developers

Timer and PWM Frequency Calculator (Prescaler, TOP and Resolution for Arduino, AVR, STM32)

PWM or overflow frequency from the timer clock, prescaler and counter top value, with the period, the duty-cycle resolution and the TOP you would need for a wanted frequency.

Results

PWM / overflow frequency 976.563 Hz
Period 1024.000 µs
One timer tick 4.0000 µs
Duty-cycle steps available 256
Duty-cycle resolution 8.00 bit
Smallest duty-cycle step 0.3906 %
TOP needed for the wanted frequency 249.0

What this tool does

Timer frequency is the clock divided by the prescaler and by the number of counts per cycle, and every choice trades speed for resolution: at 16 MHz with no prescaler, an 8-bit fast PWM runs at 62.5 kHz but has only 256 duty steps. A hobby servo wants 50 Hz, which at 16 MHz needs a 16-bit timer with a prescaler of 8 and a TOP of 39 999. Phase-correct (centre-aligned) PWM counts up and down, so it runs at half the frequency of fast PWM for the same TOP.

Formula

f = f_clk ÷ (N × (TOP + 1)) (fast PWM) · f = f_clk ÷ (2 × N × TOP) (phase-correct) · resolution = log₂(steps)

Variables

SymbolMeaningUnit
ckTimer clockMHz
prPrescaler (divider)—
tpCounter top value (TOP, ARR or ICR)—
mdCounting mode—
ftFrequency you wantHz
FPWM / overflow frequencyHz
PEPeriodµs
TKOne timer tickµs
STDuty-cycle steps available—
BTDuty-cycle resolutionbit
DSSmallest duty-cycle step%
NTTOP needed for the wanted frequency—

Worked example

  • Timer clock16 MHz
  • Prescaler (divider)64
  • Counter top value (TOP, ARR or ICR)255
  • Counting mode1
  • Frequency you want1000 Hz
  • PWM / overflow frequency976.563 Hz
  • Period1024.000 µs
  • One timer tick4.0000 µs
  • Duty-cycle steps available256
  • Duty-cycle resolution8.00 bit
  • Smallest duty-cycle step0.3906 %
  • TOP needed for the wanted frequency249.0

Limitations

  • The formula assumes ideal conditions: no friction losses, no air resistance and no efficiency losses unless you enter them.
  • Coverage and consumption figures vary between products. Take the values from the manufacturer's datasheet for the product you are actually using.