Happy Halloween! Last year I built a collection of plywood pumpkins to stick in the yard on Halloween night. I installed superbright LED's in the eyes, nose, mouth, etc and was pretty pleased with the results. This year I want to animate the LED's. I bought a DLP-245PL which uses a PIC18LF8720 to drive it's digital I/O. I need a simple transistor circuit to drive each LED. There's about 22 of them. Typical LED voltage is 2.1V to 3.4V, current ranges from 20mA to 30mA. Last year I was driving the LED's from a simple 12V DC power supply. Their cathodes are connected together and to ground. The anodes connected to appropriate resistors. For the life of me, I can't remember the equations appropriate for switching transistors. It seems like optoisolators are a bit of overkill. Things I'm worried about are the base resistor and transistor selection, and the possibility of sending 12V into the TTL outputs of the PIC. It would be nice to reuse the transistors I have on hand, which are: 2n2222a, tip34, 2n3906. chuck
PIC18 transistor LED drivers
Started by ●October 20, 2004
Reply by ●October 20, 20042004-10-20
On 20 Oct 2004 12:18:52 -0700, the renowned csembro@yahoo.com (Chuck) wrote:>Happy Halloween! > >Last year I built a collection of plywood pumpkins to stick in the >yard on Halloween night. I installed superbright LED's in the eyes, >nose, mouth, etc and was pretty pleased with the results. This year I >want to animate the LED's. > >I bought a DLP-245PL which uses a PIC18LF8720 to drive it's digital >I/O. I need a simple transistor circuit to drive each LED. There's >about 22 of them. Typical LED voltage is 2.1V to 3.4V, current ranges >from 20mA to 30mA. > >Last year I was driving the LED's from a simple 12V DC power supply. >Their cathodes are connected together and to ground. The anodes >connected to appropriate resistors. For the life of me, I can't >remember the equations appropriate for switching transistors. > >It seems like optoisolators are a bit of overkill. Things I'm worried >about are the base resistor and transistor selection, and the >possibility of sending 12V into the TTL outputs of the PIC. It would >be nice to reuse the transistors I have on hand, which are: 2n2222a, >tip34, 2n3906. > >chuckx------[Rx]----|<|---- +12 (12V) | \\\ | LED | B |/C -----[2K7]-------| |\E 2N2222A, 2N4401 etc. | | 0V (5V) -----------x----------------------- 0V (12V) Only tie the 12V supply ground to the 5V supply ground at one point. (Do not allow the LED current to flow through the 5V ground circuit). If you're using 30mA maximum, then a forced beta of 20 would imply a base current of 1.5mA, so 2.7K is about right. To calculate Rx, you need to know the LED forward voltage Vf. If you're not sure, use 2.5 for yellow or green LEDs, 3V for white or blue, and 2.0 for red. Then Rx = (12V - Vf)/Iled Eg. if the Iled is 20mA and the Vf is 3.0V, the equation gives 450 ohms, so round it up to 470R as the closest standard value. The power disipation is I^2*R = 0.188W, so a 1/4W resistor will suffice for this kind of application. Alternately, replace the 2K7s and transistors with ULN2003A/ULN2803 parts to drive 7 or 8 LEDs with one chip. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
Reply by ●October 20, 20042004-10-20
On 20 Oct 2004 12:18:52 -0700, csembro@yahoo.com (Chuck) wrote:>Last year I built a collection of plywood pumpkins to stick in the >yard on Halloween night. I installed superbright LED's in the eyes, >nose, mouth, etc and was pretty pleased with the results. This year I >want to animate the LED's. > >I bought a DLP-245PL which uses a PIC18LF8720 to drive it's digital >I/O. I need a simple transistor circuit to drive each LED. There's >about 22 of them. Typical LED voltage is 2.1V to 3.4V, current ranges >from 20mA to 30mA. > >Last year I was driving the LED's from a simple 12V DC power supply. >Their cathodes are connected together and to ground. The anodes >connected to appropriate resistors. For the life of me, I can't >remember the equations appropriate for switching transistors. > >It seems like optoisolators are a bit of overkill. Things I'm worried >about are the base resistor and transistor selection, and the >possibility of sending 12V into the TTL outputs of the PIC. It would >be nice to reuse the transistors I have on hand, which are: 2n2222a, >tip34, 2n3906.Hi, Chuck. I very much like Spehro's recommendations. But I tend to prefer a slightly different transistor topology than he recommended. +12 | --- ~ LED1 \ / ~ --- | | micro |/c Q1 pin >-----| 2N2222 or |>e 2N3906 | \ / R1 \ | gnd There are several reasons, but the main one is that since the emitter follows the base which is itself nailed to the micro output pin, the current through LED1 can be set precisely and independent of the +12V supply's variations. Here, R1 is simply [(Vcc - 0.6V)/I_led]. Let the BJT do the work of figuring out how to deal with changes in the +12V, though later tinkering choice or otherwise. Since you are really into 'animating' you might also consider doing some muxing to reduce the total count of transistors, but using some PNPs, as well. You can get "steady", "blinking", "dimming", etc. out of all that. Jon
Reply by ●October 20, 20042004-10-20
On Wed, 20 Oct 2004 21:19:13 GMT, the renowned Jonathan Kirwan <jkirwan@easystreet.com> wrote:>On 20 Oct 2004 12:18:52 -0700, csembro@yahoo.com (Chuck) wrote: > >>Last year I built a collection of plywood pumpkins to stick in the >>yard on Halloween night. I installed superbright LED's in the eyes, >>nose, mouth, etc and was pretty pleased with the results. This year I >>want to animate the LED's. >> >>I bought a DLP-245PL which uses a PIC18LF8720 to drive it's digital >>I/O. I need a simple transistor circuit to drive each LED. There's >>about 22 of them. Typical LED voltage is 2.1V to 3.4V, current ranges >>from 20mA to 30mA. >> >>Last year I was driving the LED's from a simple 12V DC power supply. >>Their cathodes are connected together and to ground. The anodes >>connected to appropriate resistors. For the life of me, I can't >>remember the equations appropriate for switching transistors. >> >>It seems like optoisolators are a bit of overkill. Things I'm worried >>about are the base resistor and transistor selection, and the >>possibility of sending 12V into the TTL outputs of the PIC. It would >>be nice to reuse the transistors I have on hand, which are: 2n2222a, >>tip34, 2n3906. > >Hi, Chuck. I very much like Spehro's recommendations. But I tend to prefer a >slightly different transistor topology than he recommended. > > +12 > | > --- ~ > LED1 \ / ~ > --- > | > | > micro |/c Q1 > pin >-----| 2N2222 or > |>e 2N3906 > | > \ > / R1 > \ > | > gnd > >There are several reasons, but the main one is that since the emitter follows >the base which is itself nailed to the micro output pin, the current through >LED1 can be set precisely and independent of the +12V supply's variations. >Here, R1 is simply [(Vcc - 0.6V)/I_led]. Let the BJT do the work of figuring >out how to deal with changes in the +12V, though later tinkering choice or >otherwise. > >Since you are really into 'animating' you might also consider doing some muxing >to reduce the total count of transistors, but using some PNPs, as well. You can >get "steady", "blinking", "dimming", etc. out of all that. > >JonThis method will generally work fine and has the advantages Jon lists. Three possible issues. 1) The trasistor will get warm. This isn't a serious issue with the suggested parts and in this application. 2) It's possible for the transistor to oscillate at high frequency, depending on layout. 3) If the transistor fails or is inserted incorrectly, 12V gets back into the micro and destroys it. You can avoid this risk (and any possible oscillation) with a small series base resistor, yet retain the advantage of a constant current source. Note that with Jon's circuit you can put a couple of LEDs in series without changing R1. You might be able to use more LEDs in series with my circuit but the resistor will have to be lower. Best regards, Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
Reply by ●October 21, 20042004-10-21
On Wed, 20 Oct 2004 18:07:46 -0400, Spehro Pefhany <speffSNIP@interlogDOTyou.knowwhat> wrote:>1) The trasistor will get warm. This isn't a serious issue with > the suggested parts and in this application.Yes, that's letting the transistor "do the work" of picking up the remaining voltage headroom. But that power (the voltage the LED doesn't need times the LED current) has to go somewhere. Since I tend to want my LED V+ supply to be whatever wall-wart I can find handy at the moment, I'd rather arrange it this way than have to go re-soldering new resistors.>2) It's possible for the transistor to oscillate at high > frequency, depending on layout.Oh, hadn't thought about that. With PIC outputs being about 70-120 ohms or so drive-wise, the base side of Cbc and Cbe aren't quite as "nailed" as I might imagine and I can see the ability for some oscillation. But I think the CJC for the 2n3906 is 4pF and the CJE is 8pF, so it would take something in the many tens (to hundreds) of MHz, wouldn't it? Or is that what you were thinking? I'd be interested to hear more on this.>3) If the transistor fails or is inserted incorrectly, 12V gets > back into the micro and destroys it. You can avoid this risk > (and any possible oscillation) with a small series base > resistor, yet retain the advantage of a constant current > source.But at the expense of reducing the frequency of oscillation you just talked about?>Note that with Jon's circuit you can put a couple of LEDs in series >without changing R1. You might be able to use more LEDs in series with >my circuit but the resistor will have to be lower.That's a nice additional point. As long as there is enough headroom, using the circuit I mentioned provides a consistent current regardless of the number of LEDs. Jon
Reply by ●October 21, 20042004-10-21
On Thu, 21 Oct 2004 07:46:55 GMT, the renowned Jonathan Kirwan <jkirwan@easystreet.com> wrote:>Oh, hadn't thought about that. With PIC outputs being about 70-120 ohms or so >drive-wise,Dynamic impedance is < 50 ohms typically with 5V Vdd. Newer chips tend to have better drive. It's the slope of the output voltage vs. output current curve on a "high" output (near Vdd).> the base side of Cbc and Cbe aren't quite as "nailed" as I might >imagine and I can see the ability for some oscillation. But I think the CJC for >the 2n3906 is 4pF and the CJE is 8pF, so it would take something in the many >tens (to hundreds) of MHz, wouldn't it? > >Or is that what you were thinking? I'd be interested to hear more on this.It's caused by parasitic inductance in the base (for example from long wires) and parasitic capacitance across the emitter resistor. The inductance causes a negative real impedance looking into the emitter, which can cause oscillation over some range of conditions.>>3) If the transistor fails or is inserted incorrectly, 12V gets >> back into the micro and destroys it. You can avoid this risk >> (and any possible oscillation) with a small series base >> resistor, yet retain the advantage of a constant current >> source. > >But at the expense of reducing the frequency of oscillation you just talked >about?It gets rid of it entirely. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
Reply by ●October 21, 20042004-10-21
On Thu, 21 Oct 2004 09:18:45 -0400, Spehro Pefhany <speffSNIP@interlogDOTyou.knowwhat> wrote:>On Thu, 21 Oct 2004 07:46:55 GMT, the renowned Jonathan Kirwan ><jkirwan@easystreet.com> wrote: > > >>Oh, hadn't thought about that. With PIC outputs being about 70-120 ohms or so >>drive-wise, > >Dynamic impedance is < 50 ohms typically with 5V Vdd. Newer chips tend >to have better drive. It's the slope of the output voltage vs. output >current curve on a "high" output (near Vdd). > >> the base side of Cbc and Cbe aren't quite as "nailed" as I might >>imagine and I can see the ability for some oscillation. But I think the CJC for >>the 2n3906 is 4pF and the CJE is 8pF, so it would take something in the many >>tens (to hundreds) of MHz, wouldn't it? >> >>Or is that what you were thinking? I'd be interested to hear more on this. > >It's caused by parasitic inductance in the base (for example from long >wires) and parasitic capacitance across the emitter resistor. The >inductance causes a negative real impedance looking into the emitter, >which can cause oscillation over some range of conditions. > >>>3) If the transistor fails or is inserted incorrectly, 12V gets >>> back into the micro and destroys it. You can avoid this risk >>> (and any possible oscillation) with a small series base >>> resistor, yet retain the advantage of a constant current >>> source. >> >>But at the expense of reducing the frequency of oscillation you just talked >>about? > >It gets rid of it entirely.Thanks, much. I need to set down and work through the details, myself, now. Appreciated! Jon
Reply by ●October 22, 20042004-10-22
On Thu, 21 Oct 2004 09:18:45 -0400, Spehro Pefhany <speffSNIP@interlogDOTyou.knowwhat> wrote:>It's caused by parasitic inductance in the base (for example from long >wires) and parasitic capacitance across the emitter resistor. The >inductance causes a negative real impedance looking into the emitter, >which can cause oscillation over some range of conditions.Got it! Thanks. Jon
Reply by ●October 22, 20042004-10-22
On Thu, 21 Oct 2004 09:18:45 -0400, Spehro Pefhany <speffSNIP@interlogDOTyou.knowwhat> wrote:>It's caused by parasitic inductance in the base (for example from long >wires) and parasitic capacitance across the emitter resistor. The >inductance causes a negative real impedance looking into the emitter, >which can cause oscillation over some range of conditions.I know the exact equations are a little different here, but let me try to put this into grossly simplified dynamic considerations that ignore the precise quantities: Looking at the 0V to 1.5V rising edge case, the inductance of long wires to the base (I've found figures like 10 nH/cm) would limit the rate of current change to (V2-v1)/L (V2 being the pin drive voltage and V1 at the base initially held to zero by the BJT capacitance.) This rising current is needed charge/discharge the base-emitter and base-collector capacitances, before the transistor can respond accurately. (For simplification, I'll just say that the transistor remains "OFF" until these capacitors are charged, rather than worry about the exact details.) At this point, the BJT goes into the normal region and operates, driving the collector rapidly down in voltage. This is coupled via newly recharged base-collector capacitor back to the base, which now drives downwards, shutting the BJT off again until the new (V/L) can again recharge the BJT capacitor pair. Etc. This will be a damped oscillation on this rising edge, an RLC thing, with the R being R1||R2 and the C being CJC+CJE? Roughly speaking, is this about it? And if so, I'd expect a different behavior on the falling edge case. Also, one could add a diode in parallel to the emitter resistor so that the downward driven CJE of the BJT could discharge somewhat more rapidly, at first, through that diode rather than just through the emitter resistor? (Not that this would impact things that much and it would just add another diode capacitance across that resistor, with probably bad effect.) Oh, well. Let me know if and how I'm off the beam, here. Thanks, Jon
Reply by ●October 22, 20042004-10-22
On Fri, 22 Oct 2004 19:39:45 GMT, the renowned Jonathan Kirwan <jkirwan@easystreet.com> wrote:>On Thu, 21 Oct 2004 09:18:45 -0400, Spehro Pefhany ><speffSNIP@interlogDOTyou.knowwhat> wrote: > >>It's caused by parasitic inductance in the base (for example from long >>wires) and parasitic capacitance across the emitter resistor. The >>inductance causes a negative real impedance looking into the emitter, >>which can cause oscillation over some range of conditions. > >I know the exact equations are a little different here, but let me try to put >this into grossly simplified dynamic considerations that ignore the precise >quantities: > >Looking at the 0V to 1.5V rising edge case, the inductance of long wires to the >base (I've found figures like 10 nH/cm) would limit the rate of current change >to (V2-v1)/L (V2 being the pin drive voltage and V1 at the base initially held >to zero by the BJT capacitance.) This rising current is needed charge/discharge >the base-emitter and base-collector capacitances, before the transistor can >respond accurately. (For simplification, I'll just say that the transistor >remains "OFF" until these capacitors are charged, rather than worry about the >exact details.) At this point, the BJT goes into the normal region and >operates, driving the collector rapidly down in voltage. This is coupled via >newly recharged base-collector capacitor back to the base, which now drives >downwards, shutting the BJT off again until the new (V/L) can again recharge the >BJT capacitor pair. Etc. This will be a damped oscillation on this rising >edge, an RLC thing, with the R being R1||R2 and the C being CJC+CJE?Not necessarily damped. Gory details: http://home.tiscali.be/kpmoerman/electronics/notes/efollow/efollow.htm>Roughly speaking, is this about it? And if so, I'd expect a different behavior >on the falling edge case.The bias is different when the output is low, so it's a bit harder for it to oscillate. Here's a simulation I did using a 2N4401: www.speff.com/emitter_follower.pdf With a lot more capacitance across the 180R it will oscillate continously, once started, even if the input goes low. In practical terms this may be an okay configuration for the purpose intended if layout etc. is good enough, but with a lash-up, maybe not. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com