Implementing a watchdog timer to fully reset an MKR WiFi 1010

Hello all,

I am currently trying to find a way to implement some sort of library in order to perform a reset on the whole board. But I want it happening in the “background” so that if the program gets stuck somewhere for 10 minutes then the board can be reset and started over as if it were being powered up.

If anyone has a way of doing this please let me know. I have found other libraries that only allow me to shut off the microcontroller, but it does not wake back up without power cycling.

You’ll want to activate the hardware watchdog. The watchdog on the ATSAMD21G18A chip on the MKR WiFi 1010 is supported by the https://github.com/adafruit/Adafruit_SleepyDog library. You can include it and say

Watchdog.enable(16000 /* ms max period */, false /* for sleep */);

Note the watchdog does not have “10 minutes” maximum time, it’s much shorter than that. Per datasheet, “max 16,000 cycles in normal mode”, whereas one cycle is the cycle of a 1 kHz clock. (I.e., one cycle = 1 / 1024 of a sceond).

Deep-Sleep / Shutdown modes of the micrcontroller can be used independently of the watchdog.

Of course, once you enable the watchdog, you will periodically need to reset it (“feed it”). If that does not happen for the set maximum time, the watchdog will trigger a reboot of the chip. Feeding the watchdog with the Adafruit library can be done with

Watchdog.reset();

Thank you. So basically you are saying that it is not possible to have a watchdog timer longer than 16 seconds?

That is the harwdare limit giving the possible clock dividers, yes.

However, no good programm should with a “superloop” architecture should have a loop iteration that costs more than 16 seconds to run. The watchdog can also be deactivated before deepsleep if needed. (Watchdog.disable();). This should be used with caution however.

Okay that makes sense.

I am working with some libraries that use some WiFi connectivity. And unfortunately some of the functions that I am using within these libraries will occasionally force the program to get stuck.