Mosfet power switch with auto-off - Page 1
Forum section: electronics / projects

author: 8086
author_rank: Super Contributor
timestamp: June 11, 2012, 12:10:16 am
content: I'm trying to come up with a design for a simple pushbutton operated power switch (over on the right side of the schematic), that I can latch somehow and turn off at will. I have a PIC in the circuit so I figure if I drive RA2 high once the circuit is powered through the momentary pressing of the button, it should stay on, and then it can turn itself off through pulling RA2 low.Are there any obvious problems with this plan? It seems logical but I know all too well there can be many "gotchas" with things that seem too simple.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 12:32:56 am
content: Let's see... a short circuit thru RA2 when someone is holding the button when PIC wants to power itself off? I'd stick a 330R resistor between RA2 and the gate/switch...

author: digsys
author_rank: Unknown
timestamp: June 11, 2012, 12:49:46 am
content: Given the info supplied, you either run the switch into it's own Input to the PIC, if you have any spare IO,OR you leave RA2 in INPUT MODE (or high impedance if that's available), then WHEN you need to controlthe output, 2 lines of code - change RA2 to OP mode via DDR, Turn On or Off. The 330R resistor is a MUSTas well. It can be up to 1-2K, as you're not running the FET at high frequency.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 12:50:46 am
content: Also, the 3V gate voltage is uncomfortably close to the gate threshold voltage of the MOSFET, in fact 2N7002 datasheet says the threshold voltage may be up to 3V max.You may get way bigger on resistance than you expect for some. You may get lucky if your supply current is extremely low. Or not. This design would be more suitable for 5V power rail.Not a huge problem in a one off project where you can pick another one that works, but I wouldn't feed an assembly line with 10000 of these, the manufacturing tolerances might bite you.I guess it's CR2032 lithium battery powered? If so, I'd have a problem with that 10k pulldown on MOSFET gate, which would have been eating your battery capacity. It may not look like much, but these CR2032s are pretty wimpy. Also I'd put a few uF cap across the CR2032, the internal resistance is pretty awful.

author: 8086
author_rank: Super Contributor
timestamp: June 11, 2012, 01:01:46 am
content: You guys are right about that resistor - oops.Interesting you should mention the threshold voltage, the datasheet I have for the 2N7002 says it's 2V typ. and 2.5V max.digsys, I'm not sure what you're getting at with giving the switch it's own input, etc, I was planning on simply setting RA2 high as the first operation after reset. The button is only going to be pressed to turn on, never to turn off.

author: Rufus
author_rank: Super Contributor
timestamp: June 11, 2012, 01:05:43 am
content: Quote from: 8086 on June 11, 2012, 12:10:16 amThere is a path from VDD to VSS through the PIC and on to the MOSFET gate via the RA2 pin clamp diode. It will sit with the MOSFET partially on or perhaps oscillate.Dave did a video on a single push button on/off circuit and there was a long thread about it and other designs.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 01:19:13 am
content: Quote from: Rufus on June 11, 2012, 01:05:43 amWhat? No, you are thinking higher gate voltages than the PIC supply, this is not the case.It's just when the RA2 outputs LOW and you press the button you would short circuit the +3V through the RA2 low side driver to GND. It would probably not even smoke the thing, these can do a few dozen of mA... but your power supply will dip and the PIC may crash due to brownout, especially on a 3V lithium battery power.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 01:25:23 am
content: Quote from: 8086 on June 11, 2012, 01:01:46 amYou're right, I was looking into the wrong box (2N7000). Damn multi-device datasheets2.5V should be OK.

author: digsys
author_rank: Unknown
timestamp: June 11, 2012, 01:28:05 am
content: QuoteA quick check aslo confirms min threshold at 2.75 max, whcih seems fine to me too.QuoteThen I don't understand the circuit .. If PA2 goes high immediately, then the OP is 3V, same as the switch?? The FET is between 0V and GNDIf SO, what potential is GND from 0V, it CAN'T be more than 20V, unless you add a zener.

author: Rufus
author_rank: Super Contributor
timestamp: June 11, 2012, 01:32:53 am
content: Quote from: hlavac on June 11, 2012, 01:19:13 amThe RA2 pin can't output LOW. LOW turns off the MOSFET which lets the PIC VSS pin rise towards 3v and the RA2 pin will rise with it.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 01:42:43 am
content: I don't think there will be a problem with that. When the PIC starts choking due to low voltage, its drivers will die off and the 10k pulldown on the gate will finish the job. It's not necessary to output LOW to turn off, merely stop outputting HIGH will do. It will just be slower.

author: 8086
author_rank: Super Contributor
timestamp: June 11, 2012, 01:47:55 am
content: Quote from: hlavac on June 11, 2012, 12:50:46 amYeah, or similar battery. Would this loss be through the pic then, considering the switch is NO, so you really just have pic -> 10k -> gnd?Quote from: digsys on June 11, 2012, 01:28:05 amIt's just a low-side switch. Instead of switching VDD, I'm switching VSS. The idea is that 0V is passed through to GND when the mosfet is on.

author: Rerouter
author_rank: Super Contributor
timestamp: June 11, 2012, 01:48:42 am
content: my first concern would be any significant capacitance between 3V and 0V will cause a slow startup that transits through the brownout region, you would want to make sure that wouldnt cause your device to do something funny,

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 01:55:59 am
content: PICs have brown out reset protection, that should not be a problem. Just enable BOD reset.

author: hlavac
author_rank: Frequent Contributor
timestamp: June 11, 2012, 02:16:27 am
content: Quote from: digsys on June 11, 2012, 01:28:05 amWhen the MOSFET turns on, it will look like a few ohm resistor between 0V and GND. There will be a small voltage drop on it dependent on the current through it.It is like a switch on the negative side of supply. It does not matter if you break the circuit at positive or negative side of the battery, it will still break.

