PDA

View Full Version : Making a pin sink?



kevj
- 3rd December 2007, 05:29
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!

mackrackit
- 3rd December 2007, 05:48
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
- 3rd December 2007, 11:44
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

kevj
- 3rd December 2007, 17:54
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!!

mister_e
- 3rd December 2007, 18:03
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=1196705374">

kevj
- 3rd December 2007, 20:08
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.

Dave
- 4th December 2007, 11:51
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

ErnieM
- 7th December 2007, 22:16
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.

kevj
- 8th December 2007, 04:45
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. :)

mister_e
- 8th December 2007, 10:02
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?

kevj
- 9th December 2007, 03:07
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?

:)

ErnieM
- 9th December 2007, 04:26
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.