(article continued from previous page)
We now have a simple circuit for generating variable duty-cycle pulse-width modulation. The next two pages are devoted to practical applications of connecting the PWM to an electronic component.
For testing purposes, it is best to start with a safe, small, and simple load. We'll start by adjusting the brightness of a single LED with a pulse-width modulated wave.
Schematic of an LED connected to the square wave output of the PWM circuit.
Connect a 180 ohm resistor and an LED of any color to pin 4 of the 74AC14 chip, as shown in the schematic. Turning the potentiometer dial changes the amount of “on time” the LED receives, thus changing the brightness.
If the LED doesn’t light, check to see if it is in backwards. If the LED is too dim regardless of the potentiometer setting, you can use a lower resistor in series with the LED. Or, perhaps you’re using a weaker output chip like the 74HC14, instead of the recommended 74AC14. Tsk. Tsk.
The potentiometer dial may not work the way you’re expecting, as turning it to the left will make the LED brighter, not dimmer. This is because the output of the first inverter logic gate is being inverted again by the second logic gate. That is, the output is the opposite of the original signal.
If you want, you can correct this by feeding the output of pin 4 into the input of pin 5 (and disconnect pin 5 from ground). This will invert the signal again, such that the output of pin 6 will match the polarity of pin 2. However, don’t use pin 2 directly, because attaching a load (the LED) will alter the charging and discharging of the capacitor.
One other option: Instead of using an extra logic gate, you can flip the LED and connect the anode to +5V instead of GND. Or, you can just ignore this.
Assuming you can now control the brightness of a single LED, you may be asking yourself why all this extra circuitry is worth it when you could just attach a single, standalone LED to a potentiometer to vary the brightness?
Well, you’re right. The single LED example is purely for diagnostic purposes. For the PWM to be worth the extra trouble, it should control varying loads, or heavier loads than a single potentiometer can handle.
Let’s start out with a schematic of a lame LED brightness-control circuit. You can try this circuit on a solderless breadboard, but don’t use it in real life because it doesn’t control the brightness very well.
Schematic of a potentiometer directly controlling the brightness of a 7-segment numeric LED display.
A seven-segment numeric LED can display numbers from 0 to 9, as well as some letters and symbols. Each individual LED segment has a current-limiting resistor to protect against going any brighter than the maximum rating (let’s say 20 mA).
The LED segments are controlled by some chip (a microcontroller or LED display chip) that can turn each LED on and off individually by applying 5V to the anode wires labeled 'a' through 'g'. For testing purposes, you can forgo the display chips and just plug wires from 5V to the resistors of the LEDs you want to turn on.
This is a common-cathode LED display. That means that all of the LEDs share the same ground (0V) wire.
All of this is good electrical engineering so far.
An electronics beginner has put a potentiometer on the cathode side to control the brightness. With the number '1' displayed on the LED (the two right-most LED segments are lit), the beginner adjusts the brightness to a satisfactory level.
Now comes the problem. The number '8' is then displayed, which lights all seven LED segments. The display is now much dimmer than before, because seven LEDs are now sharing the potentiometer resistance that was set for only two LEDs.
A single variable resistor does not work when the load changes (two LEDs to seven LEDs, or vice versa). Instead of trying to alter the resistance to change the brightness, let’s alter the “on time” versus “off time”.
Schematic of a pulse-width modulator (PWM) controlling the brightness of a 7-segment numeric LED display.
This circuit is mostly the same as the previous circuit. The difference is that the potentiometer has been replaced. The variable duty-cycle square wave from the PWM circuit is fed through a resistor (R3) into a transistor (Q3) and into the common cathode for all of the LEDs.
The transistor is the light switch. When the pulse wave is high, the transistor turns on the LEDs. When the pulse wave is low, the transistor turns off the LEDs.
Because the PWM is faster than the eye can detect (1 kHz in this example), the turning on and off (blinking) is not apparent. But, the overall “on time” versus “off time” changes the total light output of the LEDs over time, regardless of how few or how many LEDs are enabled. This is a digital change that affects all of the LEDs the same way (they’re either on or off).
Q3: A standard bipolar NPN transistor like the 2N3904 or 2N2222. The transistor is necessary because this display may use up to 140 mA (7 LEDs × 20 mA each) and the 74AC14 output pin can only supply 25 mA. You can swap in a more powerful transistor (Zetex 4 amp ZTX1047A) for much larger displays containing more LEDs.
R3: A 1 kilohm resistor. This current-limiting resistor doesn’t affect the brightness. It is only necessary to prevent too much current from flowing through the base of the transistor.
You now have a technique for adjusting the power delivered to a large load or a varying load (use a transistor and PWM). Hmm. A motor can be both a large load and a varying load. Let’s try that...