PMIC Issue with Electron

I’ve got two devices in the field (out of 1000+) that seem to be having an issue with their PMICs providing bad data. Our devices sleep often and are attached to both their LiPo battery and through external circuitry a 12V SLA battery.

We use the following (simplified) code to put the device back to sleep if our LiPo is under 20% and we do not have good power from the PMIC:

if (fuelgauge.getSoC() < 20 && pmic.getSystemStatus() & 52) {
   System.sleep(SLEEP_MODE_DEEP, 1200);

*Instead of 52, we should be using 4, but it shouldn’t affect the outcome here

My questions are:

  • If there is an issue with the PMIC, what would the return value be here? A 0 response would put our device to sleep for forever, and I think this is what device-os responds with
  • If I know that 0 is the bad value I need to protect my firmware from, how can I guard against it? Obviously I could change to pmic.getSystemStatus() & 52 || pmic.getSystemStatus() & 0 but this doesn’t seem very elegant
  • On the bq24195, if I’m powering the device through VIN, is there a way to have a legitimate reading of 0 from the bq24195?
  • Any other ideas on how I might guard against this?

Not really an answer to your problem at hand, but a few suggestions

  • just for safety I’d put the binary operation into paretheses (pmic.getSystemStatus() & 52) to ensure order of execution
  • I’d rather use hexadecimal values (or less often binary) for bit masks (e.g. pmic.getSystemStatus() & 0x34) as it makes visualising the bit pattern somewhat easier
  • “A 0 response would put our device to sleep for forever” - why would this be? I only see the device sleeping for 20 minutes and then wake again. Consequently you should have regular intervals where you can take countermeasures of any kind
  • instead of explicitly checking for & 0 you could add some sleep counter which prevents a sleep on every Nth consecutive sleep cycle