PDA

View Full Version : Drive an LED direct from a PIC IO pin (ie no current limiting resistor)



HankMcSpank
- 18th April 2011, 00:22
If I use a PIC 16LFxxxx and a 3.3V regulated supply rail...I'm figuring I should be able to drive a Blue LED direct with no current limiting resistor fed direct from a PIC pin?

I'm going to have the PIC sourcing current for the LED (ie providing voltage to the LED) - I'm thinking here that the PIC pin's internal resistance, should result in just under 3.3V (3.2V?) at the actual PIC output pin ...which for a blue LED is pretty much right on the money.

Sanity check?

rsocor01
- 18th April 2011, 01:18
Check this post out,

http://www.picbasic.co.uk/forum/showthread.php?t=14532&p=100328#post100328

Blue LEDs required forward voltage is usually higher than the other color LEDs. So, I think you are ok.

Robert

HankMcSpank
- 20th April 2011, 17:38
Thanks for that...well I tried it (basically supplying a PIC off 3.3v) ...it all works, but alas, the LEDS aren't quite bright enough.

A bit of experimentation suggests a supply voltage of about 3.6V would be best ...but I need the regulator to be a SOT23-3 package& they don't seem to exist in 3.6V voltages.

My immediate thoughts re a kludge is to use a 4V regulator but use PWM to feed the LED 'common cathodes ' with 0V only 90% of the time ....which is effectively a voltage of 3.6V across the LEDs?? (yeah I know, it's not really it's still 4V across the LEDs ...albeit for only 90% of the time ....but I'm thinking that at least the LEDs, will have 10% 'downtime' to cool off from the extra current through 'em)

Do-able?

HankMcSpank
- 20th April 2011, 23:42
Doh....the reason 3.6V to 4V works better with the LEDs (which was puzzling me, since the LEDS are meant to have a rated forward drop of 3.2V)), is because I have an NPN transistor switching the common ground to all the LEDs...this drops 0.7V across itself, therefore the LED only sees the 'supply voltage' less 0.7V the drop acrossr the NPN tranny) ...therefore at a supply of 3.3V the LED was only seeing 2.6V ...no wonder they were dim - man, I'm having a bad day!

ronsimpson
- 21st April 2011, 00:37
Driving LEDs without a resistor:
LEDs are current to light devices not voltage to light. The forward voltage is for reference only.
I just looked through 10 data sheets for parts we are using. Often the forward voltage is only stated as typ. Several LEDs were rated as 3.2V typ, 4.0 max and they did not rate Vmin. As a hobby you do what works. If you purchase millions you will find parts that need 3.7 volts and parts that need 2.8 volts.
LEDS are like a Zener diode. IF 3.0 volts = 10mA them 3.2 volts =20mA. Worse yet the V-forward drops with temperature. As the parts gets hot it will pull more current (in constant voltage move). Runaway condition.

HankMcSpank
- 19th May 2011, 21:14
Still mulling my options here.

Here's the conundrum....I want to be able to run upto 12 leds off either AA - or more likely AAA - batteries. It's be cool if I could use rechargeables.

