# LM317 LED driver with varying DC input

#### Shakin97

Joined Nov 17, 2011
2
Hello,
I have a question regarding using the LM317AT in CC mode to drive an 3x3 array of 9 3.3V, Iavg = 25mA SMT LED's. I have seen many on this forum that would work if the input DC is a constant. My question is how to wire up a LM317AT circuit on a boat to replace my incandescent light fixtures. The problem is when I am running the engine and the battery is charging it can be as high as 14Vdc, but a battery may be as low as 12V. I would like to keep the same amount of current in each leg regardless if the battery(supply) is at 12V or 14V.
Any ideas greatly appreciated.

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,230
The LM317 is certainly easy to use, but in CC mode, it's not very efficient. It has a ~1.7v nominal dropout when used in voltage mode, and CC mode is another ~1.25v, for a total of nearly 3v lost across the regulator.

So, if you want to plan for worst case scenario, and if you really like buying batteries, 11v-3v=8v left for a series string. 8v/3.3v=2.424... LEDs - of course you have to take the integer of that, so it's 2 LEDs per string. So, ~6.6v for the load, and when the battery is being charged, 14v - 6.6v = 7.4v for the regulator. 47% efficiency is pretty rotten.

By the way, if you let your battery fall below 12v, you are cutting its' life very short.

I'm afraid I don't have time at the moment to give you a better solution; but it would involve a boost-type switching regulator, and would be far more efficient. However, I don't know how many of these things you want to build.

#### Shakin97

Joined Nov 17, 2011
2
Playing around with LTSpice, I think I've figured out a way to drive the 9 LED's just using some diodes for biasing and 3 2N3904 generic transistors which will have to be SMT. This is while having 11.5Vdc to 14.5Vdc which by my best estimate is the extreme given my conditions.
I am varying re from 25 to 47 Ohms so I have either 15mA or 25mA per leg. Kinda like a set dimmer... Maybe call it mood lighting...

#### Attachments

• 122.7 KB Views: 163

#### Wendy

Joined Mar 24, 2008
23,457
That looks like it is loosly based off my drawings. You can put a variable pot across the diodes, and vary them that way.

#### bountyhunter

Joined Sep 7, 2009
2,512
Hello,
I have a question regarding using the LM317AT in CC mode to drive an 3x3 array of 9 3.3V, Iavg = 25mA SMT LED's. I have seen many on this forum that would work if the input DC is a constant. My question is how to wire up a LM317AT circuit on a boat to replace my incandescent light fixtures. The problem is when I am running the engine and the battery is charging it can be as high as 14Vdc, but a battery may be as low as 12V. I would like to keep the same amount of current in each leg regardless if the battery(supply) is at 12V or 14V.
Any ideas greatly appreciated.
If it is 25 mA per string, 75 mA total. If each LED is 3.3V, that's about 10V per string. At 14V in, the power loss in the LM317 is 0.3W, which the "T" (TO-220) package can handle easily without any heatsink. The current will be constant as long as the input voltage stays high enough (about 13V). Below that it will taper off.

You could also rig up a simple current mirror using a power transistor PNP like 2N6124 to drive the LEDs mirrored off against a small PNP (like 2N3906) connected as diode with resistor to ground to set it's current. Connect both emitters to V+ and tie both bases together. Then use emitter resistors ratioed to multiply the current on the power transistor side to 75 mA. That would get you a lower dropout voltage so it would regulate down to 12V input.

http://www2.engr.arizona.edu/~brew/ece304spr07/Pdf/PNP current Mirror.pdf

http://www.engin.brown.edu/courses/en162/Mirrors08.pdf

Last edited:

#### SgtWookie

Joined Jul 17, 2007
22,230
Try changing your resistors to 36 Ohms. Right now you'll have ~14mA through the LEDs. 36 will get you closer to 20 without going over.

.step temp 0 40 10
...as a spice parameter to see how it'll do over temp. You should see from ~17.4mA at low voltage @ 40°C to ~19.9mA @ 0°C.

You can also flip the whole thing upside-down by using PNP 2N3906 transistors as sourcing current to the anodes rather than sinking current from the cathodes.

#### Attachments

• 136.4 KB Views: 126
• 2.8 KB Views: 66

#### bountyhunter

Joined Sep 7, 2009
2,512
Try changing your resistors to 36 Ohms. Right now you'll have ~14mA through the LEDs. 36 will get you closer to 20 without going over.

.step temp 0 40 10
...as a spice parameter to see how it'll do over temp. You should see from ~17.4mA at low voltage @ 40°C to ~19.9mA @ 0°C.

