Pulse Width Modulation (PWM) is a digital control technique that varies the average power delivered to a load by rapidly switching a fixed-voltage signal on and off and adjusting the ratio of on-time to the total cycle time. In a real circuit, PWM changes the average power and thermal dissipation delivered to the load, while the peak voltage and instantaneous current remain identical to the supply rail. Instead of dropping excess voltage as waste heat through a linear resistor or transistor, a microcontroller uses PWM to deliver full voltage in short, calculated bursts.

The Core Mechanics: Frequency, Period, and Duty Cycle

To understand the PWM pulse width modulation definition practically, you need to separate the signal into three distinct parameters: frequency, period, and duty cycle. The period is the total time it takes for one complete on-off cycle. The frequency is how many of those periods occur in one second (measured in Hertz). The duty cycle is the percentage of that period where the signal is HIGH (delivering voltage).

Think of a garden hose with a rapid shutoff valve. If you snap the valve fully open for 1 second, then fully closed for 3 seconds, and repeat this cycle, the water exits in violent, full-pressure bursts. However, if you put a bucket under it, it fills at the exact same rate as if the valve were left continuously 25% open. The water pressure (voltage) is always at its maximum when open, but the average flow (current/power) is 25%.

Different microcontrollers handle the timing of these bursts using dedicated hardware timers. If you rely on software delays (like delayMicroseconds()), your PWM signal will jitter every time an interrupt fires. Hardware PWM offloads this to a silicon peripheral. Below is a spec-sheet comparison of hardware PWM capabilities across common maker boards.

Microcontroller Hardware Module Max Base Clock Resolution Default Arduino Freq
ATmega328P (Uno) Timer0 / Timer1 / Timer2 16 MHz 8-bit (0-255) 490 Hz / 980 Hz
ESP32-WROOM-32 LEDC (LED Controller) 80 MHz (APB Clock) 1 to 20-bit 5000 Hz (at 8-bit)
ESP32-S3 MCPWM / LEDC 80 MHz Up to 16-bit Configurable via prescaler
RP2040 (Pi Pico) 8x PWM Slices 125 MHz (System Clock) 16-bit (0-65535) 1000 Hz (MicroPython default)
Resolution vs. Frequency Trade-off: On the ESP32, the LEDC peripheral's maximum frequency is inversely proportional to its resolution. If you configure a 16-bit resolution (65,536 steps), your maximum frequency drops to roughly 1.2 kHz. If you need a 20 kHz signal to avoid audible motor whine, you must drop the resolution to 11 bits or lower. See the Espressif LEDC API documentation for the exact clock divider formulas.

Worked Example: Sizing a PWM Signal for a 12V DC Motor

Let's apply the math to a real-world embedded scenario. You are driving a 12V, 2A brushed DC motor using an IRLZ44N logic-level MOSFET controlled by an ESP32 GPIO pin. You want the motor to run at roughly 75% of its maximum speed.

1. Calculate the Duty Cycle and Average Voltage
Target speed: 75%.
Duty Cycle = 75% (or 0.75).
Peak Voltage = 12V (when the MOSFET is fully ON).
Average Voltage = 12V × 0.75 = 9V.

2. Determine the Frequency and Timing
Brushed DC motors can emit an audible, annoying whine if driven at frequencies within the human hearing range (20 Hz to 20 kHz). To keep the motor quiet, we will set the PWM frequency to 20 kHz (ultrasonic).

  • Period (T): 1 / 20,000 Hz = 0.00005 seconds, or 50 µs.
  • On-Time (HIGH): 50 µs × 0.75 = 37.5 µs.
  • Off-Time (LOW): 50 µs × 0.25 = 12.5 µs.

