📐

PWM / Timer Calculator

Calculate PWM frequency, period, and duty cycle from MCU timer settings.

Quick Presets
Input Parameters
ℹ Edge: f = CLK / (PSC+1) / (ARR+1) | Center: f = CLK / (PSC+1) / (2 * (ARR+1))
Results
Timer Clock—
PWM Frequency—
Period—
Duty Resolution—
Duty Steps—
Compare Value (for duty%)—
Dead Time Duration—
Min Achievable Freq—
Max Achievable Freq—
💡 Usage & Formula

PWM (Pulse Width Modulation) is used to control power delivery by switching a digital signal on and off rapidly.

Formulas:

  • Edge-Aligned Mode: f = Clock / ((PSC + 1) * (ARR + 1))
  • Center-Aligned Mode: f = Clock / ((PSC + 1) * 2 * (ARR + 1))
  • Duty Cycle %: (CCR / (ARR + 1)) * 100

Usage: Enter your MCU's timer clock frequency, select the alignment mode, and set the Prescaler and Period Count to calculate the resulting PWM frequency and resolution.

When you need it: Setting an LED dimming or motor-drive frequency, generating a servo pulse, or synthesising an analog voltage by low-pass filtering the output. On an MCU the real task is picking a timer prescaler (PSC) and auto-reload (ARR) that hit your target frequency, then a compare value (CCR) for the duty.

Worked example: A 72 MHz timer clock targeting 20 kHz PWM needs ARR + 1 = 72e6 / 20000 = 3600, so PSC = 0, ARR = 3599. For 25% duty, CCR = 0.25 × 3600 = 900. The available duty resolution is timer_clk / f = 3600 steps (~11.8 bits).

Tips & gotchas:

  • Resolution and frequency trade off: at a fixed timer clock, doubling the PWM frequency halves the number of duty steps.
  • Higher frequency reduces audible whine and output ripple but raises switching losses in the driver/MOSFET.
  • Use center-aligned mode for motor drive (symmetric edges, lower harmonics) and insert dead-time on complementary half-bridge outputs.
  • To make an analog voltage, size the RC filter so fc ≪ f_PWM; ripple falls ~20 dB/decade below the PWM frequency.