You can also flip the whole thing upside-down by using PNP 2N3906 transistors as sourcing current to the anodes rather than sinking current from the cathodes.

Considering the 2N3906 only costs about a dime, I would replace the two 1N94148 diodes with a diode connected 2N3906 (and an emitter resistor) and make it a true current mirror so it will give constant current over temperature changes. You can tweak the value of the emitter resistor to adjust the current in the LEDs.

#### Wendy

Joined Mar 24, 2008
23,457
Current mirrors do not work well outside an IC. This is due to extreme temperature instablility, and they can easily run away. I show this on my albums, but I also mention that they are not a good idea.

..

I tend to favor the transistor emitter constant current source because of the low dropouts. Here is a LED grow light I helped develop a long while back...

Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Current mirrors do not work well outside an IC. This is due to extreme temperature instablility, and they can easily run away.
No, that is completely wrong if an emitter resistor is used since it provides emitter degeneration that both balances and opposes thermal runaway. I have used them in dozens of applications including adjustable battery chargers where the charge current can vary over a wide range by selecting the emitter resistor.

The only current mirrors that only work in an IC are ones that require exact matching, ie have no negative resistive degenration in the emitter.

What I don't recommend is designs where discrete diodes like 1N4148 are "paired" against transistor junctions since they are WAY off and certainly don't match worth beans. That design "matches" a diode against a resistor and that will have a terrible TC.

#### Attachments

• 9.2 KB Views: 85

#### Wendy

Joined Mar 24, 2008
23,457
Then it is not a current mirror. See the illustrations I've just put up. Current mirrors are a specific type of circuit. What you show is a standard transistor constant current source.

The illustration I show is the most basic type of current mirror, there are many other configurations. Far as I know, all of them suffer the same temperature instability problems. The reason it isn't a problem on an IC is the thermal coupling on a chip is very tight.

Everything on the 300W LED grow light schematic needs heat sinks. Switching mode power supplies are better, but much more complex.

Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Then it is not a current mirror. See the illustrations I've just put up. Current mirrors are a specific type of circuit. What you show is a standard transistor constant current source.
The circuit I showed is the example of what NOT to do. The current mirror I recommended was using a diode connected 2N3906 transistor to set the bias current and the three other 2N3906 transistors to feed the LED strings. Emitter resistors are selected to adjust the current in the LED strings to desired value. The ratio of the resistors multiplies the current. A current mirror does not have to be a 1:1 mirror: in fact, most are not. However, inside IC's we adjust the current ratios by emitter areas. In discrete designs we adjust the ratios with emitter resistors.

#### Wendy

Joined Mar 24, 2008
23,457
Have you tried your current mirrors? I don't think they will work as well as you think they well, as they now have features that will interfer with the basic theory of operation of a current mirror, namely the emitter resistors.

Fact is, they will still be thermally sensitive, it is in the nature of how a current mirror works. Current mirrors lean heavily on the BJT being used in it's voltage controlled mode as opposed to a current controlled mode (the traditional Ic=ß Ib). As long as the two transistors mirror each other (that includes temperature) then it works very well. A small change in basic operating paremeters causes major instabilities. If the transistors are operating in two different areas of their current curves they won't be very mirrored either.

A common collector current source is pretty stable, I have verified this experimentally.

I've never seen your variations, nor heard how well they work. It will be something I will have to research and build.

Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Have you tried your current mirrors? I don't think they will work as well as you think they well
Many dozens of times, a number of them are working even now (battery chargers with selectable charge current rates). I'ts late now, so I'll just post the design assuming the OP wants the best solution. It has approximatey 500 mV of degeneration so it will compensate for even gross mismatches of VBE and temps with minor variation in current across the LEDs. The emitter resistors may have to be tweaked slightly to hit 25 mA precisely but with LEds, but a slight current variation is not visible.

#### Attachments

• 33.1 KB Views: 85
Last edited:

#### Wendy

Joined Mar 24, 2008
23,457
Don't think that will work. Where is the bias to turn the base current on for Q1 (the first transistor)?

All you will have from this is a bunch of dark LEDs, no current. If you short the BC on Q1 it will not be a current mirror, just a fancy diode/resistor circuit with a bunch of emitter followers.

If you insist I will be glad to build a version with Q1 and Q2, and report the results.

#### Attachments

• 14.6 KB Views: 366
Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Fixed the typo in the schematic. It's late here. I drew it in five minutes.

#### Wendy

