PDA

View Full Version : Sinking current from 9V into a PIC pin.



HankMcSpank
- 21st March 2011, 18:39
Just wondering how to approach this....obviously there's a 20mA limit on a PIC pin (not to mention a 5V limit too).

I don't want to 'feed' the LEDs from the 5V rail as that will stress the overworked (small) regulator I'm using, but rather I would like to sink the current from the raw unregulated 9V rail (a PP3 battery)....I realise this approach probably isn't optimum, as because when the battery voltage level starts dropping, so will the current through the LEDs...and therefore the brightness (I was thinking of compensating the falling battery voltage by monitoring the battery level through a potential divider into an ADC pin, then adjusting the PWM duty cycle ceiling as the battery voltage falls)

my question is, how should I approach this?

Would something like the circuit I've lashed up below suffice?

(if it's not clear - RC5 is a PWM pin that feeds the PNP transistor, which in turn sinks current from the 9V rail, through the LEDS into the PIC pins (ie set LOW to enable the LED)

http://img541.imageshack.us/img541/3538/ledm.jpg (http://img541.imageshack.us/i/ledm.jpg/)

Are there any specific (SMD) PNP transistors that work well in this situation?

mark_s
- 21st March 2011, 22:19
Hank,

One simple way to regulate the leds, is to tie R10 going to the base PNP to the +5 rail and the emiter to +battery. This will regulate the voltage going to the leds to a little over 5v and not strain or add noise to the uP supply.

Your idea of pwm current regulation with adc feedback is the most efficent, but at the cost of two pins.

I have used a lot of PN2907 pnp transistors. SMD, MMBT2907A

sayzer
- 22nd March 2011, 05:47
Just wondering how to approach this....obviously there's a 20mA limit on a PIC pin (not to mention a 5V limit too).

I don't want to 'feed' the LEDs from the 5V rail as that will stress the overworked (small) regulator I'm using, but rather I would like to sink the current from the raw unregulated 9V rail (a PP3 battery)....I realise this approach probably isn't optimum, as because when the battery voltage level starts dropping, so will the current through the LEDs...and therefore the brightness (I was thinking of compensating the falling battery voltage by monitoring the battery level through a potential divider into an ADC pin, then adjusting the PWM duty cycle ceiling as the battery voltage falls)

my question is, how should I approach this?

Would something like the circuit I've lashed up below suffice?

(if it's not clear - RC5 is a PWM pin that feeds the PNP transistor, which in turn sinks current from the 9V rail, through the LEDS into the PIC pins (ie set LOW to enable the LED)

http://img541.imageshack.us/img541/3538/ledm.jpg (http://img541.imageshack.us/i/ledm.jpg/)

Are there any specific (SMD) PNP transistors that work well in this situation?

Did you actually turn on and off this led, did you try it in real solid circuit?
You are driving a PNP transistor (tied to +9V), by 5V to its base and it works?

____________________________

Archangel
- 22nd March 2011, 06:42
Did you actually turn on and off this led, did you try it in real solid circuit?
You are driving a PNP transistor (tied to +9V), by 5V to its base and it works?

____________________________
Hi Sayzer,
as long as the supplies have common ground? You might try "Digital Transistors" and eliminate the base resistor. Why use PNP at all ?

HankMcSpank
- 22nd March 2011, 09:42
Firstly, it all works as expected ...as per the circuit diagram! (btw: I'm more of a FET, Opamp, Valve type fella vs transistors!).

Ok, so why use a PNP......because I want the LEDS to source their current from the 9V rail *not* the PIC IO pins...therefore I need to switch the voltage into the LEDs...is there any other way of acheiving the same result that's more elegant?

Re the digital trannies....I found them yesterday & have some sitting in a cart with my RS Account ...

http://docs-europe.electrocomponents.com/webdocs/0469/0900766b804694cd.pdf


(it can handle 100mA, & I'm working on about 5 LEDS @ 18ma, so that should be ok)

sayzer
- 22nd March 2011, 11:41
Hi Sayzer,
as long as the supplies have common ground? You might try "Digital Transistors" and eliminate the base resistor. Why use PNP at all ?

Hi Joe,

My point was not what you meant.
If a PNP transistor is supplied by 9V, and you drive it with +5V (less than 9V), then the transistor will not be ignited as you expect.

As easy as having it tested on real circuit.
Just drive an LED via PNP transistor by a PIC, ON and OFF.
You will see that LED will not fully turn OFF.

And for the subject, our friend should use NPN, or for the easniness, use ULN2003, ULN2803.

Charlie
- 22nd March 2011, 12:15
I confess that I did not look at the PIC device being used, but if RC5 is a standard pin (can be 5V or 0V and can sink or source current) then I think if you measure the circuit being proposed, you will see the transistor really is not doing anything - in fact, it will be on at all times.
Instead you need an NPN transistor. The base gets connected directly to RC5, The collector to 9V and the emitter to the LED Anodes. This limits the voltage seen by all PIC pins to 5V or less (closer to 3V), and supplies the current from 9V (The PIC still needs to sink that current)
You may well damage the PIC trying out the circuit shown in the drawing.

HankMcSpank
- 22nd March 2011, 12:17
Hi Joe,

My point was not what you meant.
If a PNP transistor is supplied by 9V, and you drive it with +5V (less than 9V), then the transistor will not be ignited as you expect.

As easy as having it tested on real circuit.
Just drive an LED via PNP transistor by a PIC, ON and OFF.
You will see that LED will not fully turn OFF.
And for the subject, our friend should use NPN, or for the easniness, use ULN2003, ULN2803.

The LED *does* turn off ! (ie the PNP tranny is working as I intended/required - real world, not simmed or theorized!) .....ie at a PWM duty cycle of value 255 the LED is visibly off (at a duty cycle value of 250 the LED light is just detectable...the LEDS continue to get brighter all the way to a duty cycle value of 0)

Re using an NPN....how would that slot into my needs of having a PIC sink the current per LED (in otehr words the suply voltage to the LED anodes needs to be commonised - how to switch that common voltage with an NPN?).

re using the ULN2003...I have no extra space available! (that's why I want to use a single, SOT23 SMT tranny to switch the 9V to the LEDS)

Archangel
- 22nd March 2011, 16:58
Re using an NPN....how would that slot into my needs of having a PIC sink the current per LED (in other words the supply voltage to the LED anodes needs to be commonized - how to switch that common voltage with an NPN?).

? ? ? Swap the emitter and collector so power flows in correct direction, then invert PWM values (or not), transistor now conducts on positive instead of NEG. Keep those digital transistors, which are avail. from Mouser in mind to save board space too, they are equipped with internal bias resistors for logic level switching, and they are still very small footprint.

Charlie
- 22nd March 2011, 19:57
Any base-emitter pair can only be a diode drop apart if the device is working. So, if the emitter is at 9V then the base is at 8.4 V or so. This means that either the PIC RC5 pin would need to be above 8.4V, or tri-stated to an open circuit to turn the transistor off. At 5V or 0V, the transistor is on. So you must be changing the tri-state, not the value (0,1) of the pin.
The problem with this is that all of the pins are briefly exposed to 9V, albiet through current limiters. Maybe the device has a sense of humour about this, maybe not. If you are making a hobby toy for yourself - have at it. If you are making a product, do the support folks a favour and do a little reading about transistors.
You have not shown us your code, or which device you are using so we are guessing here, but rest assured the concerns are valid. Just because it *appears* to work, does not mean it still will next week.

HankMcSpank
- 22nd March 2011, 21:49
This is the point where Hank asks for a large dose of humble pie...obviously at some stage in my frenetic breadboarding activity (moving wires around all over the shop), I've actually got 5V going to the PNP emitter (not the 9V I thought was on there).

Just to prove the point...I put 9V on the emitter...the PIC lived, but the LEDS didn't turn off when the duty cycle went to 255.

You're all vindicated! (not that I ever doubted you!)

Charlie...this is just a hobby.

sayzer
- 23rd March 2011, 07:27
...
You will see that LED will not fully turn OFF.
....


The LED *does* turn off ! (ie the PNP tranny is working as I intended/required - real world, not simmed or theorized!) .....


... I've actually got 5V going to the PNP emitter (not the 9V I thought was on there).

Just to prove the point...I put 9V on the emitter...the PIC lived, but the LEDS didn't turn off when the duty cycle went to 255.

....

Hello there....

I was going to ask you to measure the voltage on the emitter. But you already had it.

And for the idea of yours, you have a pwm pin and also LED pins.
And you are trying to show the voltage level, as much as I understood.
So, as the voltage drops, you want to show it with the LEDs.
Say, if the voltage is 8V, you have one LED off. Am I right? or something like it.
But, why are you using PWM then?
Can you explain more?
How the pwm and the LEDs will work?

HankMcSpank
- 23rd March 2011, 09:31
Hi Sayzer,

I'm just learning about driving LEDs & PWM here.

I want to be able to have numerous LED patterns (hence the individual PIC connections to the LEDS, but also a 'common' dimming ability (hence the PWM to the, tranny controlling the supply to all the anodes).

What I was ideally after was to connect the 'common' supply (controlled by the transistor) for all the LED anodes to 9V. This would save some heat losses, whereby the 9V gets regulated down to 5V first, & then feed the anodes.

the problem of course with using an unregulated power source, is that when the voltage starrts drooping (as the battery life fades), then the current through the LEDS will be less.

9V battery = plenty of LED brightness
7.8V battery = less LED brightness.

My idea was to monitor the voltage level of the battery within the PIC and then have an adjustable PWM ' maxceiling' to suit, therefore....

Fresh 9V battery = PWM value of 220 *max*
7.8V battery = PWM value of 255.

In other words I get the PIC to regulate the 'effective' voltage as presented to all the common anodes based on the battery voltage its monitoring.

Charlie
- 23rd March 2011, 10:26
This application calls for a transistor to operate in it's linear region, and not as a switch.
Use an NPN transistor. The base gets connected directly to RC5, The collector to 9V and the emitter to the LED Anodes. This will accomplish your objective of having the current come directly from 9V instead of your small regulator. The NPN effectively becomes a regulator as it's emitter will be either a diode drop below 5V (4.3V or 4.4V) when RC5 is high, or 0V when RC5 is low.
The voltage across the transistor when it's on will be 9V - 4.3V = 4.7V Multiply this by the current flowing to get the power dissipated by the device, and if it is too high, then choose a resistor, based on the maximum current, and put it between the collector and 9V to move some power out of the transistor and into the resistor. (I doubt you will need to do this).
As a side note, the LED will maintain brightness down to about 6V without any adjustment of pulse width, so if this is the only reason for the PWM then you could connect the base directly to 5V instead of RC5. However, left at RC5 you can still dim the LEDs for aesthetic reasons, and power savings.

HankMcSpank
- 23rd March 2011, 10:53
The voltage across the transistor when it's on will be 9V - 4.3V = 4.7V Multiply this by the current flowing to get the power dissipated by the device, and if it is too high, then choose a resistor, based on the maximum current, and put it between the collector and 9V to move some power out of the transistor and into the resistor. (I doubt you will need to do this).


So in essence, I'm moving the 9V->5V 'conversion heat' dissapation from the regulator, directly to the tranny controlling the LEDs?

Perhaps I'd be better just upping the spec of the regulator?

I guess what I was shooting for was the most battery friendly way of driving six LEDs from 7.5V thru 9V, and in my simplistic world I thought that avoiding regulating the 9V down to 5V (direct heat loss), and using PWM to switch the tranny on/off would be the way to go!

Charlie
- 24th March 2011, 11:09
You can certainly use a higher rated regulator, although splitting current into 2 devices to share power load is pretty standard practice and not at all bad form - especially if increasing the regulator current would drive you to a heat sink! However, using the PWM to dim the LEDs will still save power if you keep the transistor in the circuit. Your intent was to make them the same brightness as the voltage dropped, which won't be necessary. But you could instead make them 1/2 brightness all the time with the PWM - and save 1/2 the power. Or any other ratio you choose.

Ramius
- 9th April 2011, 19:50
Hi Hank,
Hope this may assist you. In such matters I tend to use and optical isolator which has 2 LED's and transistors in one 8 pin package such as the NTE3086.

Best, Ed