Making a pin sink?


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2007
    Posts
    67

    Default Making a pin sink?

    Silly question...

    How do I make a pin sink current? I want to use a single pin to open a PNP transistor used as a power switch on the positive rail.

    Do I set it as an input? Do I set it as an output then set it's low state? I guess the direct question - how do I programatically connect a pin to ground? I'd prefer a straight PBP solution.


    And a follow-up question...

    Is it safe to use this switch to actually drive the PIC? So the Pic is downstream, using a push button to temporarily "jump" the transistor, when the Pic boots up it begins to sink current from that transistor causing it to come open, then when the button is released, the Pic continues to operate as usual - essentially latching it's own supply open. When I want to power down, I make that pin stop sinking current which should shut down the Pic (after it's 10uF cap discharges) which should give it time to cleanly execute the last program statements - basically pulling its own power supply.

    But the first question is most important... trail and error, but I'd feel better hearing the "right way" from someone who knows.

    Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do I set it as an output then set it's low state?
    YUP.

    Think of it like this. LED connected anode to positive rail. To make it light with the cathode connected to a PIC pin you would output LOW. (LED has a drop down resistor)

    The same pin will also have a 100K resistor to the positive rail in the transistor case to keep it from floating low.

    I can not see why the transistor idea would not work, have not tried it though.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    kevj, What is the potential on the emitter of the transistor in reference to ground? I am assuming you are using it as a pass transistor for the supply to some other circuitry. If you are trying to switch a voltage potential greater than 5volts + .7 volts then the PIC pin connected thru a resistor directly to the base of the transistor will not work. The PIC pin will not open it's circuit completely but have the VDD source voltage present. You will have to put a diode in series with the 1k resistor to the base of the transistor (cathode towards the PIC) so as to block the 5 volts being sourced from the PIC pin. Then a resistor of about 10k from the base of the transistor to the emitter.

    Dave Purola,
    N8NTA

  4. #4
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Dave-

    The emitter will see the same 5v supply that's going to Vdd on the PIC. I want to use a single transistor to turn on and off some downstream components.

    After reading more about BOR and using MCLR, I'm not going to use the same transistor to switch the supply to the PIC itself anymore.

    So it's basically just a PNP on the supply side of several downstream components. As those components are spread out a bit and my board space is super limited, I wanted to switch them all with 1 transistor (well within it's power rating), rather than putting NPN's on the ground side of all the components or having to route ground traces everywhere.


    Right now I've got the schematic like this......


    {5v Supply} ----------------------- {PIC}
    |
    |
    -------------{NPN}------ collector to downstream loads --->
    |
    |----- base via a 2k resistor direct to PIC pin set as Output


    I've seen this setup in several other schematics and never saw a diode in there - maybe that's only required if driving the pic's supply itself as I stated in my OP?

    When the Pic boots up, it'll bring that pin low to turn on the downstream stuff, then before "shutting down" it'll bring it high then sleep which will bring it's MCLR low as well as pulling Vdd below the BOR - so it should be shut all the way down.

    What I don't understand is why that pin (to the PNP base) doesn't drop back to ground when the PIC goes into reset. I've tried it with an LED being sunk, and the LED does go out as soon as the PIC shuts down, so it would seem that reset does not cause all the output pins to click back to ground.

    Can someone give me a warm fuzzy that this is correct? I don't want a PIC in reset to allow a pin to float back down to ground (after being in reset for say - a week or two), and all of a sudden that PNP comes open again and powers up all the downstream stuff without the PIC being alive. Nothing really bad would happen except it would quickly kill the limited onboard battery supply.

    Thoughts?

    Thanks!!

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    When the pic boot, usually all I/O are configured as input. The small nifty voltage could be just enough to trigger your transistor, PNP or NPN. What we usually use if we can't deal with the settle delay (Bor, Power up timer etc etc) OR to keep things safe while using Bootloader or ICSP, is to add a simple resistor between the Base and the Collector. This way it solve the problem.

    <IMG SRC="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2175&stc=1&d=119670537 4">
    Attached Images Attached Images  
    Last edited by mister_e; - 3rd December 2007 at 18:15.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Thanks e. That's perfect. That's exactly the way I've got it in my schematic. I'm using a 2k resistor for the base, and a 20k for the bridge to Vcc (I read "use 10x the amount") on another site.

    I'm still don't totally understand exactly what's happening or why I need the bridge to Vcc, but I see it in every example I look at so it's in there.


    Anyway, using that example, there should be no way for the Pic to continue to sink current and open the transistor when it is in reset - correct? Or should I switch that pin to an input programatically before allowing the Pic to go into reset?

    Part of the output of that transistor is what will hold MCLR high, so that's the main reason I want to make sure once it's off it stays off. I've got a tact switch that jumps over all of this via a diode to boot up the Pic.

    Thanks again... I think I'm on the right track anyway.

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    kevj, Mister E drew a nice picture of what I was talking about. The diode I mentioned was because I had no idea of what potential you were trying to switch. I didn't think i had to draw you a picture.....

    Dave Purola,
    N8NTA

  8. #8
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    The “bridge to Vcc” resistor is needed cause transistors ain’t perfect. There is always a leakage current from B to C that needs come from somewhere. If you don’t provide a source for it then it comes from E to B, which is real base current, which makes the device begin to turn on, which increases current out the collector, which burns power, which heats the device, which increases the B to C leakage that needs come from somewhere …

    The bridge resistor gives the current a source path to keep it from going E to B. I personally go much higher, like 100x.

    In this specific case, if Vcc also supplies the PIC you don’t need the bridge resistor, because it is only needed when you turn the device off, and at that time the base resistor is connected to Vcc (thru the output)… so you actually get the same benefit of the bridge from the base resistor.

    The same is true driving grounded emitter NPN’s thru an R from an output, you don’t really need the bridge.

    But if in any doubt, resistors are cheap; put it in.

  9. #9
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by ErnieM View Post
    The “bridge to Vcc” resistor is needed cause transistors ain’t perfect. There is always a leakage current from B to C that needs come from somewhere. If you don’t provide a source for it then it comes from E to B, which is real base current, which makes the device begin to turn on, which increases current out the collector, which burns power, which heats the device, which increases the B to C leakage that needs come from somewhere …


    Outstanding! Thank you Ernie - that actually helps a lot - I'm much more clear now. Total lightbulb moment.

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    while i can't 100% agree with explanation for a simple G.P. NPN/PNP, i will suggest you a simple test... configure an I/O as input,and measure the voltage between it and GND.. what do you get?

    What's the trip point of a transistor?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Aug 2007
    Posts
    67


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post

    a) a simple G.P. NPN/PNP

    b) configure an I/O as input,and measure the voltage between it and GND.. what do you get?

    c) What's the trip point of a transistor?

    a) What is a G.P. ???

    b) With the power on or off?

    c) Don't know.

    d) Can I buy a vowel?


  12. #12
    Join Date
    Jul 2005
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    The last one is easy!

    c) What's the trip point of a transistor?
    It's a trick question. Transistors are analog devices; they don't have anything like a well-defined trip point.


    And I'll go out on a limb here and guess "GP" is General Purpose.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

Members who have read this thread : 1

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