Author Topic: power latching for mC with few parts?  (Read 1256 times)

0 Members and 1 Guest are viewing this topic.

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
power latching for mC with few parts?
« on: April 15, 2023, 02:05:43 pm »
Hi,
a little project of mine is an arduino based portable watch device. Since it shows time with LEDs and should last several days, I went with the following approach:
The arduinoboard is standard off. Time is kept by an RTC modul (allways on plus backup battery in case of empty main battery). To show the time a pushbutton triggers the latching circuit and the time is read from the RTC and displayed for a set time period (some seconds).
I did used the "power-latch-circuit" (attached).
After doing some research I frankly got more confused than informed. I seems to me there are circuit with less parts.
I did the video of doublec4.
https://www.eevblog.com/forum/beginners/push-button-power-circuit-for-arduino-trying-to-modify-it-for-12v-input/

From my little knowledge it seems to me that the first circuit described there (power_latch_2), I "think" I could reduce that to what I did in "simple_pushbutton_only", given, that I don't need an "off-switch" function from the pushbutton. (I guess I don't even need D1?).

As I was pondering a bit about it, I thought it might be useful to get the device powered on by an alarm from the timer, too. That lead to "pushbutton_alarm"

Did I miss some important parts, that shouldn't be missing?

EDIT: for the bigger picture.
step 1 is to make a tiny latching circuit pcb.
step 2 is my own arduino board. With these functions: samd21 type mC as brain, RTC (temperature compensated) as precise time source, integrated charging logic for the single cell LiPoly power source and the latching circuit for low power consumption. As small as possible with as many I/O ports as possible available.
« Last Edit: April 15, 2023, 02:19:34 pm by mclien »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10220
  • Country: nz
Re: power latching for mC with few parts?
« Reply #1 on: April 15, 2023, 02:21:37 pm »
If using a MCU GPIO to latch power on once a button is pressed you will probably need a capacitor somewhere to add off-delay to ensure a very short button press will hold power on long enough for the MCU's startup delay, which can be quite long depending on the MCU in question and what fuse bits you set.  etc from memory AVRs can be set 4 - 60ms before code starts to run and hence before the GPIO can be set to hold the power on.

If you ever have multiple buttons that can wake up the system all isolated by diodes then pay attention to the diode reverse leakage current. I had an issue once where I used schottkys and the reverse leakage caused from pressing one button would sometimes cause other buttons to read as pressed by back flow through the diodes between buttons.
« Last Edit: April 15, 2023, 02:39:34 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #2 on: April 15, 2023, 02:33:30 pm »
All you need is one MOSFET, one PB switch and a resistor.  The MCU can handle this by itself.

Why do you even need a latch circuit?
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10220
  • Country: nz
Re: power latching for mC with few parts?
« Reply #3 on: April 15, 2023, 02:37:31 pm »
It can get a bit more complex if you have a regulator between the battery and your MCU and so need to take into account voltage differences between the battery voltage on the buttons and the lower regulated voltage the MCU runs at.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #4 on: April 15, 2023, 02:42:07 pm »
Okay, two resistors.
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #5 on: April 15, 2023, 04:11:50 pm »
So, like that?
(regulator is simplified just to mark the differences.)
EDIT:
for the PB off-delay is not needed. User should hold the button till the first LED lights up. (even prevents from accidentally pressing, I guess).
As for activating via alarm from the RTC, I'll first look up, if the RTC can be configured to hold the signal long enough. I intent to have the "power hold pin" on high at boot time (bootloader should be possible to be modified, I think).
EDIT2: I know that one isn't working. (leave it attached for documentation purpose)
« Last Edit: April 17, 2023, 06:34:21 pm by mclien »
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #6 on: April 15, 2023, 07:22:10 pm »
Yeah, that will do.  You could even get rid of R2.

Set the pin to input, turn on weak pull-up and monitor for the button to be pushed, then switch to output and drive it low for as long as you want the display on.

I would not turn the MCU on and off, just the display.  The MCU can be put into low power mode.

Or you could even use two pins to make the programming easier.

BTW, I think Q1 is drawn around the wrong way.
« Last Edit: April 15, 2023, 07:25:43 pm by BillyO »
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #7 on: April 15, 2023, 08:07:17 pm »
You a right about Q1, I noticed that one right after I uploaded the image.

The other thing I noticed: wouldn't my last circuit require the out pin to be "high" to have Q1 closed?
Is that possible with an unpowered mC? (I think not..)

 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #8 on: April 15, 2023, 08:10:35 pm »
That's why I suggested not turning the MCU off. :-+
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #9 on: April 15, 2023, 08:20:00 pm »
Hm, that somehow contradicts the "power cutoff".

Forgive me about the stubbornness to really wanting cut off the power for all unused devices.
So to make it work, I'll need a Transistor with a pulldown R at the base, which will be switched by the output pin.

OR use a N-channel MOSFET in the GND line?
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #10 on: April 15, 2023, 08:34:16 pm »
If Q1 is a P-channel MOSFET then it will be off with the base tied to 3.5V through R1.  When you push the button then it will turn on.  The the MCU needs to hold it low for the duration.  I would not use a 1M resistor though.  10K would be more appropriate.  You will also have to hold the button closed long enough to boot up the MCU.

But I'm still not really on board with having the CPU powered off.  First, there is no real reason for it - the MCU can be put into a sleep mode where it will consume less power than the self discharge rate of the batteries.  Second, the button will bounce turning on and off the MCU possibly dozens of times.  Not sure what the end effect of that will be.

You'll have to use a circuit that latches and that the MCU can turn off.