author: electroguy
author_rank: Regular Contributor
timestamp: June 12, 2012, 11:40:08 am
content: Quote from: 8086 on June 11, 2012, 01:47:55 amI agree, you would be lucky if this thing lasts 1 to 2 months turned "off" MAYBE 3 if you are lucky.Why not just bite the bullet and get a high side switch? or make one using a few p and n type fets. that way your product should last 8 to 10 years turned "off"I know cost is always a factor, but you are only talking about an extra 15 to 20 cents for a HSS over the 2n7002. A HSS is about 25 to 30c and a 2N7002 is about 5 to 10cCan you afford the extra 20 cents to make your product last 30 to 50 times longer?! If not, just make your own using a few FET's, might only cost you 5 to 10c more.

author: 8086
author_rank: Super Contributor
timestamp: June 12, 2012, 05:37:38 pm
content: Okay, so here's an attempt at a high side switchIncluded the diode so the PIC can take the button as an input. Vf is only 0.26V @ 10mA and the NMOS threshold is max. 2.3V so I think that should be okay.Think it should work better than the previous design? I am finding it difficult to imagine unexpected battery drain paths, maybe there is a problem with R5 and R6 when it is switched off?

author: electroguy
author_rank: Regular Contributor
timestamp: June 12, 2012, 11:15:33 pm
content: much better.the diode is a good idea, that way you can use the switch to also turn off if you want, in addition to software time out auto power off.Also, does RC2 have internal pull down (i haven't checked the data sheet). If not, don't forget to add it externally, because the switch can only switch high.The only thing is the choice of fet's. i haven't checked your data sheet, but you want to make sure you get a decent on VGS voltage. I had a quick glance, it says VGS 3V, which is probably no good for your circuit, as your battery drops off and gets 2.9, 2.8, 2.7 etc... what will happen? check the data sheet carefully.

author: 8086
author_rank: Super Contributor
timestamp: June 12, 2012, 11:34:00 pm
content: Forgive me if I've missed something, but the datasheet seems to be saying that Vgs is max. 2.3v, for both N and P type (not accounting for polarity)?http://www.diodes.com/datasheets/DMG6602SVT.pdfSo with the diode voltage drop (assuming it's between the 0.2v @ 1mA and 0.26v @ 10mA to be safe) I think it should definitely be good down to a battery voltage of ~2.6v?EDIT: I just realised, I think I must have the P-channel fet upside down?

author: Short Circuit
author_rank: Frequent Contributor
timestamp: June 12, 2012, 11:41:21 pm
content: Quote from: hlavac on June 11, 2012, 01:42:43 amProbably wrong; the pin goes to negative voltage, which the input diodes don't allow beyond 0.6V. So the FET gate becomes about VCC-0.6V.

author: electroguy
author_rank: Regular Contributor
timestamp: June 13, 2012, 12:35:24 am
content: Quote from: 8086 on June 12, 2012, 11:34:00 pmIt's the P type you are worried about, as that is the one passing the higher current. The N type is only passing the current of the 1M resistor, so it will probably work at under 2V (maybe as low as 1V or less, so maybe add a pull down to the gate of the N fet, so it doesn't turn back on while the PIC is shutting down...). But the P type, you want that to have the minimum resistance when on, so you don't waste power on it. Briefly looking at it, it should be OK, so you should have no problems with a battery voltage as low as 2V, depending on your overall circuit current consumption...Quote from: 8086 on June 12, 2012, 11:34:00 pmyes, good pickup, i didnt notice! haha

author: 8086
author_rank: Super Contributor
timestamp: June 13, 2012, 12:54:57 am
content: Awesome, thanks.The upside down fet also explains the weird simulation results i've been having - I just corrected and tried again and this time got the results i expected.So, here's what I have now, I think it's all there, are 1M pullup/down appropriate, they will surely be best for battery life, or should I go for 100k, or even 10k? The 1k resistors on the PIC, would it be worth swapping them with 1M resistors as well, just in case there's some leakage through the PIC, or is leakage through the PIC not a problem with the inclusion of the high side switch, as the available current for everything will be determined by Q3?

author: electroguy
author_rank: Regular Contributor
timestamp: June 13, 2012, 01:48:28 am
content: Quote from: 8086 on June 13, 2012, 12:54:57 amlooking at your original circuit with the op amp, you are already using 100k. So if you want to minimise your BOM, i suggest you make R4, R6, R7, R8 all 100k (or you can leave R4 1M if you want to save that extra little bit of power). the PIC has a typ 0.1uA and MAX 1uA input pin leakage current, so 1M is probably a touch too big if you want to cover the full temperature range. R5 can stay 1k or 10K, (or at least something 10 times smaller than R7, as you have a voltage divider).Also, make sure your internal pullups on RA2 and RC2 are OFF.Quote from: 8086 on June 13, 2012, 12:54:57 amThat's right! much better solution, im sure you agree! If your P and N FET are low leakage (sorry i don't have time to check your data sheet), you should get 10 years+ "off" time with this using a CR2032 lithium. Your main concern now would be the "on" current usage!

author: 8086
author_rank: Super Contributor
timestamp: June 13, 2012, 07:47:03 pm
content: Awesome, thanks

author: electroguy
author_rank: Regular Contributor
timestamp: June 14, 2012, 01:29:39 am
content: no problem!there's lots of different ways to do it. You could probably get your original circuit working, but i think your final version is a bit better. Don't forget to look at HSS's, you might find some cheaper than what you can make yours, or maybe not, but it doesn't hurt to have a look at what's available.