Watchdog timer prescaler or every 1 minute?

Hi there,

I’m using the autonomo watchdog timer ( https://github.com/SodaqMoja/Sodaq_wdt ), however I’d like to change the timeout of the watchdog to a period longer then 16 seconds (around 1 minute). I don’t want it every 16 seconds due to power consumption. Is there a way to do this? Could I use a prescaler on the watchdog clock? Or is there another way to achieve this?

Thank you!

Do you actually need the watchdog functionality or just a timed interrupt to wake the board?

If you just need a timed interrupt source, the RTCZero library will provide you with minute resolution repeating alarms. Additionally, you can schedule a one off alarm at a specific time (and even date). By continously rescheduling thealarm it is possible to create any period with a resolution of seconds.

Alternatively, the RTC can be also configured as a counter (instead of a calendar). This can be used for second resolution repeating alarms. However, the existing library (RTCZero) is designed for calendar mode operation.

Thanks Gabriel, for your quick reply. We use the RTC to trigger an alarm every minute and do an action. However we want the watchdog functionality in case of hardware/software malfunctioning.

On line 59 of Sodaq_wdt.cpp you will see the following macro:

GCLK_GENDIV_DIV(4);

This sets the clock divider from the 32kHz OSCULP32K source. Since the DIVSEL bit is set in GENCTRL (on line 71), the divider is set to 2^(p+1) where p is the passed parameter value of 4. In this case, the divider is being set to 32, resulting in a 1kHz clock to the WDT module.

If you increase that parameter to 5, the divider will be 64 and all the WDT periods should be doubled.

I’m am not sure what the limit as I can’t find the documentation on the number of DIV bits the GCLK_WDT GENDIV register has.

Update: WDT_GCLK is a definition in that library which is set to 4 (GCLK4). The GENDIV register of all GCLK units have at least 8 DIV bits, with the exception of GCLK2 which is limited to 4 DIV bits. Additionally, GCLK1 has 16 DIV bits.

Thanks Gabriel, that worked :smile:

I hope that someone (hint Gabriel :wink: ) can explain why my watchdog won’t trigger; loop starts is printed but WDT won’t trigger. Even if i copy paste the example on github it won’t trigger… Could someone give me a hand?

void loop()
{
DIAG_STREAM.println(“Loop Starts”);
// If the WDT interrupt has been triggered
if (sodaq_wdt_flag) {
sodaq_wdt_flag = false;
sodaq_wdt_reset();

DIAG_STREAM.println("WDT interrupt has been triggered");




Get_data_and_send();

// Flash LED
digitalWrite(WDT_LED, HIGH);
sodaq_wdt_safe_delay(LED_FLASH_MS);
digitalWrite(WDT_LED, LOW);

}

// Try and enter sleep mode
systemSleep();
}

Make sure that you are enabling the watch-dog timer, this only needs to be done once probably in setup():

sodaq_wdt_enable(); 

You can pass an optional parameter to that function to change the period. The default is to create an interrupt after one second and reset the board if another second.elapses without a call to reset. For other options see the enum in Sodaq_wdt.h.

Thanks for the quick reply; i copy pasted your example code, that isn’t triggering either…

If the board enters sleep mode, you will not see further messages printed. This is because the USB connection is disabled (and so the terminal session) every time the board enters sleep. You should still see the LED flash though.

Aha, but after x seconds it comes out of sleep; right? Where do i have to put a serial print / request a function in the program (like : Get_data_and_send(); ?

I thought it would execute the void after X seconds?

That code is still being executed, however, the Serial session gets closed when the board enters sleep. It doesn’t automatically reopen the session. That is why you stop seeing the output in the Serial Monitor.

If you add a few second delay after waking, you should be able to open a new session (close and re-open the serial monitor). You should then see the output from a single wake cycle.

Alternatively, skip the sleep stage. You should see the Serial output once per second.

Thanks, Will try ! Makes sense but is a little hard for a beginner without serial :grinning:

In general sleep mode does not work well with debug output via the serial monitor.

Thanks… the combination sleepfunction and the lack of coverage (lorabee) had me going for a while, but i got it :)…