Rate this calculator

PWM Calculator

Calculate PWM period, on/off times, and average voltage from frequency and duty cycle — or find the duty cycle needed to achieve a target average voltage.

PWM Parameters

%
V

Results

Period (T)1.000 ms
tON500.0 µs
tOFF500.0 µs
Average voltage (Vavg)2.500 V
VavgtONtOFFVp

Vavg = Vpeak × D/100

Common PWM Frequencies by Application

ApplicationTypical Frequency
DC motor speed control1–20 kHz
Servo motor control50 Hz
LED dimming100 Hz – 20 kHz
Switching power supply20 kHz – 2 MHz
Class D audio amplifier40 – 400 kHz
Piezo buzzer tone1 – 20 kHz

How PWM Works

Pulse-Width Modulation (PWM) is a technique for encoding analog information in a digital signal by varying the fraction of time the signal is high (the duty cycle). The average voltage seen by the load equals the peak voltage multiplied by the duty cycle.

A low-pass filter on the output converts the PWM waveform to a true DC analog voltage equal to Vavg. Without a filter, the load itself may integrate the switching (e.g., a motor's inductance or an LED's phosphor persistence).

Average Voltage

Vavg = Vpeak × D / 100

Period and Timing

T = 1 / f | tON = T × D/100

Key Points

  • Higher frequency: smoother output but higher switching losses
  • D = 0% = always off; D = 100% = always on
  • Motor control: higher frequency reduces audible noise (>20 kHz)
  • Servos use 50 Hz with 1–2 ms pulse width to encode angle
  • LED dimming: >100 Hz prevents visible flicker
  • PWM resolution: an N-bit timer gives 2ᴺ steps of duty cycle

Applications

  • Motor speed and direction control
  • LED brightness dimming
  • Servo position control
  • Switching power supply duty cycle
  • DAC via RC low-pass filter

PWM Formulas

D = t_on / T = t_on × f | Vavg = D × Vhigh + (1–D) × VlowFor Vlow=0: Vavg = D × Vcc | f = 1/T | T = t_on + t_offResolution: n bits → 2ⁿ steps, step size = Vcc/2ⁿArduino 8-bit: f = F_CPU / (prescaler × 256)

Arduino PWM Reference

TimerPinsDefault freqPrescaler optionsNotes
Timer0D5, D6976 Hz1,8,64,256,1024millis() uses this
Timer1D9, D10490 Hz1,8,64,256,102416-bit timer
Timer2D3, D11490 Hz1,8,32,64,128,256tone() uses this
ESP32Any GPIO1Hz–40MHzconfigurableLEDC peripheral
RP2040Any GPIO1Hz–62.5MHzconfigurableFlexible PWM

Practical Examples

DC motor speed control (Arduino, D9)

analogWrite(9, 128): D = 128/255 = 50.2%, Vavg = 0.502×12V = 6.02V → ~50% speed

Frequency = 490Hz. For smoother motor control, increase to 20kHz (above audible).

LED dimming at 1kHz (ESP32)

ledcSetup(0, 1000, 8): 1kHz, 8-bit → 256 steps

ledcWrite(0, 64): D = 64/256 = 25% → LED at 25% brightness

At 1kHz: no visible flicker (human eye flicker threshold ~60Hz)

Design Tip

For motor control, use f > 20kHz to avoid audible whine. For LED dimming: f > 200Hz is sufficient (100Hz minimum to avoid flicker on camera). High-frequency PWM increases switching losses in MOSFETs (P_sw = ½×Vds×Id×(tr+tf)×f). RC low-pass filter converts PWM to analog: τ = RC >> 1/f for smooth DAC output.

Did you know? PWM dimming of LEDs is preferred over analog current reduction because LED colour temperature shifts at lower currents. By switching the LED fully on and off rapidly (>100 Hz), PWM maintains consistent colour while varying average brightness — the technique used in all quality LED dimmers.