Friday, 21 June 2019

Simple soft power latching circuit for a microcontroller


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 :




Answer



I've implemented this circuit and it works perfectly on my devices :



When the button is pressed, the microcontroller is powered on. Its firmware is programmed so that it sleeps for about 2 seconds before doing anything. If the button is released during this time, the power is cut off and nothing happens. Otherwise, when the delay is reached, the microcontroller asserts the PW_EN line, forcing the gate of Q1 low to assert the EN pin of the regulator and keep the power on from now on. The button is decoupled from this by D4, so it can be used as an input for any purpose by the microcontroller on the BTN_PW line. The firmware is responsible for detecting a 2-second press on this button and when it does, it performs a clean power off by saving the current state to flash memory, disabling peripherals, and finally, setting PW_EN to low to cut the power off.


In the end, it checks all the requirements I had : configurable timings, no power consumed when OFF, ability to perform a clean power off, BOM reasonably small.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...