I'm building a simple device with a microcontroller and I'd like to be able to turn it on and off using the "hold a pushbutton for 2 seconds" trick that is found on so many consumer devices nowadays (bluetooth headset, USB powerbank, smartphone.. come to mind). This feature seems to be called "soft power latching" but all the schematics I can find to implement it have drawbacks that make them impractical for such application, such as :
- overly complicated, too many components for a small PCB such as found in a bluetooth hand-free headset
- sometimes erratic behaviour in some borderline use cases such as a peak of current draw
- need two separate buttons for on and off, or act as immediate response and do not allow for a 2-second-ish delay
- a non-negligeable amount of current is consumed either at the on or off state, or both.
I thought such feature would easily be found implemented in a small IC for such applications, for example one with a pulled-up input for the push button, an external resistor/capacitor to configure the delay, and an open-drain output to control a pass-transistor or an EN pin. A Clear input pin to allow a software shutdown, a way to be able to use the pushbutton by the microcontroller as a user input, and a way to detect an imminent shutdown to perform a cleanup routine, would also be necessary in my case. However I fail to find such chip (granted I might not be using the right keywords). The closest I've found is the MAX16054 but it is a bit expensive for such feature and doesn't allow for the 2-second-hold delay (adding a capacitor beside the button seems a bit hacky because it would rely on the activation voltage of the IN pin).
I've therefore imagined a simpler/smaller/cheaper circuit that looks like it would match all the requirements but I'd like an external opinion on it, because it doesn't feel right that I can't find anything similar documented anywhere for such a useful and widespread feature :
It works like this :
- the LDO's EN is pulled low by R3 and Q1 is pulled in a blocking state by R2, ensuring the LDO is off by default
- when the button is pressed Q1's grid is pulled low, making it conductive and pulling EN high, which powers on the microcontroller
- the MCU waits for two seconds then ouputs a low state on its PIN0 to permanently enable the LDO even if the button is released, allowing the delayed-latching behaviour (if the button is released before the delay, there is no latching : the LDO is disabled immediately)
- the voltage across the button is pulled high again by R1 and made independent from Q1's grid by D1, allowing it to be used by the MCU through PIN1
- the software is responsible for implementing the turn-off behaviour as required by reading PIN1 and releasing PIN0 to shutdown itself after doing the required clean-up
My questions are therefore :
- would this circuit work and are there drawbacks I'm not thinking of?
- why this kind of simple and useful IC doesn't exist and how is it implemented in consumer devices? (or alternatively, am I bad at searching?)
Edit : the circuit above will not work because the ESD diodes in the microcontroller will pull the lines low when the LDO is disabled (thanks @ElliotAlderson for pointing it out). Here is an updated version which should address the issue :