Therein lies a problem....3 x 1.2V is 3.6V ....an LDO would be no good here (they normally have a drop out voltage of about 0.8V.....meaning with 3 batteries the max I could expect to get regulated is about 2.7V (& that's with fresh batteries!)

I could up the battery quota to 4 batteries, but I'm really pushed for space...so I'd like to stick with 3 x 1.2V batteries (or 2 x 1.5V batteries)

Ok, blue LEDS ....yep, they normally have a forward voltage quoted around the 3.4V mark....having measured the batch I have, the current through 'em at that particular voltage is about 20mA. I actually want to 'under volt' them....the blue LEDs I tested only pull about 10-12mA at around 3.1V....but they're still plenty bright.


So here's what I was thinking....

use a 'LF' PIC variant, supplied by battery but the PIC gets it's supply via low quiescent current 2.5V regulator.

Drop the unregulated battery supply via a two resistor divider, so that the max that can be seen at the PIC ADC pin from the resistor the junction feeds is 2.5V.

So for example.....3 x normal AA batteries (fresh @1.6V initially), would mean 4.8V unregulated.....so eg use two resistors R1 2.3K, R2 =2.5K.

Ok, now with fresh batteries, there'll be 2.5V at the junction....feed this into a PIC, ADC it, now use a LUT....

If the PIC's ADC reading is 255, then the duty cycle (to the leds) should be 168 (66%)...therefore the effective voltage the LEDS 'receive' is 3.1V (4.8V x 67%)

Ok, now the batteries drop after usage, let's say they now amount to 3.8V in total ...this would read as an ADC value at the pic pin of 201, the duty cycle to the LEDs is 211 83%,so what I'm proposing is a simple lookup

if ADC value = 255 the duty_cycle = 168
if ADC-value = 201 then duty cycle = 211

& all values in between.

Or is there an LED driver IC (or an inductorless buck converter ....as inductors don't work well in guitars) to save me the bother? (to recap, I don't want to lose the 'spare/excess' voltage as wasteful heat (ie via a linear regulator)....but rather use PWM to 'manage/massage' the effective voltage that the LEDs ' receive'

(yes I know leds are current devices, but there's a good correlation between voltage applied across them & current they draw...also, again, I'm going to be underpowering them)

mister_e
- 20th May 2011, 01:30
You get the idea.

Look Melanie Dice example, or do it simple, plug your LED directly to the PIC and have a PWM running out of your PIC, use a MOSFET to drive the common GND or VDD of your LED (whatever floats your boat).

You now have a variable intensity, using a minimum of parts... BUT, the more the battery get flatten, the less intensity you'll also have (assuming you don't use anything to monitor it... and if so... you end up with more extra hardware than a simple LDO regulator)

HankMcSpank
- 20th May 2011, 08:21
You get the idea.

Look Melanie Dice example, or do it simple, plug your LED directly to the PIC and have a PWM running out of your PIC, use a MOSFET to drive the common GND or VDD of your LED (whatever floats your boat).

You now have a variable intensity, using a minimum of parts... BUT, the more the battery get flatten, the less intensity you'll also have (assuming you don't use anything to monitor it... and if so... you end up with more extra hardware than a simple LDO regulator)

This is exactly the setup I'm proposing....use a transistor to control the 'effective' voltage the LEDSs 'see'. But for monitoring, I'll use a spare ADC pin on the PIc to monitor the unregulated supply voltage....and then adjust the PWM to the LEDs accordingly.

The problem with using an LDO regulator, is they're very inefficient.

mister_e
- 20th May 2011, 10:00
I would suggest to use a Mosfet with a decent small Rds, this way you could/should loose less voltage across than a regular BJT.

Add a small value resistor between the MOSFET source and GND, put a cap on it, feed it to the ADC and voila you monitor the current.

Tons of way to do it.

HankMcSpank
- 20th May 2011, 10:03
I would suggest to use a Mosfet with a decent small Rds, this way you could/should loose less voltage across than a regular BJT.

Add a small value resistor between the MOSFET source and GND, put a cap on it, feed it to the ADC and voila you monitor the current.

Tons of way to do it.

All good stuff there....have you any example of suitable mosfets you've used in the past? (just to give me a general vibe of the spec - I'm ideally looking for something in a SOT23 package)

Edit: Hmm: I'm thinking here that I'm only going to be switching 3.3V across the leds - do mosfets work ok that low (all the ones I'm seeing on digikey are typically 20V VDS or more ...ok so that's a max figure, but never having used modfets, are they ok with switching 3.3V well)

mister_e
- 20th May 2011, 10:06
Yish, me and remembering Mosfet Part # are two different animal ;)

I would say go on Digikey website, type Mosfet SOT23, then shop by max current and Rds.

How much current you'll need?

mister_e
- 20th May 2011, 10:09
And don't forget to check the datasheet... Vgs...

HankMcSpank
- 20th May 2011, 10:14
Yish, me and remembering Mosfet Part # are two different animal ;)

I would say go on Digikey website, type Mosfet SOT23, then shop by max current and Rds.

How much current you'll need?

Not much....8 possibly 12 leds....ay about 15mA each max ....say 180mA, I'll have a sniff on Digikey.....


Edit: Hmm: I'm thinking here that I'm only going to be switching 3.3V across the leds - do mosfets work ok that low? (all the ones I'm seeing on digikey are typically 20V VDS or more ...ok so that's a max figure, but never having worked with MOSFETS previously, are they ok with switching 3.3V well)

mister_e
- 20th May 2011, 10:29
Double check those

BSS138, 2n7002K, FDV305

mister_e
- 20th May 2011, 10:37
Edit: Hmm: I'm thinking here that I'm only going to be switching 3.3V across the leds - do mosfets work ok that low? (all the ones I'm seeing on digikey are typically 20V VDS or more ...ok so that's a max figure, but never having worked with MOSFETS previously, are they ok with switching 3.3V well)
You want to look for Logic Gate one and/or with a low Vgs... at least under the battery voltage ;)

HankMcSpank
- 4th June 2011, 00:47
Double check those

BSS138, 2n7002K, FDV305

Well in the end I ordered up a few BSS138s.....I have to hold my hands up & say I'm gernally bemused about what's going on here.

Firstly, here's the simple circuit (the schem shows a tranny, but for the purposes here, it could be a tranny or a fet)...

