Wake up on power re-applied?

I have a design which is turned on and off via a switch in the main power supply i.e. 5V to the electron is turned on and off as an when the user wants to use the Electron . When 5V is removed from the the Electron the default behavior appears to be to continue running off its battery. Here’s the problem: I don’t want to run the battery down (mainly want to minimize the charge/discharge cycles) and so have put the device to sleep (I have tried various modes and the one shown below was the last) as soon as 5V is no longer present (I used the pmic.GetSystemStatus() within bGetHasExternalPower())).

if (!bGetHasExternalPower()) System.sleep(LOW_BAT_UC,RISING,0); // Go to sleep if still no power
 but wake when the PMIC generates an interrupt

When power is reapplied though, the device does not always wake up and a physical press of the reset button is required. So the question is: what is the most reliable method for ‘turning off’ the Electron (i.e. minimizing battery current draw) yet reliably waking up/restarting as soon as 5V is re-applied?

I haven't tested this, but I'm pretty sure this should work.

When running, monitor the power good flag so you know when the switch is turned off. Disable the BATFET which disconnects the battery from the Electron, causing the Electron to turn off since there's no mains power.

When you wake up, it's because you have mains power. Run the code to reenable the BATFET, reconnecting the battery.

You should use SYSTEM_MODE(SEMI_AUTOMATIC) so you don't connect to cellular before the battery is connected.

This code shows how to enable and disable the BATFET:

3 Likes

Thank you! Fixed! I have spent days and days on this - really could not find anything directly related to ‘power down’. This also fixes the issue of the Electron getting stuck while connecting to the cell tower and power being removed - it would occasionally get ‘stuck’ and I never figured out why - simply killing power by turning of BATFET solves all that! Thanks again.

2 Likes