Joined Mar 24, 2008
23,457
Again, that is not a current mirror. I could get identical results by simply substituting Q1 with a conventional diode.

You have a voltage divider with a transistor wired as a diode. The rest is just voltage followers.

The basic theory of operation is missing, that being setting a current by precision voltage across the BE junction. Transistors do not usually use that mode, but with a current mirrors they do. It is also why they are unstable with temperature, the transistors being close to identical is critical.

The circuits drawn using the diodes have one overwhelming difference, they are true constant current sources. You can vary the power supply voltage and the current through the LEDs will not vary.

Plus, the parts count is smaller.

***********************

OK, parts count is not smaller, but it is simpler selection of parts that ends up being a better , more stable design.

The only reason you would want a constant current source is unstable power supply voltage, otherwise a simple resistor would work as well. The other reason is making a variable current with one control for many LEDs.

If you would like to pick up a discussion of current mirrors I would be glad to start another thread on the subject.

***********************

After doing a bit of research you were right, and I was wrong, that is a current mirror.

My statement of replacing the first transistor with a diode is true enough, as is the fact that it is entirely dependent on the power supply, which renders it mostly useless for a LED current source.

Doing a bit of studying the concept of a current mirror is much looser than I had previously thought. For it to be a true constant current source you need to regulate the voltage of the Q1 side, then the current would be independent of the power supply voltage. The circuit is incomplete without voltage regulation.

Which brings up the fact that the circuit I show is very similar to yours, but has fewer parts since the voltage regulation is incorporated into the diodes. It is the best circuit for this kind of job.

You could even get rid of the second diode on the second example, and it would work.

There is another reason I like this design, and that is with very little modification it will vary the intensity 100%, from completely off to 100%, something a current mirror would have trouble doing. PWM is linear, this is not, but it would work.

#### Attachments

• 4.7 KB Views: 328
• 4.5 KB Views: 327
Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Again, that is not a current mirror.
Yes, it's just not a 1:1 mirror. It's a 1:2.5 mirror. The mirror is because changes in the diode string are mirrored in the LED strings.

Again, that is not a current mirror. I could get identical results by simply substituting Q1 with a conventional diode.
No, that's wrong. The left PNP is the same device as the others which means it's VBE is nearly the same and behaves the same with respect to varying current and temp. If you drop 1N4148 in there it will not match or track the other VBEs and it sure won't track a resistor. The top design in your post shows two diodes: one corresponds to the transistor P-N junction and the other's voltage is forced across the 36 Ohm resistor. So, the current is the VBE/36 which means it has the diode's tempco..

The circuit I posted works. Simulate it or build it, it works perfectly and will track well over temp. I never claimed it had perfectly constant current regardless of input voltage, but since the application is automotive, the supply hardly varies anyway (12.6 - 14V).

Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
Definition of a current mirror: the only difference is mine has emitter resistors added to force VBE temp tracking and also adjust sharing ratios. It's still a current mirror, or specifically, a "current sourcing mirror".. It's advantage is all the VBEs track over temp. An easy way to get perfect tracking is glue the face of the diode-transistor to the face of one of the other transistors.

#### Attachments

• 101 KB Views: 56
Last edited:

#### bountyhunter

Joined Sep 7, 2009
2,512
The only reason you would want a constant current source is unstable power supply voltage, otherwise a simple resistor would work as well.
Yes and no. An auto supply is hardly unstable (varies only about 10%) but a resistor would not work since the LED load has about 10V across it. A resistor setting 25mA @ 12.5V (100 Ohms) will feed it 40 mA at 14V in which is a 60% increase. The circuit I posted will only vary the LED current about 10% in for the 12.5 - 14V range.

#### SgtWookie

Joined Jul 17, 2007
22,230
Bountyhunter;
Point well taken about the current variations due to temperature and the mismatch between diodes & transistors being used.

Changed it over to a current mirror, and rather than using a resistor for the current sink from the collector, used an LM317 to provide the constant current. This got away from the 3v minimum dropout being in series with the LEDs, and provided for much better regulation than just using a resistor for the collector/base current sink.

The previous circuit I'd posted had a range of ~17.4mA to ~19.9mA over 11.5v to 14.5v and 0°C to 40°C; 2.5mA difference.
This modified version has an LED current range of 19.58mA to 19.74mA over the same voltage and temp range; 0.16mA variation.

It would be better if I'd used an LM317L so I could decrease Iout to ~5mA, but I don't have a model for that. I've been looking ...

#### Attachments

• 129.4 KB Views: 75
Last edited: