I’m working on a control system for my stereo, with more information on that project to be posted soon. I was running into a problem having enough pins on my PIC to connect all the inputs, pushbuttons, LEDs, and outputs.
Yesterday I was talking to Tom and describing how each bicolor output LED requires two microcontroller pins to control both colors. I’m sure this scheme has been used a million times before, and I may even have seen it before, but I was very pleased to realize in a flash of insight how to drive a bicolor LED from a single output pin.
Instead of connecting the LED between the control pin and V+ or ground, connect it to a voltage divider between the two. Raise the control voltage to V+ and the green LED will conduct through R2. Lower the control voltage to 0V and the red LED will conduct through R1. Here’s the best part — change the control pin to an input and it’ll go into a tristate (high-impedance) mode, leaving the left end of the bicolor LED floating, with both elements off. Perfect! That saves my project!
I breadboarded this circuit with 330Ω resistors, and the LED was quite a bit dimmer than normal. Well, of course it was; it’s running off less voltage than usual. Plus the voltage divider isn’t exactly a stiff current source. But I was curious exactly how much less voltage (seems obvious, but wouldn’t it be nice to know for sure?), and what was the exact series resistance (ah, somewhat less obvious, eh?).
Thévenin Analysis
Thévenin’s Theorem states that any linear circuit (comprising only voltage sources and resistors) can be represented as a single voltage source and a single series resistor, and provides a very simple method to determine the equivalent voltage and resistance. So a Thévenin analysis of the voltage divider will give us a simpler model of that section of the circuit, which can then be used to determine the actual LED current.
First, to determine the Thévenin voltage (VTH), mentally remove the load from the circuit and use Kirchhoff’s Law to find the voltage at the load connection.
In this case, assuming R1 = R2, VTH is V+ / 2.
Next, to determine the Thévenin resistance (RTH), (mentally) short out all the voltage sources and use Kirchhoff to find the overall resistance looking into the circuit.
In this case, mentally shorting V+ to ground puts R1 and R2 in parallel, giving
RTH = (R1 * R2) / (R1 + R2)
Or again in the case where R1 = R2,
RTH = R2 / 2R = R / 2
Thévenin Equivalent Circuit
So assuming R1 = R2, the voltage divider is equivalent to a voltage source of V+ / 2 in series with a resistance of R / 2, which gives this simplified circuit:
This makes it easy to determine the LED current (ID). Whether the control voltage is at V+ or 0V, the LED and Thévenin resistor will see a voltage of V+ / 2 (forward or reverse).
Using the zeroeth approximation of a diode as a device that conducts electricity in a forward direction with no voltage drop, the resistor has the full voltage across it, so the resistor current
IR = (V+ / 2) / (R / 2) = V / R
and ID = IR. For a 5V supply and 330Ω resistors, I = 5V / 330Ω ≈ 15mA.
But that’s exactly the same current (and concomitant LED brightness) we’d expect running an LED from a full V+ with a full R, and I distinctly noted that the LED was dimmer. What’s going on?
LED Voltage Drop
The answer lies in the first approximation of an LED as a device that conducts electricity in the forward direction with a voltage drop and no resistance. The bicolor LED I was using has about a 2V drop in either direction (about 2.08V green and 1.95V red, at the temperature and moment I measured).
Still using a 5V supply and 330Ω resistors, an LED voltage drop VD = 2V gives a voltage across the resistor of
VR = (V / 2) – 2V = 2.5V – 2V = .5V
IR = VR / RTH = .5V / 165Ω ≈ 3mA
ID = IR ≈ 3mA
Whoa! That’s a whole different story! Halving the effective supply voltage dramatically exaggerates the effect of the LED’s voltage drop.
In fact, to get back up to ID = 15mA:
RTH = VR / IR = .5V / 15mA &symp; 33Ω
That’s an order of magnitude lower current-limiting resistance to get the same LED current and brightness.
Even worse, note that this circuit (the original) has a continual current of V+ / 2R through the voltage divider. With 330Ω resistors, that’s 7.6mA (38mW), which may be tolerable in a non-battery-driven circuit; but with 33Ω resistors, that’s an unacceptable 76mA (380mW) per LED driver!
Tolerable Adaptations
So how can we make this circuit work well enough to be practical? Here are a couple of options.
First, note that the current-limiting resistance needed to be made so low because half the supply voltage is barely more than the diode’s voltage drop. With a higher supply voltage, more voltage would be “left” after taking out the LED’s drop, and a higher resistance could be used to get the same LED current.
But how far can we raise the supply voltage? For the circuit to work properly, the control voltage from the microcontroller needs to swing over the same range as the LED’s voltage divider. And alas, the PIC I’m using has a maximum VDD of 7.5V; or say a safe working voltage of 7V.
Adding 2V to V+ adds only 1V to the LED/resistor supply, increasing VR from .5V to 1.5V, or threefold. That translates into three times larger resistance and one third the voltage-divider power consumption — progress, but not as much as I’d like.
Second, note that the bicolor LED I’m using is not particularly high performance. Newer LEDs appear to me to be several orders of magnitude brighter at the same current. (Go check the amazing mCd claims of LED vendors on eBay. For the most part, they’re increasing efficiency, not current-handling capacity.) I’d gladly pay a little more for a much brighter LED that has lower current requirements for the same brightness.
Even one order of magnitude difference in LED efficiency pushes the voltage divider power consumption back into an acceptable level for the device I’m designing. It also cuts the power requirements for the PIC pin driving the LED. The datasheet quotes 25mA source or sink per pin, 200mA source or sink for all pins, but I’m old-fashioned and don’t want to push my luck.
One thing I don’t know is whether high-efficiency LEDs have the same voltage drop as traditional ones. With only 2.5V available for the LED, if higher efficiency comes at the expense of a higher voltage drop, I could “efficient” the circuit right out of its operating range.
Boosting the Drive Current
Before doing the actual calculations, I was pondering whether the PIC could really source and sink enough current to power all my LEDs as brightly as I want. I was musing out loud with Tom about how to build a transistor driver to buffer/boost the PIC’s output.
The driver needs to be a totem pole, meaning that it has two stacked elements so it can source the LED line up to V+ or sink it down to ground. The catch is the tristate trick that makes it possible to turn the bicolor LED off. Trying to cram a traditional complementary totem-pole output into this circuit IS WRONG AND DOESN’T WORK.
When the control line is high, the upper (PNP) transistor is off and the lower (NPN) is on, so the NPN pulls the driver output low. Likewise, a low control line pulls the driver output high.
The problem is when the control line is tristated. Then current flows through the PNP’s emitter and base to the NPN’s base and emitter, turning both transistors on and shorting V+ to ground. Real totem-pole drivers are designed to make sure this can never happen, even during transitions.
Here’s Tom’s solution, which like the tristate trick is probably a reinvention, but which is so clever that it still tickles me a day later to think about it.
Just swap the NPN and PNP transistors in the totem pole, putting the NPN on top and the PNP on the bottom. When the control line goes high, the upper (NPN) transistor is on and the lower (PNP) off, so the NPN pulls the driver output high. Likewise, a low control line pulls the driver output low.
And a tristated control line leaves both transistors off and the driver output in a high-impedance state, because the emitters aren’t connected to the power rails to conduct through the bases any more.
Brilliant! Makes me want to use it, even though I realize with high-efficiency LEDs I no longer have any technical reason to. But I’ll keep it in my bag of tricks.