3. The Hardware Reality Check (Switching Losses)
At 20 kHz, the ESP32 is commanding the MOSFET to switch on and off 20,000 times every second. Every time the MOSFET transitions between the cutoff region and the ohmic region, it passes through the linear region where both voltage across the drain-source and current through the channel are high. This generates switching loss heat. The IRLZ44N has a relatively high gate charge (approx 63 nC). If you drive it directly from an ESP32 GPIO (which can only source ~40mA max), the rise and fall times will be slow, increasing switching losses. For a 2A motor at 20 kHz, direct GPIO drive is usually acceptable, but for loads above 5A or frequencies above 50 kHz, you must add a dedicated gate driver IC (like a TC4420) to charge the gate capacitance in nanoseconds.

Safety Note: Inductive loads like motors resist changes in current. When the PWM signal goes LOW and the MOSFET cuts off, the motor's collapsing magnetic field will generate a massive reverse voltage spike (flyback voltage). You must place a flyback diode (e.g., 1N5819 Schottky) in reverse parallel across the motor terminals, or this spike will punch through the MOSFET and fry your ESP32.

Where You Meet PWM in Practice

Once you internalize the PWM pulse width modulation definition, you will start seeing it everywhere in power electronics and embedded systems. It is the backbone of modern efficiency.

  • LED Dimming: Human vision features persistence of meaning the eye integrates rapid light pulses into a perceived average brightness. However, if the PWM frequency is too low (e.g., 100 Hz), smartphone cameras will capture severe banding and flicker. Professional LED drivers use >1 kHz, often pushing to 20 kHz to eliminate camera flicker entirely.
  • PC Cooling Fans: The Intel 4-Wire PWM Fan specification mandates a 25 kHz PWM signal on the blue control wire. This specific frequency was chosen because it sits above the audible range of human hearing, preventing the fan blades and internal coils from resonating and whining at lower frequencies.
  • Switch-Mode Power Supplies (SMPS): Buck and boost converters use PWM to regulate output voltage. The controller monitors the output via a feedback loop and dynamically adjusts the duty cycle of the internal MOSFET. If the 5V output sags to 4.8V under a heavy load, the controller widens the PWM pulse to dump more energy into the inductor.
  • RC Servos: Hobby servos use a specialized, low-frequency PWM variant. The signal operates at 50 Hz (a 20 ms period), but the position is dictated strictly by the absolute width of the HIGH pulse, typically ranging from 1.0 ms (0 degrees) to 2.0 ms (180 degrees).

Common Confusions: PWM vs. DAC and PFM

When reading datasheets or designing circuits, engineers frequently confuse PWM with other modulation or conversion techniques. Understanding the distinctions prevents costly design flaws.

PWM vs. DAC (Digital-to-Analog Converter)
A DAC outputs a true, steady DC voltage proportional to a digital value. If you write 128 to an 8-bit DAC referenced to 5V, the output pin sits at a constant 2.5V. If you write 128 to a PWM pin, the output pin violently swings between 0V and 5V, spending 50% of its time at each extreme. If you feed a DAC signal into an audio amplifier, you hear smooth music. If you feed raw PWM into an audio amplifier, you hear a harsh, high-frequency square-wave buzz. To make PWM act like a DAC, you must pass it through an RC low-pass filter to smooth the square wave into a DC average. For a 1 kHz PWM signal, a 10kΩ resistor and a 1µF capacitor (yielding a cutoff frequency of ~15.9 Hz) will effectively smooth the ripples into a usable analog voltage, as detailed in this All About Circuits PWM guide.

PWM vs. PFM (Pulse Frequency Modulation)
In PWM, the frequency is fixed and the pulse width (on-time) changes to regulate power. In PFM, the pulse width is fixed (often to the minimum on-time the hardware can reliably achieve), and the controller regulates power by changing the frequency (skipping pulses entirely when the load is light). Modern DC-DC buck converters (like the TI TPS62160) often use PWM at heavy loads for tight voltage regulation and low ripple, but automatically switch to PFM at light loads. PFM drastically reduces the quiescent current consumed by the controller's internal logic when the system is sleeping, extending battery life in IoT sensor nodes.