Turn-on only latch, turn off with GPIO. Better BOM? - Page 1
Forum section: electronics / beginners

author: disq
author_rank: Newbie
timestamp: July 21, 2022, 11:20:52 am
content: HiI'm looking to implement this in my project:https://electronoobs.com/eng_circuitos_tut61.phpIt's basically a turn-on only latch, which also makes a pin available for the MCU to turn off when it wants to shut down. My plan is to use a double pole switch and use the second pole for button input to the MCU. (The device can be turned on once, after all... closing the first pole while it's already on shouldn't do anything)My question is, what would be a good choice of mosfet and BJTs provided we're only triggering sub-6v (possibly single cell lipo levels, or even less using a CR2032) and the current consumption would be sub-100mA?Also power drain when it's off should be as close to zero as possible.The schematic uses IRF4905 which looks like an absolute overkill in many ways.edit: Related EEVBlog video (with a 10 years younger Dave)

author: langwadt
author_rank: Super Contributor
timestamp: July 21, 2022, 11:51:05 am
content: why not just uses a votlage regulator with a shutdown/enable pin ?

author: gamalot
author_rank: Super Contributor
timestamp: July 21, 2022, 11:57:52 am
content: I use Si2305 or AO3415 for low voltage low current power switch.

author: free_electron
author_rank: Super Contributor
timestamp: July 21, 2022, 01:12:55 pm
content: Here's my go-to circuitPower comes in from the left. the P-MOS Q1 gate is kept high by R1 so it is OFF, no power flows to the power-out node.When pressing SW1 the gate is pulled low through D1 (take care not to exceed the max gate voltage ! you may need a zener clamp on the gate)Transistor Q1 now turns on and power flows. The microprocessor powers up and sets the keep-on signal logic HIGH. this turns on Q2 which now takes over pulling the gate low so power is "latched".When you are pressing SW1 the BUTTON-OUT signal is pulled low through diode D2. R2 provides the pull up of that node.When it's time to siwthc off the micro simply makes the KEEP-ON signal low , cutting its own power.Why two diodes ?- D2 : we do not want power-in to provide leakage to the button-out node. if D2 were missing there would be current from power-in through R1,D1 to button-out. We want R1 as high a value as possible. The leakage could be enough to create a substantial enough voltage drop across R1 so that Q1 would turn on no matter what. D2 blocks that.- D1 : we want to retain the ability to still sense the contact closure even when Q2 is in an on state. when Q2 is on the diode D1 becomes reverse polarized ( the anode is tied to ground through Q2 , the cathode is pulled high through R2 and D2 ) . So Q2 has no impact on the node D1-D2. the logic zero provided by the switch will travel correctly.Implementation : use a double-diode for D1/D2. something like a BAT54C in SOT23 . Two schottky diodes with a common cathode.The two mosfets can be a p-n pair in SOT26 (sot23 with 6 pins)So you end up with a design that has 2 SOT23 style packages and two resistors. So small you could place it on the backside of the board , underneath the pushbutton... If you have a tiny pushbutton : use SOT323 or SOT523 packages...

author: disq
author_rank: Newbie
timestamp: July 21, 2022, 06:50:41 pm
content: QuoteLooks great, my concern would be the necessity to always have the KEEP_ON on, this would mean all code (including bootloader(s)) would have to accomodate this to be able to firmware upgrade for instance. Otherwise I'd have to keep the button pressed while uploading new firmware. That's why I like the solution with latching on the electronics side.Another feature could be hold pushbutton very long (maybe 10 secs?) for hard reset / power cutoff, without involving the mcu. This way if something were to go wrong (crash/loop) and the power can't be cut, at least the user has a recourse, short of pulling the battery.

