gob
New Member
Posts: 1
|
Post by gob on Jul 16, 2018 12:00:07 GMT -8
Hello, I am looking for a power switch to safely turn my pi in and and off.
I was checking out the power save because I am also using a battery so it would be nice to trigger shutdown when the voltage gets too low.
Is there a way to add a switch to the power save or use some other device so that when desired, a safe shutdown command can be executed?
Does the power save use an interrupt code running in order to trigger shutdown?
Thanks.
|
|
|
Post by lbendlin on Jan 16, 2019 7:11:32 GMT -8
Think of it as sawing off the branch you're sitting on. There are USB output boards (like SunControl) that can be directed via GPIO pins to switch off the USB load. However that would result in a power cut, not a clean shutdown. And since the "off" command came from the client that is now, eh, off, there is no real way to "on" it again, ever.
Which leaves the battery voltage monitoring. SunControl can cut the USB power when the voltage is going somewhere below 3.43V - unfortunately the exact value is dependent on a lot of external conditions.
So let's say you decide to do an orderly shutdown of the Raspberry Pi at 3.50V. So far so good. Technically the Pi will still draw power even in that state, eventually draining the battery below 3.43V and triggering the Hysteresis circuit on the SunControl and cutting the USB. Given enough charge at some point that circuit will trigger again, re-enable the USB and start up the Pi.
But you can already see the dilemma - What if you shut down the Pi at 3.5V and then all of a sudden the sun comes blasting and the battery voltage recovers. USB power will stay on , hysteresis will not trigger, and the Pi will continue to be in the shutdown state.
I think what this calls for is a Real Time Clock (RTC) addition to the Pi. PaPiRus have ePaper hats that have a RTC and a pogo pin to revive the Pi host at a given time, assuming the Pi is in shutdown state and that it still has power.
So you would modify your routine to shutdown the Pi at 3.5V, but before that you set a timer for , let's say 1 hour (basically enough time to drain the battery for another 70 mV) to reset the Pi. If the battery did recover during that time the Pi will wake up again. If the battery drained, the hysteresis will have kicked in, cut the USB power, and the RTC circuit would have no target to revive.
One more thing - I don't think a watchdog timer plays a big role here - it is only useful when the Pi crashes, not when needs to be woken up from sleep.
|
|
|
Post by SDL on Jan 16, 2019 12:51:12 GMT -8
|
|
|
Post by lbendlin on Jan 16, 2019 16:24:35 GMT -8
What's the maximum interval the watchdog can wait before panicking? If I shutdown the Pi at 3.5V it will take much longer than 200 seconds to drop the output voltage below the 3.43V hysteresis cutoff.
|
|
|
Post by SDL on Jan 16, 2019 17:48:08 GMT -8
The Watchdog actually triggers the USB PowerControl to go off. It won't come back on until ~3.9V.
BP
|
|
|
Post by lbendlin on Jan 17, 2019 4:59:56 GMT -8
Ah, that makes so much more sense. I always thought that the watchdog would initiate a power cycle of a (supposedly crashed) Pi. But if the watchdog can be made to only switch off the load after the Pi had completed its shutdown and is no longer patting the dog, then that is indeed safe.
I guess this then moves closer to my other topic ("Give hysteresis another chance") as you might be wasting valuable operating time by waiting for the battery to reach 3.9V. I still haven't figured out the full impact of "sun pressure" on the battery voltage reading but from my data it looks like roughly 0.15V difference between no sun and full sun.
|
|
|
Post by SDL on Jan 18, 2019 9:17:54 GMT -8
It will do that also! Either way. If the Pi crashes above the battery 3.9V, it will just reboot.
You need hysteresis in this system. What happens is say your battery gets to 3.6V and the Pi turns on. The voltage on the LiPo will go down (the pi is now running), and will take the voltage down below the 3.4V and you get into this up and down cycle. On / Off On / Off and bye-bye SD card.
The "sun pressure voltage" makes sense to me. The voltage on the battery will be a little higher when it is charging.
BP
|
|
|
Post by lbendlin on Jan 18, 2019 17:45:49 GMT -8
I know you have a formula somewhere, but here's what I came up with for now Adjusted Battery Voltage = 3.43 + (measured voltage - 3.43) * Load wattage / (Load wattage + 0.2 * waste wattage ) Not perfect, but relatively close to what I think the real voltage is. The chart shows the participating components as a zero sum game (incoming energy = outgoing energy) for a day period. O is output wattage, W is waste wattage, loadc is the corrected voltage on the battery. Idle consumption (overnight) is about 500 mW.
|
|