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.

Single button, power and input

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.

| improve this question | | | | |
  • \$\begingroup\$ Your N-MOSFETs M1 and M2 will not be able to supply the full value of V+ to Vin. Vin will be lower than V+ by the transistor threshold voltage. \$\endgroup\$ – Joe Hass Feb 16 '14 at 2:32
  • \$\begingroup\$ It doesn't make sense for either M1 or M2 to be N-channel MOSFETs; Vin would be reduced by their threshold voltage. They should be P-channel devices, but the switch and resistor need to be swapped for M1 (but then you can't connect it directly to the micro input), and M2 needs a separate control line from the micro (or an inverter) to drive it. \$\endgroup\$ – Dave Tweed Feb 16 '14 at 2:34

The easiest circuit uses a signal level N-channel to pull a power P-channel gate low. The signal-level gate can then be left floating, and be pulled low by a MCU that wants to turn off itself. I've used this myself, and it works reasonably well. There's an intermediate state where there is still power in the filter capacitors after the P-channel switch, but the P-channel is currently on, where the brown-out detect of the MCU will reset it, so you really want the MCU to be active-keep-on instead of active-turn-off. The first thing the MCU does is pull the pin high, and then keep it that way, until it comes time to turn it off.

Latching P-channel on circuit

Note that there will be some current through R5 while on; typically you'd want to take advantage of this for an "ON" LED indicator or something to avoid it going to waste. VSW will default "off" because of R5 pulling the gate of the P-channel power MOSFET high. Pressing ON will turn on the power by pulling the gate of the N-channel high, which in turn turns the gate of the P-channel low. The MCU is assumed to be powered indirectly by the VSW voltage and turn CTL high as soon as it starts. Turning CTL low will turn off the power (VSW).

If you stay below 15V input, then the Zener diode is not needed. If you use more than 20V in (or whatever the VGS of the P-channel MOSFET is) then you will need some circuitry to limit the negative voltage that the P-channel gate sees, such as another Zener. Gates are typically quite voltage sensitive.

| improve this answer | | | | |
  • \$\begingroup\$ I think that you missed the fact that the OP also wants to be able to read the switch directly (as a control input) while the micro is keeping the power on. \$\endgroup\$ – Dave Tweed Feb 16 '14 at 2:29
  • \$\begingroup\$ I see. I suppose another signal level N-channel to pull a pin low, and using the built-in pull-ups that most MCUs have, would work then. \$\endgroup\$ – Jon Watte Feb 18 '14 at 1:21
  • \$\begingroup\$ Also, in the original diagram, the input to D2 is not voltage protected, so if the power voltage is higher than VSS for the MCU, you'll fry it. \$\endgroup\$ – Jon Watte Feb 18 '14 at 1:31
  • \$\begingroup\$ V_SS is usually ground. In the original drawing, it's pretty clear that V+ and V_in are intended to be the same voltage, so no problem. \$\endgroup\$ – Dave Tweed Feb 18 '14 at 13:02
  • \$\begingroup\$ Yes, I meant VDD :-) (D = drain) The problem with switching only the regulated VDD is that the regulator is still powered while the MCU is switched "off" which, in many cases, means that a battery will be drained by the idle current of the regulator even when "off." Thus, you typically want to be switching the battery/source voltage. \$\endgroup\$ – Jon Watte Feb 19 '14 at 22:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.