Driving LEDs and Optoisolator Inputs:


LEDs (Light Emitting Diodes) have improved by orders of magnitude in recent years. They are commonly availible in IR(infra-red), visible red, green, yellow, and just recently - blue. The most power efficient LEDs are generally the IR and visible red LEDs. These are also available in relatively high power configurations. The figure of merit for guaging the "brightness" of an LED is by its "millicandle" rating. Early LEDs were typically 5 or 10 millicandles, whereas "high brightness" red LEDs with 2000+ millicandle ratings are currently available at Radio Shack. The electrical parameters of interest include the forward voltage drop of the LED (typically 1.7V for red LEDs), and the maximum forward current, which typically ranges from ILED =5mA to as much as 50mA, with 20mA being a common rating. If you want your LEDs to last, derate them! I.e. never drive the LED at more than about 2/3 of its "maximum" ILED rating!

The figure below shows typical drive circuits for LEDs. Remember, when using an optoisolator, you are also driving an LED!
Typical LED Drive Circuits
Typical LED Drive Circuits

Example (a) shows the method commonly used in the past by TTU EE students for driving an LED. Although it will work OK for low-current LEDs, I have heard reports that this method has "led"(no pun intended) to students damaging their 68HC1x output ports by requiring the outputs to sink too much current (leading to eventual thermo-nuclear damage - i.e. burning out of the port output transistors).
Example (b) shows an incremental improvement, that allows the current load to be shared by a pair of port pins. To turn the LED on, you write 0 to both port pins, and to turn the LED off, you write 1 to both port pins. This does tend to hog the few port pins availible on a 68HC11, but if you're using a 68HC12, you have ports to burn!(No pun intended).
Example (c) shows the safest way to drive an LED, by letting a 2N2222 or 2N3904 NPN transistor do all the work (although it requires more wiring). These transistors can easily handle, say, up to 60mA of current.
In all cases, a current limiting resistor should always be placed in series with the LED. Have the spec's available for your LED or optoisolator. Then choose:

ILED(actual) <= (2/3)xILED(max).

Then find the forward voltage across the LED, VLED (typically 1.7V).
The basically use Ohm's law to find the value for Rs, the series resistor as:

Rs = [Vcc - VLED]/ILED(actual).

For example, if Vcc= +5V, and ILED(max)=20mA, and VLED = 1.7V, then maybe choose ILED(actual) = 13mA, so that:

Rs = [5V - 1.7V]/13mA = 254 ohms.

Finally round this resistance to the nearest "standard" value (e.g. 220 ohms).


These calculations have neglected the fact that VOL for a 68HC1x output is probably going to be more like 0.2V, as opposed to 0V etc.. If you want to be a purist, you can also account for, say, VCEsat ~ 0.2V and whatnot, but the above equations are more than accurate enough for most applications. A concientious designer would later go in and measure the actual LED current, e.g. by measuring the voltage drop across Rs and using Ohm's law to find ILED.

Back to Home Page