PWM Duty & Frequency Calculator

PWM Duty & Frequency Calculator

Calculate PWM parameters for any microcontroller. Frequency, resolution, duty cycle mapping for servo, LED, motor control.

Key Formulas

fPWM = fclk / (N × TOP)

Vavg = Vmax × Duty

Frequently Asked Questions

What does this PWM Duty & Frequency Calculator compute?

This tool calculates key PWM parameters including the required prescaler and auto-reload (ARR) register values for common microcontrollers (e.g., STM32, ESP32, AVR), along with achievable resolution, duty cycle step size, average output voltage, and RC filter cutoff frequency. It bridges theoretical specs to practical register-level configuration.

How do I use this calculator for servo motor control?

For standard 50 Hz servos, set Desired PWM Freq to 50 Hz and Duty Target to 2.5–12.5% (corresponding to 0°–180°). The tool confirms whether your clock and resolution support the required 10 ms period and ~20 µs pulse width resolution — critical for smooth, jitter-free positioning.

What is the significance of “Clock Frequency” in the inputs?

Clock Frequency refers to the timer peripheral’s input clock (e.g., APB1/APB2 for STM32, or system clock divided for ESP32 timers). It directly determines the smallest time increment (tick) available — higher clocks enable higher PWM frequencies or finer duty resolution at a given frequency.

Why does increasing resolution reduce maximum achievable PWM frequency?

Resolution (in bits) defines the number of distinct duty steps (2res). For a fixed clock, higher resolution requires a longer period to count all steps — lowering max frequency. For example, 16-bit resolution at 72 MHz limits max frequency to ~1.1 kHz, while 8-bit allows ~281 kHz.

What are typical values for Clock Frequency and Resolution across common MCUs?

Clock Frequency commonly ranges from 8 MHz (basic AVRs) to 160–240 MHz (high-end ARM Cortex-M7/M8). Resolution typically spans 8–16 bits; many STM32 timers support up to 16 bits, while ESP32 LEDC supports 10–15 bits, and Arduino’s analogWrite() defaults to 8-bit (256 steps).

How does the RC Filter R value affect my PWM-to-analog output?

The RC filter (with optional C value inferred or entered separately) smooths PWM into a DC voltage. This tool computes its cutoff frequency (fc = 1/(2πRC)). To avoid ripple, fc should be ≪ PWM frequency — e.g., for 20 kHz PWM, aim for ≤200 Hz cutoff using R=10 kΩ and C≈80 nF.

Why does my calculated duty cycle not match the expected output voltage?

Verify that Output V reflects the *actual* PWM high-level voltage (e.g., 3.3 V for GPIO, not 5 V). Also ensure no load-dependent voltage droop or logic-level mismatch (e.g., open-drain vs push-pull). The calculator assumes ideal switching — real-world losses, diode drops, or driver saturation may reduce effective Vout.

Can this tool help me avoid aliasing or audible noise in motor/LED applications?

Yes — set Desired PWM Freq above 20 kHz to eliminate audible switching noise in motors and LEDs. The tool flags when your clock/resolution combination falls short, and suggests tradeoffs (e.g., lowering resolution to hit 25 kHz). It also highlights duty step size to ensure smooth brightness/speed transitions.

What does “Duty Cycle Step Size (%)” mean in the results?

It’s the smallest duty cycle increment possible at your chosen resolution and frequency — calculated as 100% / 2res. A 12-bit resolution yields ~0.024% steps; insufficient for fine dimming below ~1% or precise servo angles. Use this to verify if your resolution meets application granularity requirements.

How do I interpret the “Timer Register Values” output for STM32 or ESP32?

The Prescaler sets timer clock division (e.g., PSC = 71 for 72 MHz → 1 MHz tick); Auto-Reload (ARR) defines period count (e.g., ARR = 49 for 20 kHz at 1 MHz). For STM32 HAL, use these directly in htim.Init.Prescaler and htim.Init.Period; for ESP32 LEDC, map to ledc_timer_config_t and channel duty values.