A circuit that turns itself off. - Page 1
Forum section: electronics / beginners

author: braincat
author_rank: Contributor
timestamp: December 01, 2024, 05:43:56 pm
content: Greetings All,I was looking for a circuit that could turn on an MCU and latch, so that an MCU could then turn the circuit completely off (no battery drain) by setting its pin to logic low. This seems to fit the bill --https://electronics.stackexchange.com/questions/146487/momentary-switch-power-press-to-turn-on-microcontroller-can-turn-itself-off(I am attaching the schematics from that link), and I think I understand how it works. I would appreciate it if more experienced forum members could take a look and confirm that it does what I think it does. Is there a better or simpler way to accomplish the same thing?Thanks!

author: Peabody
author_rank: Super Contributor
timestamp: December 01, 2024, 06:32:50 pm
content: I think there's a potential problem with power off. A0 is switched to output low, and things initially go as planned. But at some point the voltage on Vcc will fall below the point where the processor can stay on, and at that point A0 will switch back to input mode. At that point the voltage on the gate of the N-channel will be re-established by the resistor divider. Then the question is whether that voltage will still be high enough to turn the N-channel back on again. The Vcc voltage doesn't drop immediately to ground, but reduces gradually because of the aggregate bypass capacitance in the circuit. Of course you have the threshold voltage of the 2N7000 working in your favor, and that may be enough to make it work. But in my opinion it's the kind of circuit that may work, but is fundamentally faulty.One question is whether you need the latch at all. Unless the MCU is connected to USB, it should boot pretty fast. Then its first act in setup() would be to bring A0 high to turn on the N-channel. If that doesn't happen fast enough, you could blink the builtin LED as a signal that it's ok to release the button.If you need the button to function as an input after powerup, the circuit below would work. Note that it it requires a high on the GPIO to keep the power on. That will be lost when you switch it to input or to output low, and it will not revert back to high as the Vcc voltage drops.Edit: Another potential problem is that the threshold voltage of the 2N7000 is 0.8V minimum, 2.1V typical, and 3.0V maximum. If the divider is at 2.5V, that may typically work, barely, but there will be some 2N7000s that don't work. So if you have a 3.0V Vth 2N7000 copy, it may not turn on, but if you have a 0.8V Vth copy, it may not turn off.

author: braincat
author_rank: Contributor
timestamp: December 01, 2024, 06:57:41 pm
content: Thank you very much for the comment.

author: braincat
author_rank: Contributor
timestamp: December 01, 2024, 08:21:56 pm
content: ... and your circuit seems to work as intended! thanks again.

author: Ian.M
author_rank: Super Contributor
timestamp: December 01, 2024, 08:32:11 pm
content: Note that bad things happen on powerup of your original circuit - the MCU will typically have internal protection diodes on its inputs, which typically have an abs. max. limit of +/-20 mA for older MCUs and possibly quite a bit less for modern ones. When you press the button you are connecting 5V direct to the input of an unpowered MCU, and there is probably some decoupling capacitance from its Vcc pin to ground, so a rather large current spike, far in excess of its abs. max. ratings will flow through the upper protection diode to charge the decoupling capacitance, before the 2N7000 has time to pull the P-MOSFET gate low and turn it on. The spike is very short duration but may well cause culminative damage. There is also a small risk of it causing latch-up by triggering parasitic SCR structures in the MCU's internal input circuit, causing the MCU to short the switched 5V supply, and possibly destroy itself.Peabody has already shown you a circuit that avoids this problem or you could search these forums for: "soft latch" power switch and you'll find several topics offering better alternatives.