SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By hcker2000
#12192
To be safe I should say that all leds are capable of being on at once as I have two patterns that at some point all the leds are lit.

It would be great if I could just use the pic to drive the leds as that realy cuts down on cost and time.

Right now I'm using porta on my 16f88. In the end I may be switching to a 16f628A just because why waste a pic with some many fetures on blinking some leds :D

I supose I could put 3 channels on porta and 3 channels on portb though its gona be a pain in the but to write the code.

Just let me know what you all think would be best.
By Philba
#12230
Actually, the 7805 will see the same amount of dissipation either way.

You could simply drop the current to 10 mA - you would still get decent light from the LEDs, stay within the PICs current limits and not have to fiddle with extra hw (drivers, regulators, etc).

The nice thing about the F88 is you can use a boot loader - think about what happens if you have the device installed and you decide to change the program? If you have a connector with a max232 (or what ever) in the cable all you have to do is plug it into the board and, using a laptop, boottload the new program. worth the extra buck it costs.

Phil
By riden
#12235
hcker2000 wrote:To be safe I should say that all leds are capable of being on at once as I have two patterns that at some point all the leds are lit.
You didn't mention if brightness is a critical issue. Try taking a LED and connect it to 5v via a 470 ohm resistor and another to 5v via a 1k resistor. Are both LEDs bright enough for your purposes? If they are, you could use the hardware PWM (pulse width modulation) feature in the 16F88 to vary the duty cycle controlling the average current through the LEDs. Just a thought.
By hcker2000
#12247
Well I was planing on using them on my car so I would like the out put to as great as posible. Though each pair of leds will be encased in epoxy or some thing with a difuse front.

There will be 6 of those units total and will get placed in the grill of the car and wired to the pic mcu.

I'm playing right now with some different values for the leds to see what brightness might be ok with me. Right now there 12 degree visable so I'm going to be filling the leds down flat so who knows maby when I do that they will look crazy bright.

So there is no way to make the transistors work like switches if the base is at 5v and the collector is at 12v? I have no problem with having a transistor for each led group I just need to know how to set that up.
By Philba
#12248
hcker2000 wrote:...
So there is no way to make the transistors work like switches if the base is at 5v and the collector is at 12v? I have no problem with having a transistor for each led group I just need to know how to set that up.
yes there is but not exactly the way you are saying. Use an NPN as low side driver. Connect the load to +12, load to collector, emitter to gnd. Use a base resistor (couple of K would do) to connect to the pic. You will have +12 minus the bipolar silicon drop (about.7V) - 11.3V. you could put up to 3 LEDs in series plus a dropping resistor as your load this way. just calculate your dropping resistor based on 11.3V and the total led drop.
By hcker2000
#12259
I think I fallow you.

Dose it matter if I run two leds in series with a droping resistor or 2 leds in parallel with a droping resistor? I'm gona take a guess and say that buy runing them in a series I will need a lesser value resistor.

If by chance any one could post a little diagram of the connections to the npn that would help greatly. If not I can whip one up tomarow and post it and ask if it is correct.
By Kuroi Kenjin
#12264
Actually the NPN turn on is dependant upon the voltage across the base to emitter. So it switching a totemo pole like that doesn't matter, with the exception of how much current/voltage you need to drive the LEDs. Also remember, even when full on a transistor will have a voltage drop across the collector to emitter (Vcesat is the datasheet symbol).
By Philba
#12282
Vcesat can vary based on Ic (current drawn by the collector) so you will need to know that. You will probably have to guess at a Vcesat. I used .7 which is a middling value. I suspect that Vcesat will be fairly low since we are talking an Ic of 20mA The base resistor can be large because of the low Ic unless your transistor has a pathetic Hfe. [edit] I take back the R1 = 10K comment, just use 2.7K and you will be good. the reason is Hfe will drop at higher temps and you are using this ina car. [/edit]

Total voltage drop must equal 12V so you just add up the Vcesat and the LED drops. The resistor takes care of the rest and you use ohms law to figure the size for the current you want.

You definitely want series because in parallel it will pull twice the current.

here is the picture of what I meant.
Image
By hcker2000
#12289
Thanks that helps alot.
By Philba
#12290
One thing I didn't cover is calculating the base resistor as I was short of time earlier.

Basically, the transistor is a current amplifier and Hfe defines the DC gain. so 1 mA in (Ib) and an Hfe of 30 gets you 30mA out (Ic). Now you have to calculate the voltage at the base by subtracting the Base-Emitter saturation voltage (Vbesat) from the applied voltage (call it 5V from the PIC). Typical Vbesat is .7V but check the datasheet. So 5V-.7 = 4.3V and you want 20 mA or better for Ic. I'd pick a base current of 1mA. So, apply ohms law: R = V/I = 4.3/.001 = 4.3K. A standard value. when the Hfe is 30, for example, the transistor can deliver 30mA but the LED dropping resistor will limit the flow to 20mA, assuming that's what you chose R2 for. It's important not to depend on an Hfe - just pick a value below the minimum for all the conditions your circuit will encounter. If you want, you can work backwards from the value of Hfe that you picked to work with.
By hcker2000
#12318
Thanks for the fallow up that will help me figure it out.

What did you use to draw your digrams?
By Philba
#12319
I use eagle and then export/image
By hcker2000
#12320
Cool stuff I will see what I can whip up with eagle cad.