PWM (Pulse Width Modulation): How Digital Signals Control Analog Power

2026-05-22

PWM is how microcontrollers fake an analog output without a DAC. You switch a digital pin on and off very fast, and the ratio of on-time to total period (the duty cycle) determines the average power delivered. A motor, LED, or heater sees the average — not the rapid switching — as long as the frequency is high enough.

The core math: Average voltage = Duty cycle × Vsupply. A 12V supply at 25% duty cycle delivers an average of 3V. The duty cycle ranges from 0 (always off) to 1.0 (always on), typically expressed as 0–255 in 8-bit microcontrollers or 0–65535 in 16-bit timers.

Why it works: Inductive loads (motors, solenoids) and thermal loads (heaters, incandescent bulbs) have time constants much longer than the PWM period. The current can't change instantly through an inductor, and a filament can't cool between pulses. They effectively integrate the waveform. For LEDs, the human eye does the integration — anything above ~200 Hz looks steady.

Picking the frequency:

Real-world example: A 3D printer hotend running on 24V at 40W. You don't want to switch 40W on and off mechanically. The firmware reads the thermistor, runs PID, and outputs a PWM duty cycle to a MOSFET. At 50% duty, the heater dissipates 20W on average. At 100%, it pulls full power for fast heat-up. The thermal mass of the heater block makes the switching frequency irrelevant — even 1 Hz works.

The catch — switching losses: The MOSFET dissipates power during the transitions between on and off. Faster switching means more transitions per second and more heat in the FET. This is why motor drivers use gate driver chips: they slam the MOSFET gate from off to on in nanoseconds, minimizing the time spent in the resistive middle region.

Rule of thumb: If you can hear your motor whining at a specific pitch, your PWM frequency is too low — push it above 20 kHz. If your MOSFET runs hot at high duty cycles, the issue is conduction loss (RDS(on)); if it runs hot at 50% duty, it's switching loss.

See it in action: Check out Pulse Width Modulation (PWM) - Electronics Basics 23 by Simply Electronics to see this theory applied.
Key Takeaway: PWM controls analog power with digital signals by varying duty cycle, relying on the load's inertia (thermal, inductive, or visual) to average out the switching.

All newsletters