/ˌpiːˌdʌbəljuːˈɛm/

noun — "modulates digital signal duty to control analog behavior."

PWM, short for Pulse-Width Modulation, is a technique used to encode analog signal levels or control power delivered to electronic devices by varying the duty cycle of a digital square wave. It allows a digital output, such as a microcontroller pin, to simulate analog voltage levels by controlling the ratio of time the signal is high versus low within a fixed period.

Technically, a PWM signal is defined by two main parameters:

  • Frequency — the number of complete cycles per second
  • Duty cycle — the percentage of one cycle in which the signal is high

The output voltage seen by a device is proportional to the duty cycle. For example, a 50% duty cycle on a 5V signal results in an average voltage of 2.5V over the cycle.

 


# Example: controlling LED brightness
PWM_frequency = 1000  # 1 kHz
Duty_cycle = 75      # 75 high, 25 low
# LED sees an average of 0.75 * 5V = 3.75 V

In embedded systems, PWM is commonly used for:

  • Controlling LED brightness
  • Driving motors with variable speed
  • Generating audio tones or simple waveforms
  • Voltage regulation in power electronics

 

The microcontroller or peripheral hardware generates the PWM signal using timers or counters. Software configures the frequency, duty cycle, and output pin, while the hardware ensures precise timing. Some advanced PWM modules support complementary outputs, dead-time insertion, and synchronized multi-channel operation for complex motor control.

Conceptually, PWM is like turning a switch on and off very quickly. The longer the switch is on relative to off, the brighter the LED or faster the motor spins. The device integrates the high-speed pulses into an effective analog response, giving precise control while using simple digital logic.

See GPIO, Microcontroller, Embedded Systems, SPI.