http://img708.imageshack.us/img708/1326/44691757.jpg (http://imageshack.us/photo/my-images/708/44691757.jpg/)

(there are actually two more 'legs' of leds not shown....they join to the same FET drain ...so in total 8 LEDs)


So the story is, I'm wanting to use a 9V battery...but rather than waste the extra voltage across a high value resistor, I want to use PWM to 'average' the current the LED sees through it.

I initially used a NPN digital tranny, but measured approximately 3V across the emitter collector. Now that struck me as a lot, so I posted further up on this thread ...the recommended BSS138 looked like a reasonable contender ...about 3.5 Ohms when on.

So I put one in situ today expecting to see a couple of hundred millivolts drop across the source drain....nope not at all .....at 9V supply, with those resistors above, & with the PIC running at a duty cycle value of about 87 (where 255 is max), Im measuring 2.59V on the FET drain .....since the source is tied to ground, this means there's 2.59V being dropped across the fet....yet across the resistors I'm measuring 780mV ....which means there's about 20mA running through each LED 'leg'...so the FET has 4 x 20mA running through it = 80mA (ie four groups of two leds......each group has 20mA throug it) ....so how come I'm seeing a drop of 2.59V across the FET?

This suggest the Jfet Drain Source resistance is about 32 Ohms?!! (which is nowhere near the 3.5 ohms I was expecting!)

What am I missing here?

rmteo
- 4th June 2011, 01:27
What that tells you is that the average Vf (forward voltage drop) of your LEDs is 2.815V [(9-2.59-0.78)/2] at 20mA current draw.

HankMcSpank
- 4th June 2011, 11:12
Well, I have to say I'm well confused...these are white leds....have a forward voltage of 3.175V (for 20mA), I can only imagine my DC readings (& my brain) are being put out of whack by using a meter that's not factoring in the PWM (which with a HPWM duty cycle figure of 89, means the voltage is only there 1/3rd of the time)....I need a strong coffee to ponder this one more!

HankMcSpank
- 5th June 2011, 10:37
Ok the issue in the end was embarrasingly simple...I was using a meter that wasn't true RMS, therefore my readings are out of whack.

I've just ordered up a true RMS multimeter (a uni-t UT61E, mainly becuase the U61D fared reasonably well in this shootout.... http://www.youtube.com/watch?v=3-_dUB8vy8U *especially* for its 'true RMS' reading ability 42m30s in)

HankMcSpank
- 25th June 2011, 19:55
Ok, a real quickie wrt PWM and this circuit config...

http://img135.imageshack.us/img135/3407/bss138.jpg (http://imageshack.us/photo/my-images/135/bss138.jpg/)

...will a high value of duty cycle (eg 255) turn the LEDs on fully (and a duty cycle of 0 turn them) off or vice versa?

mister_e
- 25th June 2011, 20:14
it has to... It's a case by case thing, monitor your HPWM output with a scope. But usually you want to manually turn the PIN HIGH /LOW. Just disable the PWM mode and use HIGH/LOW.

HankMcSpank
- 25th June 2011, 21:53
Well I can tell you what's happening in practise (with that very circuit) ....a PWM duty value of 255 turn the leds on bright, a duty value of 0 turns them completely off. But my brain is now frazzled, because I always thought that with 'n' channel fet, with no source/ gate voltage differential (therefore a duty value of 0) a fet will conduct at its lowest RDS resistance .....& to 'cut it off', you need to make the gate more negative.

But obviously with the above config the the source is at ground, the only way is up so to speak (on the gate...ie if driven by a PIC) ..therefore no possiblity of turning the n fet off.....which bit am I not grasping?!

I removed the PIC (so the gate was floating) & the leds remained on (which is kind of what I expect)

Brainache.

HankMcSpank
- 25th June 2011, 22:39
Well this clarifies how an n-channel mosfet will work

http://www.youtube.com/watch?v=Te5YYVZiOKs

but it doesn't go into detail.

I'm making a (bad) assumption) that an n channel mosfet, will work in a similar fashion to a jfet (which I've used prior...mosfets never)...with jfets, you have to make the gate negative wrt to the source to cut them off....hey ho, I guess that why a jfet is called a jfet & a mosfet is called a mosfet....different devices...no workee the same.

rmteo
- 25th June 2011, 23:27
....to 'cut it off', you need to make the gate more negative.

But obviously with the above config the the source is at ground, the only way is up so to speak (on the gate...ie if driven by a PIC) ..therefore no possiblity of turning the n fet off.....which bit am I not grasping?!

Look up the Vgs parameter (and the typical transfer characteristics graph - IRF8714 in the example below) in the datasheet of a MOSFET for the answer.