Pulse width modulation is used when a digital system needs to control a system that expects an analog signal of varying amplitude. A typical example is a 12 V motor: the speed of the rotor can be regulated by changing the voltage from low (0 V) to high (12
V). At 12V the motor will go at full speed. The alternative is to pass the rotor always
12V, but in discrete pulses, as shown in Fig. 1. If 20% of the time is filled by pulses (20% duty cycle), then the motor will receive small kicks that keep it running at a low percentage of full speed. The motor runs smoothly because of the inertia of the rotor and because the frequency of the pulses can be adjusted.
Figure 1: A PWM signal and three different duty cycles
A PWM is, in some sense, a special purpose digital to analog converter. Most microcontrollers provide one or more PWM output lines.
The advantage of controlling a motor with PWM instead of a real analog signal is that the full torque of the motor can be used. In DC motors, there is a linear relationship between the voltage supplied and the torque obtained from the motor: the higher the voltage, the higher the torque. Think of a small motor used for moving a loaded car. If the analog voltage is too low, the motor will not move, because of the load and friction between the wheels and the floor. We have to start increasing the voltage until at some point the wheels move and the car goes away at great speed (because dynamical friction is lower than static friction). A PWM signal, on the other