Controlling Two LEDs per uC pin

6a. Complications: Diodes Drop Different Voltages

Until now, I've just assumed that diodes will drop 0.6v, no matter what. In reality, the voltage dropped by a diode will depend upon the current flowing through it. Different types of diode will drop different amounts. In general, the more current flowing through a diode, the greater the voltage dropped.

To determine what sort of voltage drop we can expect, we'll therefore need to know what sort of current we're expecting;

Most normal LEDs can take 20mA. We will be lighting between 0 and 8 LEDs, hence the total current we can expect will be 0 to 160mA.

With that in mind, let's look at a few different diodes to see what the typical variation in voltage drop they give across this range of currents; (weasly caveat: don't use these figures anywhere as they're likely to be plain wrong.)

BAS16:(SOT23, high-speed switching diode)
BAV99:(SOT23, high-speed switching diode - dual package)
1N4148:(leaded signal diode)
1N4001:(leaded rectifier diode)

0.5mA 20mA 60mA 100mA 160mA
BAS16 0.45v 0.80v 0.88v 0.96 1.05v
BAV99 0.45v 0.75v 0.88v 0.95 1.10v
1N4148 0.58v 0.80v 0.88v 0.92 1.05v
1N4001 0.6v 0.65v 0.68v 0.70 0.82v

Table 5.1: voltage drop at various currents

Note: I've used a current of 0.5mA in the table, as obviously figures aren't available for 0mA.

This information brings a couple of problems to the fore:

  1. I've calculated the resistors to use based on a fixed 0.6v drop.
  2. The voltage drop tails off at very low currents.

6a.1 Recalculating for a dynamic voltage drop...

When reasonable currents are flowing (e.g. one LED is lit), the voltage drop over the diodes is larger than previously expected, hence the voltage across our current limiting resistor(s) will be lower, hence the current through the LED will be lower than calculated. e.g. we'll get less than the targetted 20mA. As more LEDs are turned on, a greater drop in voltage will be encountered, meaning that even less current will flow through each LED

e.g. When only one LED is on, it will be less bright than expected. When 8 LEDs are on they will be even dimmer still.

Will that matter?

Calculating the actual current expected (and hence voltage drop etc.) is tricky, because;

In other words, they are interrelated.

I think that I'm supposed to summon Mr Newton or Mr Raphson to help with balancing all the equations here, but that would need two things;

  1. a mathematical model of the diode's forward current vs voltage drop graph
  2. me to remember my A-Level maths.
Since I can do neither of these, I'm not going to attempt it.

Instead, I'm going to do some simple iterative calculations to verify that my choice of resistor and diodes are reasonable.

I'm going to be using BAS16 diodes and 68 ohm resistors.

Note: this resistor is much lower than the 95ohms calculated in section 5, but I have the benfit of hindsight - 68 ohms is actually a more useful value

When one LED is on, I'm assuming roughly 20mA as a start-point.

At 20mA, the BAS16 will drop 0.74v. That leads to a voltage of 5v-(2*0.74v)-1.9v = 1.62v across 68ohms which = 23.8mA

At 23.8mA, the BAS 16 will drop abount 0.75v. That leads to a voltage of 5v-(2*0.75v)-1.8v = 1.6v across 68ohms which = 23.5mA.

Further iterations will get the result to somewhere between these two figures. Let's say 23.7mA.

When 8 LEDs are on, I'll assume 160mA

At 160mA, the BAS16 will drop 0.95v. That leads to a voltage of 5v-(2*0.95)-1.9v = 1.2v across 68ohms which = 17.6mA per LED, or 141mA

At 141mA, the BAS16 will drop 0.94v. That leads to a voltage of 5v-(2*0.94)-1.9v = 1.22v across 68ohms which = 17.9mA per LED, or 143mA

Further iterations will, again, get the result to somewhere between these two figures.

This means that one LED will run at 23.8mA, and that 8 LEDs will run at 17.8mA each. That seems reasonable. I know that my LEDs are OK up to 30mA.

6a.2 When all the LEDs are (supposedly) off...

At very low currents, the voltage dropped by the diodes tails off markedly.

"Why is that a problem?"

If the voltage-droped from the diodes is too little, then the voltage across an LED pair may actually be enough to light them (even if it's with a very low current). In practice, this may only be a problem for high-efficiency LEDs, since they have a long tail at the bottom of their "Forward Current vs Forward Voltage" graphs. This means that at voltages well below their stated VF, they will still let some current through, and thus light the LED dimly.

Four diodes may not be enough to prevent a pair of high-efficiency LEDs from glowing.

Actually calculating wether LEDs will or won't work with this technique is tricky if you're just working from datasheets. They don't tend to give detail at the lower end of the "Forward Current vs Forward Voltage" graphs [I suspect that the standard-deviation down at these areas of the graph is quite wide, and that for most applications of the LEDs, the detail would be irrelevant]. It's a lot easier to just hook up a pair of LEDs and a few diodes and see if they glow.

If the LEDs still glow with 4 diodes, try 6!

6b. Complications: Diode Power Dissipation

When selecting diodes, you're going to have to consider the power they can handle...

I originally wanted to use the BAV99 diodes (a pair of diodes in a single SOT-23 package), but it turns out this might not be a good idea... Here's why;

At 160mA, each diode in a BAV99 will drop 1.1v.

Power = IV, so the power being dissipated will be 1.1v * 160mA = 176mW per diode.

That's 352mW in the dual-diode package. That's too close to the datasheet's maximums, so I've had to opt for the BAS16s instead...

A BAS16 will drop 1.05v at 160mA, leading to 168mW being dissipated. My BAS16 datasheet says it's good for 350mW, so I should be OK.