Anyway, have fun.
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10220
  • Country: nz
Re: power latching for mC with few parts?
« Reply #11 on: April 15, 2023, 10:30:03 pm »
The disadvantage of a software sleep instead of hard power off is protection from crashing. If you want to ensure the system never crashes you have to run the watchdog and wake up periodically to clear it.

You can do full MCU power off, just need cap/caps in the right place to add some turn off delay, So even a short button press causes power on for long enough to start up MCU.
I used the two transistor design, P switch and N to control it.
And you need resistor to ensure any caps will auto-discharge when you are in power off state.

I also had 200nF in series between the mcu output and npn transistor. I forget why I did that but it had a reason. I think it avoids some extra battery drain just due to how all the resistors are configured.

In my application it was 2x AA's boosted to 3.3V so there were some additional considerations to ensure two AAs at 1.0V min each could turn the transistors on even with some voltage lost in the diodes.
Really need 1.8V mosfets or better.
« Last Edit: April 15, 2023, 10:42:11 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
Re: power latching for mC with few parts?
« Reply #12 on: April 16, 2023, 02:15:27 pm »
If you want to switch power for everything, then your circuit in reply #5 will not work.  If the processor did actually power down, its GPIO pins would go to ground through the protection diodes, which would ground the mosfet gate, turning it back on.  So you need the two stage circuit where the GPIO drives an NPN transistor, which in turn drives the mosfet gate.  Then the GPIO must be high to keep the power on.

If you also want to use the RTC's alarm pin to turn on power, and assuming the RTC is the DS3231 or something similar with an active-low open-drain alarm output, then you can tie the alarm pin directly to the mosfet gate.  But you will probably need to remove or disconnect any pullup resistor on the alarm pin on the RTC module since you already have the gate pullup resistor.  The alarm pin will stay low until you communicate with the RTC and clear the alarm flag (again assuming the DS3231).  This works so long as the supply being switched has a lower voltage than the absolute maximum voltage on the alarm pin, which for the DS3231 is 5.5V.

In any case, you need a different mosfet.  The threshold voltage on yours is too high.  You need a logic level mosfet with a threshold voltage of 1V to 1.5V.
 

Offline BillyO

  • Super Contributor
  • ***
  • Posts: 1674
  • Country: ca
Re: power latching for mC with few parts?
« Reply #13 on: April 16, 2023, 02:26:38 pm »
its GPIO pins would go to ground through the protection diodes

No, they wouldn't.
Bill  (Currently a Siglent fanboy)
--------------------------------------------------
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #14 on: April 16, 2023, 09:03:48 pm »
Thanks for the replies. I'll have a deeper look into it, it's just too late for my brain to process...
(Spent most of the time of the weekend to figure out, if all parts will fit size wise for what I planned (Should work, if I use mostly 0402 foodprint for R/C/D parts). RTC will be RV-3032 BTW. Mostly because of the package size and precision.
But the alarm PIN works the same way.
"I'll be back"
« Last Edit: April 16, 2023, 09:18:18 pm by mclien »
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #15 on: April 17, 2023, 07:08:23 pm »
as for the sleep vs. power off: The final board is intended to be a base for small watches to build. Like being the main-board to build differed style wrist watches with a daughter board.
So there might be some other build which has components which need to be turned off alongside the mC. (connected to the +3V8 as representation for Batt+ in the "wake" state).

As Peabody mentioned correctly the RTC modul is active-low, I "think" this circuit should do the trick. (finding the correct components/values that is). It has 1.3V to 5.5V input range hece should be fine directly at the main battery.

The RTC alarm put the pin to low and needs to be put back to high via software, so not "too short" press on that side.

As for the pushbutton: I like the fact that a short button press will not power up the thing, so no "accidental" activating.
The physical button will be placed at the daughter board(s). So switch debounce and off-delay can be placed there.

Side note: I was looking into USB connectors and was surprised how much bigger the usb-c types are compared to the microB types..
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
Re: power latching for mC with few parts?
« Reply #16 on: April 18, 2023, 01:32:24 am »
I would just suggest that you delete R3.  As you have it, it puts the mosfet gate at the midpoint of a voltage divider (with R1), so it doesn't go all the way to ground when the alarm pin goes low.  And R3 doesn't accomplish anything.
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #17 on: April 18, 2023, 05:00:27 pm »
Thanks a lot for that, I'll correct that and will do a bit of bread-boarding with that. (Might take a bit to get there)
 

Offline james_s

  • Super Contributor
  • ***
  • Posts: 21611
  • Country: us
Re: power latching for mC with few parts?
« Reply #18 on: April 18, 2023, 05:26:40 pm »
The right way to do this is just leave the MCU powered all the time and go into low power sleep mode at which point it will draw a few microamps, I have mega328 based devices that run for years off of batteries just going to sleep. You can use a pin change interrupt to wake up the MCU, and if you have any hardware that lacks a low power sleep mode you can use a IO pin to drive a transistor that controls power to those devices.
 

Offline mclienTopic starter

  • Newbie
  • Posts: 8
  • Country: de
Re: power latching for mC with few parts?
« Reply #19 on: April 18, 2023, 07:08:53 pm »
Am I calculating this right?
Self discharge for LiPoly batteries is ~5%/month (at least from what I found).
So for a 200mAh cell, that should be like-. 5% -> 10mAh/month -> 10mAh/750h -> 0.0133mA -> 13.3 µA
deepest sleep mode for the SAMD21 is (according to datasheet) 12.8 µA.
Close call, since there is at least a voltage regulator permanently powered, too.
« Last Edit: April 19, 2023, 06:45:28 am by mclien »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf