Pulse-width modulation, or PWM, is a common electronics technique used to reduce the average amount of power that is sent through a circuit. This is useful because we often need to reduce the amount of power that electronic devices receive in order for them to perform needed functions, like making motors slow down and lights dim. PWM is perfect for many of these applications because it can be very easily and accurately controlled with digital devices like the Raspberry Pi.
Imagine a single-speed desk fan. Turning it on normally will make it spin at full speed, but let’s say we need to make it spin a bit slower. A simple way to do this would be to quickly turn it on and off. For the moment it’s on it will start to speed up, but as soon as it’s turned off it will start slowing down. Doing this for a little while will reveal that, on average, the fan is spinning slower and moving less air, because between being turned on and off it never quite reaches full speed nor does it ever completely stop spinning. This is, fundamentally, how PWM works – it just automates the process.
PWM is comprised of two variables: duty cycle and frequency. The duty cycle refers to how long power is turned on vs. how long it’s turned off. A duty cycle of 90%, for example, means that power is on 90% of the time and off for 10%. Using the fan example, it might mean that we leave power on for 9/10 of a second and off for 1/10 of a second. Higher duty cycles mean more average power, and lower duty cycles mean less average power. A 72% duty cycle in a 10V circuit will reduce the average voltage the device receives by 28%, making it act exactly as it would were it only receiving 7.2V from the voltage source.
Frequency, measured in Hz, is the measure of how quickly each duty cycle is performed. A duty cycle of 50% performed at 10 Hz means that 10 duty cycles will be performed in 1 second, with each power pulse lasting for .05 seconds. Given the same duty cycle, all frequencies will produce the same average power in a circuit, though higher frequencies tend to appear “smoother” in practice. 200Hz is a reasonable frequency for most basic applications.
This topic has much more background to cover than some other circuit topics, but is very useful in many applications (including the L293D module). While certainly not a day one circuits topic, I feel that this could be used in an introductory electronics course as long as lots of examples and hands-on explorations are used to aid in understanding – this certainly helped me when I first learned about PWM.
What is pulse-width modulation?
Why would we use pulse-width modulation instead of a variable resistor? (In what particular cases?)
Does every pin on the Raspberry Pi 4 support hardware PWM?
What is the duty cycle? How does it change the effect of PWM?
What is the frequency? Why is it sometimes important to ensure the frequency is high?
Can all devices use PWM?
PWM overviews:
https://www.analogictips.com/pulse-width-modulation-pwm/
Overview that includes points on advantages/disadvantages and more advanced concepts:
https://electricalfundablog.com/pulse-width-modulation/
Raspberry Pi specific overview:
https://circuitdigest.com/microcontroller-projects/raspberry-pi-pwm-tutorial
Compilation of PWM projects, ranging from intermediate to advanced: