Sinking current from 9V into a PIC pin.


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    653

    Default Sinking current from 9V into a PIC pin.

    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)



    Are there any specific (SMD) PNP transistors that work well in this situation?
    Last edited by HankMcSpank; - 21st March 2011 at 18:46.

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    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
    Last edited by mark_s; - 21st March 2011 at 22:24.

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by HankMcSpank View Post
    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)



    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?

    ____________________________
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by sayzer View Post
    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 ?
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    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...6b804694cd.pdf


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

  6. #6
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    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.

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by Joe S. View Post
    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.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by sayzer View Post
    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)
    Last edited by HankMcSpank; - 22nd March 2011 at 12:21.

  9. #9
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by HankMcSpank View Post
    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  10. #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    Quote Originally Posted by sayzer View Post
    ...
    You will see that LED will not fully turn OFF.
    ....
    Quote Originally Posted by HankMcSpank View Post
    The LED *does* turn off ! (ie the PNP tranny is working as I intended/required - real world, not simmed or theorized!) .....
    Quote Originally Posted by HankMcSpank View Post
    ... 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?
    Last edited by sayzer; - 23rd March 2011 at 07:34.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  11. #11
    Join Date
    Mar 2009
    Posts
    653


    Did you find this post helpful? Yes | No

    Default Re: Sinking current from 9V into a PIC pin.

    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.
    Last edited by HankMcSpank; - 23rd March 2011 at 09:34.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts