PWM

Pulse-width modulation controls average power by switching fully on and off with a variable duty cycle. Learn duty, frequency and resolution, carrier-based PWM, filtering, dead time, and how to choose PWM frequency for LEDs, motors and converters.

Instead of dissipating power in a resistor or linear transistor, PWM switches a load fully on and fully off very quickly. The fraction of time it's on — the duty cycle — sets the average voltage, and the load or a filter smooths the pulses.

PWM is everywhere: LED dimming, motor speed control, every DC–DC converter and inverter, servo signals and class-D audio amplifiers.

An analogy

PWM is like controlling a room's brightness by flicking the light switch on and off very fast: on 25 % of the time looks like quarter brightness, because your eye averages it.

Duty cycle and average

With a 12 V supply, 25 % duty gives 3 V average, 50 % gives 6 V, 100 % gives 12 V. Because the switch is either fully on (tiny voltage drop) or fully off (no current), it dissipates very little power.

Generating PWM

Microcontroller timers count up to a period value and toggle an output when the count passes a compare value. Analogue PWM compares a control voltage with a triangle or sawtooth carrier; the comparator output is the PWM signal.

Choosing the frequency

Higher frequency means smoother output and smaller filters, but more switching loss and lower resolution.

Resolution trade-off

A 72 MHz timer at 20 kHz has 3600 steps (≈ 11.8 bits); at 200 kHz only 360 steps (≈ 8.5 bits). Center-aligned (up-down) counting halves the counts again but produces symmetric pulses with lower harmonics — preferred for motor control.

Complementary PWM and dead time

Half-bridges drive high and low switches with complementary signals separated by dead time. Advanced timers generate these pairs in hardware, with break inputs that shut everything down within nanoseconds on a fault.

Spectrum and dithering

PWM energy sits at the switching frequency and its harmonics, which is what filters and EMC measures target. Spread-spectrum (dithered frequency) PWM smears that energy to lower peak emissions, and sigma-delta or dithered PWM increases effective resolution.

Formulas

Worked example: Timer resolution

Given: f_clk = 72 MHz; f_PWM = 20 kHz, edge-aligned

Find: Counts per period and resolution.

Answer: 3600 steps ≈ 11.8 bits

Worked example: LED dimming

Given: 12 V LED strip; D = 25 %

Find: Average voltage and (for a resistive model) power fraction.

Answer: 3 V average, 25 % brightness

Common mistakes

Applications

Key takeaways

Going further