Help with a auto-off power circuit - Page 1
Forum section: electronics / projects

author: Jeremyvnc
author_rank: Newbie
timestamp: October 22, 2014, 10:42:17 pm
content: So, I'm trying to use a digital Output from an AVR ATMEGA1284 to ground the gate on my power switch circuit's n-channel mosfet to turn off the switch. This works fine for higher input voltages but now I'm using the same circuit with a single li-ion cell. At this lower voltage, the power just blips and turns back on.What I think I need is a circuit to hold the mosfet gate lower (because I can still ground it with a wire and it turns off). Can you help me here? I'm thinking the microcontroller pin turns on an npn transistor that has an RC pair on the gate so that even if the microcontroller resets to high impedance, the npn transistor will still remain on which will allow current to flow and ground the mosfet gate. What are your thoughts? Any better ideas or something I'm not thinking?Attached is the circuit for the power switch.Auto-Off is the signal from the microcontroller pin.

author: Mr.B
author_rank: Unknown
timestamp: October 22, 2014, 11:05:28 pm
content: I have done a similar thing using this circuit from Pololu:http://www.pololu.com/product/751Cheap: USD 5.95Push button "On".It has a dedicated off input that can be triggered by your MCU.There are two versions available depending upon your power supply voltage.

author: ajb
author_rank: Super Contributor
timestamp: October 22, 2014, 11:07:50 pm
content: I'm guessing your soft power switch goes between Power- and Power+? What's the purpose of C3 and R4?At lower voltages, the AVR may not be able to hold the gate of Q1N down long enough to allow R3 to fully discharge the gate of Q1P, allowing enough current to flow through Q1P and R5 to turn the latch back on. Try removing or decreasing the value of R6 so that Q1N turns off more quickly and/or decrease the value of R3 to more quickly discharge Q1P's gate.

author: Marco
author_rank: Super Contributor
timestamp: October 22, 2014, 11:19:24 pm
content: Why can't you just get rid of Q1N and pull Q1P's gate down with an open drain I/O? Add a gate resistor to the positive rail, add some capacitance if necessary so if you release the start button before the AVR has finished booting it gets time to pull down the gate and keep power coming. To turn off just stop pulling down the gate, the resistor to the positive rail will turn it off eventually.

author: dannyf
author_rank: Super Contributor
timestamp: October 22, 2014, 11:25:49 pm
content: QuoteTake a look at the AVR transistor tester's power-on/-off circuits.Yours is way too complicated.

author: 0xdeadbeef
author_rank: Super Contributor
timestamp: October 22, 2014, 11:48:01 pm
content: I'm using something like this with 3xAA NiMh batteries (~3.6V).I ripped this out of a larger schematic. Vcc is the battery and Vsw the switched power supply to the microcontroller.When in OFF state, pressing the button will connect the power supply to the microcontroller by switching the P-FET on.At initialization, the microcontroller pulls the powerlatch pin high which then keeps the FET active.Due to the diode, the button level can still be read during runtime. So the button can be also used as off-switch:The microcontroller detects the wish to switch off and pulls the powerlatch pin low -> the P-FET becomes inactive -> power is switched off.Indeed I also implemented a timeout, so after 2h or so without activity, the microcontroller will also pull the powerlatch pin low and thus switch its power off.

author: Jeremyvnc
author_rank: Newbie
timestamp: October 23, 2014, 10:49:53 pm
content: Thanks all for your thoughts on this. For some reason I didn't get any emails when you posted even though I checked "Notify me of replies."@Mr B. The polulu board does indeed do what I need but my overall design isn't large enough to allow that to be integrated as a sub-board. It is sad that they will not open up their design@ajb The Power- and power+ signals do indeed go to either side of a momentary button (membrane switch to be exact). The purpose of C3 and R4 serves to switch the function of the push button. I have jumped out R6 but I will try to decrease R3 tomorrow to see it if allows the p-chan gate to fall faster.@Marco and 0xdeadbeef - I would like to keep it a standalone circuit so that the microcontroller isn't necessary to the power staying on. I just want a way to turn it off after some time.@dannyf - I'm always open for different solutions. I'm not saying this circuit is perfect, it has just always served me well for my on/off needs with systems 9-20V input. This is the first time I've used it with a 3.7V li-ion cell.Should I possibly need to downsize my p-chan/n-chan pair to a smaller Vgs?-Jeremy

