Something that a project that I'm working on has me doing is using a serial to parallel IC (think 74HC595) to control leds. However, rather than drive the leds directly from the pins, I opted for the use of transistors. After testing this out, it became apparent to me that perhaps the leds might be too bright, so I went in search of a simple PWM generator.
Of course, there are a couple of instructables that already feature such a circuit, but I was unable to get them to work correctly for whatever reason. This being the case, I will now present the circuit that I came across and works very well.
Step 1: Yet Another Overview
PWM stands for Pulse Width Modulation, which is a simple way of efficiently supplying varying amounts of power.
For example. Say that you wanted to control the brightness of an led (note: there are many ways to do this, but for the sakes of an example, I'll only note two). The first way would be to put a variable resistor in series with the led. This would alter the amount of current that went through the led, while holding the voltage constant. If you put the variable resistor at 40%, the led would be 40% as bright as it could be.
The second way would be to connect a led in series with a resistor and a power supply that could be turned on and off really quickly. Let's say that you were able to turn on and off the power supply quick enough to the point where 40% of the time it was on, and 60% of the time it was off. This would be reflected by the led being on full brightness, but only for 40% of the time, giving the illusion of being 40% as bright as it could be.
Two different methods, for the same result. What's the difference? About 60% of the energy gets burned off as heat in the resistor in the first circuit, while in the second circuit, almost all of the energy supplied is used.
This is why PWM is useful. It allows a signal to range from completely off to completely on. If a signal is turned on and off quick enough, given a certain ratio, a signal can appear to be that ratio, without suffering from much power loss at all.