author: Peabody
author_rank: Super Contributor
timestamp: July 21, 2022, 10:41:28 pm
content: Quote from: disq on July 21, 2022, 06:50:41 pmIf you are flashing firmware, you are connected to your computer in some way - either USB or a programmer, and can provide power through one of those sources. In fact, you wouldn't normally power the processor through this latching circuit when flashing firmware, even if you could.The need to shut down when things get locked up is the reason God invented the watchdog timer. It can shut things down even without holding the button down.Well here's my version of free_electron's circuit. It has a single GPIO pin configured as INPUT_PULLUP, which keeps the lower mosfet on, which keeps the main mosfet on. But the button can also be used as an input on the same pin - since it's in input mode. The button press input may be related to things other that power control, so it becomes more general purpose. But the software could be written to interpret a long press as a signal to shut down.

author: Peabody
author_rank: Super Contributor
timestamp: July 21, 2022, 11:05:47 pm
content: I should add that the IRF4905 would not be suitable for low voltage power such as a single cell lithium. Its threshold voltage has a maximum of 4V, so you cannot be sure the mosfet would even turn on if its gate is grounded. The right TO220 mosfet would have been the NDP6020P if they still made it. I'm afraid you'll have to get an SOT-23 package mosfet such as the DMP1045U (1V threshold), but that may also mean you'll have to get a little SOT-to-DIP adapter board to mount it on. And of course finding anything in stock these days is an adventure.The N-channel could be almost anything, such as a 2N7000 or BS170.

author: disq
author_rank: Newbie
timestamp: July 22, 2022, 07:03:03 pm
content: Quote from: Peabody on July 21, 2022, 10:41:28 pmNot correct in my case as I'm planning BLE OTA updates, but that would be 90% of the cases, yes.I believe the HW already has a watchdog timer and it should be enabled by default, almost forgot about that.INPUT_PULLUP is also a good idea with the diodes. Simple enough.

author: artag
author_rank: Super Contributor
timestamp: July 22, 2022, 08:06:41 pm
content: Quote from: disq on July 21, 2022, 06:50:41 pmYes, this can be a problem. My device, which works in roughly the same way, suffers from this problem even when connected to USB. The problem is that I also shut down if battery is low, and sometimes when I'm programming it I have no battery. So the micro starts up, determines the battery is low, tries to shut itself down (it turns off the keepalive pin and then does a reset) and disappears from USB (it's a 32U4).It requires a fiddly power up sequence, but I end up holding down the power button (a momentary type) while the USB programming proceeds. This keeps it alive while the bootstrap loader runs. Some similar mechanism may work for you, tailored to the specifics of the power switch circuit.Thanks for bringing up the subject. Although I have a working circuit, the designs people have posted contain less components.

author: langwadt
author_rank: Super Contributor
timestamp: July 22, 2022, 11:12:44 pm
content: with a regulator with enable pin

author: disq
author_rank: Newbie
timestamp: July 23, 2022, 11:06:29 am
content: Quote from: langwadt on July 22, 2022, 11:12:44 pmYes, but the power is from a battery, aiming for CR2032, and I'm after saving all the microamps. The module is a nrf52840 so lots of power saving features, but just having the firmware in poweroff mode I couldn't get below 790uA in standby (possibly due to board config) and looking to squeeze more using a plan-b soft latch.

author: langwadt
author_rank: Super Contributor
timestamp: July 23, 2022, 02:12:43 pm
content: Quote from: disq on July 23, 2022, 11:06:29 ama regulator with an enable pin can be the soft latch

author: Doctorandus_P
author_rank: Super Contributor
timestamp: July 23, 2022, 11:25:22 pm
content: If leakage current in the off position is an important design goal, then using a BJT as the main switch can be attractive. BJT's (in general) have lower leakage then MOSfets. I attempted to measure the off current of the ubiquitous transistor tester, but it was below my measurement threshold of about 100nA.BJT's have a Base / Emittor voltage of around 600mV, but when saturated the Collector / Emitter voltage can be well below 200mV, which makes the loss of the main power supply voltage manageable.