This question already has an answer here:
I'm trying to create a single button circuit for the purpose of both powering on a microcontroller (probably an arduino) and then allowing the microcrontroller to control its own power (power itself off) and accept further presses of the same button as input ( functionally like the power button on a smartphone: Hold it down when the phone's powered off and it starts. Push it again when the phone's operating and it will bring up your power menu ).
From research it seems MOSFETs might be the way to go, and from reading I've planned a circuit. I have no experience with MOSFETs though (my first batch are on order now), and am not aware of the potential pitfalls. Attached an example circuit regarding which I have a couple of questions.
The intention is: when the button (a momentary switch ) closes the circuit initially, current is allowed to pass through M3 ( P-Channel MOSFET with no voltage at the gate ) through M1 ( N-Channel MOSFET with voltage currently applied to the gate ) and through to VIn. In the MicroControllers setup routine, it asserts D1 high, applying voltage to the gates of both M3 and M2, closing M3 and the startup circuit, and opening M2 which is now the persistent power circuit. The micro-controller can then choose to shutdown by asserting D1 low, which will shut off M2 and cut off the power.
Now the circuit is open and the power is on, the switch can be used as an input to D2.
1) Obviously... should this circuit work in theory?
2) Do I need to protect the MOSFETs against initial power burst with capacitors to ground or equivalent?
3) Is controlling M3 and M2 with the same voltage that they are allowing to pass like trying to pull yourself up with your own shoelaces? Should I buffer the supply in some way?
4) The example circuit at wikipedia shows a resistor connecting the gate to GND. Is this necessary? Should current be allowed to flow past the gate leg of a MOSFET?
5) Is introducing an input voltage to a digital input of a microcontroller before it has programmed its inputs and outputs safe? (Connection to D2 on power up).
---------- Edit 1 ----------
The duplicate question does provide an alternative (and it would seem quite robust circuit ) that achieves what Ive laid out above ( I hadn't found that answer in searching... Sorry ) My aims though with this question are:
1) To establish if this, or a corrected version, is a feasible circuit without the extra step of the regulator. Most arduinos and equivalents already have one on board, without the enable pin.
2) To understand a little more about MOSFETs.
From answers and comments below @Dave Tweed and @Joe Hass, is the the Threshold Voltage subtracted from the voltage across source and Drain then? Ie. If I supply 10V and the nMOSFET has a a threshold of 5V I can expect 5V at drain going to Vin? (And this doesn't happen in reverse with pMOSFETs?)
@Jon Watt thanks for the example. That answers most of what I'm looking to do, minus the digital input signal. A question though that may seem obvious, is R2 essentially a pull down resistor to keep the gate low when no input is applied from CTL?
Ideally this would be a standalone modular power circuit which you could put on a board and interface with any particular uC setup, with just Vin, Gnd, Vout, Shutdown and Input pins. Whether Shutdown and input are high or low logic doesn't really matter.
Also, in case the detail helps, for my particular application at the moment, I'm looking to have absolute power shut off, as this is for devices that should retain their charge over a long time and will only be sporadically used (once a day). So no sleep mode draining even minimal resources.
If I can understand the threshold problem, and nobody thinks this is beyond possibility, I'll have another go at drafting some potential circuits.