rocketscream / Low-Power

Low Power Library for Arduino
www.rocketscream.com
1.26k stars 345 forks source link

Using Low-Power with a hardware watchdog? #85

Open Bambofy opened 5 years ago

Bambofy commented 5 years ago

Hi, i need to ping a watchdog frequently to keep the Arduino running.

Am i ok to loop say, 10 times, and perform a SLEEP_60MS multiple times, pinging the watchdog after each sleep?

Bambofy commented 5 years ago

Like this:

 int numberOfLoopsToPerform = (int)numberOfLoopsInDelay;

  for (int i = 0; i < numberOfLoopsToPerform; i++)
  {
    Pin_Interface_WatchdogHeartbeat();

    LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
  }
robervaltaylor commented 4 years ago

Related to #89 ?

mariovaldez commented 3 years ago

Yes, that will work, I use similar code with external watchdog timers (like the TPS3828 or a second MCU). I just would just make sure the external watchdog signal is send not only before sleeping but also on wake up, so your code would be:

  int numberOfLoopsToPerform = (int)numberOfLoopsInDelay;
  for (int i = 0; i < numberOfLoopsToPerform; i++)
  {
    Pin_Interface_WatchdogHeartbeat();
    LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
  }
  Pin_Interface_WatchdogHeartbeat();