author: Jeremyvnc
author_rank: Newbie
timestamp: December 31, 2014, 06:57:27 pm
content: Okay, been away doing other work projects but I'm back to this one now. I've thought about what you guys have said and have tried most of the suggestions. So far I have not been able to make this circuit work with low voltage nor will the suggested adaptions fit my circumstances. I even made a few of the suggested circuits and was about to move ahead with one of them when I realized I can't have the microcontroller latch the system power on. The AVR Transistor Tester on/off circuit and 0xdeadbeef's on/off circuit both require the microcontroller to keep the power on and decide when it goes off. The latter is fine, I want the uC to be able to turn the circuit off. However, I cannot have the uC control the power through a latched pin because if the microcontroller gets reset (such as through a programming cycle for example), the power would drop as well.My goals are to have a simple 1 button momentary pushbutton circuit with 1 press on, 1 press off and have the ability for the microcontroller to shut the circuit down. The power should remain on even if the microcontroller is reset or isn't on. The circuit I posted does exactly that but not at lower voltages (<5). I have tried reducing R3 to as low as 1K, I have tried jumping out R6. I have even tried a lower Vgth N and P channel mosfet pair. The on/off portion works but not the microcontroller turning it off function. The power led just blinks.I found out yesterday that the circuit does work as shown if I don't plug in the xbee radio with a single LiPo cell which leaves the device pretty much just down to the microcontroller.Any thoughts? Is there a way for the microcontroller to hold the pin low longer (which works)? Maybe an NPN transistor with a slow decaying capacitor?

author: Jeremyvnc
author_rank: Newbie
timestamp: December 31, 2014, 09:19:15 pm
content: Small update: if I put the xbee to sleep and turn off the other powered devices, then the auto-off circuit works at 3.0V. Not a fix per se, but it is a pretty good workaround...

author: dannyf
author_rank: Super Contributor
timestamp: December 31, 2014, 10:31:50 pm
content: Give this a try. Here is how it works, when the button is pressed:1) initial state is off: the button turns on Q1, which sends power to the mcu. Once powered on, the mcu will hold MCU_LATCH low and put an interrupt on MCU_SENSE's falling edge (to sense the next button press). You will need to handle debouncing here.2) initial state is on: once a falling edge on MCU_SENSE is detected, MCU_LATCH is released and power to the mcu is cut-off. You will need to handle debouncing as well as any delays here due to capacitance on the power line.The circuit is built on a very important assumption: when powered on, MCU_SENSE will read '1'. That's true at higher voltage but you have to test in your environment.If that doesn't hold, it can also be done, with slightly more complexity.

author: dannyf
author_rank: Super Contributor
timestamp: December 31, 2014, 11:03:04 pm
content: In case that you have a low voltage circuit or you want to use a mosfet for switch, the prior circuit doesn't work anymore - MCU_Sense will not read reliably a '1'.This circuit tries to solve that problem.The pins operate the same as before. R5 is only needed if the pull-up on MCU_Sense isn't available / strong enough.BTW, the base resistor is only needed if a bjt is used as the switch. Not drawn in the prior circuit.

author: Jeremyvnc
author_rank: Newbie
timestamp: January 02, 2015, 04:19:22 pm
content: This idea is very nice and simple but it still relies on the microcontroller to latch (low) the power circuit. The latching needs to be independent of the microcontroller. If I were to reset the controller for this circuit, the power would drop as the normal operation of an I/O pin on an AVR is a high impedance input.I like the simplicity of your circuit but the latching needs to be standalone from the microcontroller.

author: dannyf
author_rank: Super Contributor
timestamp: January 02, 2015, 07:39:38 pm
content: Put a flip-flip there.Or a small mcu dedicated to this job.

author: ion
author_rank: Regular Contributor
timestamp: January 02, 2015, 08:15:31 pm
content: I came across this old EEVBlog a few days ago:Using the microcontroller to ground the circuit between the button and the base of the transistor on the left should turn it off.Perhaps a largish cap across the micro's power pins would delay the reset long enough to turn the transistor off completely.

author: Jeremyvnc
author_rank: Newbie
timestamp: January 05, 2015, 11:05:07 pm
content: Quote from: dannyf on January 02, 2015, 07:39:38 pmA Flip-flop would probably be a good idea, I don't remember why I didn't go that direction (I think it was the input voltage range).The board I'm putting this on is only 1"x 1.5" in size and is very cramped already with other components so a dedicated mcu doesn't seem that feasible.Quote from: ion on January 02, 2015, 08:15:31 pmThat video is actually what got me making a circuit like this right after he posted it. While Dave's circuit does work, it isn't very robust. I wanted to make a circuit that would satisfy the requirements mentioned before but also be robust enough to be a go-to circuit for these needs with a large voltage input range. This is actually the third or fourth revision of the circuit as you see it.Attached is my final fix. I made a simulated (and breadboard) circuit of this and it pulled the N gate low long enough no matter the load and it works at 3V to 13V input voltage.This circuit allows for a momentary push button press to turn on and after about 500ms, another press to turn off the power to the circuit. Also, a kill signal (high) from the microcontroller to kill the power automatically. No microcontroller latching required.This has been tested with power regulators (with 330uF capacitors even) on the Vout side and battery charging circuit outputs on the Vin side.Thank you all for your advice and suggestions. They definitely got me thinking.