Why is the watchdog biting to quickly?

Hello, currently trying to implement a watchdog into my project. I am using the WDTZero library for controlling the watchdog on my MKR NB 1500. The program is trying to measure data, send it to a server, go to sleep, wake up, and repeat the process. Sometimes the code can hang if it can't connect to the NTP server or the server on which the data is being stored, I want the watchdog to reset the program in cases in which this happens.

A sketch of the program is below. The reason why the NB network is often after different connections is that the NB 1500 is not able to connect to another server if the GPRS connection is already open, so I always reset it before trying another connection.

void setup()
{
    setup_watchdog(); //Sets up the watchdog timer
    delay(1000);
    connect_GPRS_NB(); //Connects to the NB network and opens a GPRS connection
    request_NTP(); //Requests epoch1970 from the NTP server and then closes the connection
    timezone_adjustment(); //Adjusts the epoch time to my timezone (in Norway)
    set_RTC(); //Activates the SAMD21 RTC with this timezone adjusted time
    disconnect_NB(); //Disconnects from the NB network
    delay(2000); 
    MyWatchDoggy.clear(); //Resets the watchdog timer
    }

void loop()
{   
    connect_GPRS_NB(); //Connects to the NB network and opens a GPRS connection
    get_ENV_data(); //Takes measurements using the MKR NB ENV shield
    connect_to_server(); //Connects to the server in which the data will be stored
    write_to_server(); //Writes the data on the server
    disconnect_from_server(); //Disconnects from the server
    disconnect_NB(); //Disconnects from the NB network
   
    LowPower.deepSleep(300000); //Goes to deep sleep for 5 minutes
    delay(3000);
    MyWatchDoggy.clear(); //Resets the watchdog timer
}

All the functions above are written in other .cpp files and imported thru header files into the main file. Here is the code for activating and configuring the watchdog:

#include "watchdog.hpp"
#include "GPRS_NB_connection.hpp"

WDTZero MyWatchDoggy;

void setup_watchdog()
{
    MyWatchDoggy.attachShutdown(NVIC_SystemReset); //calls reset function
    MyWatchDoggy.setup(WDT_SOFTCYCLE8M); //8 minute watchdog timer
}

The program works fine in the way described at the top of the post when the watchdog is not included. But when including the watchdog, it bites after 30 seconds when the dog only should have bit after 8 minutes. I see this because data is being sent about every 25-30 seconds to the server.
At first, I thought I had not activated the watchdog in the right way, so I wrote another program to test it:

#include <Arduino.h>
#include <WDTZero.h>
#include <RTCZero.h>


WDTZero MyWatchDoggy;
RTCZero rtc;

void set_RTC()
{
    rtc.begin();
    rtc.setYear(0);
    rtc.setMonth(0);
    rtc.setDay(0);
    rtc.setHours(0);
    rtc.setMinutes(0);
    rtc.setSeconds(0);
}

void shutdown()
{
    Serial.println("Shutting down");
    
}

void setup()
{
    Serial.begin(9600);
    while (!Serial)
    {

    }
    Serial.println("Starting up Arduino");
    MyWatchDoggy.attachShutdown(shutdown);
    MyWatchDoggy.setup(WDT_SOFTCYCLE8M);
    set_RTC();

}

void loop()
{
    Serial.print(rtc.getMinutes());
    Serial.print("/");
    Serial.print(rtc.getSeconds());
    Serial.println("");
    delay(1000);
}

But in this program the watchdog bites after about 8 minutes as it should.

I have not included the code for the functions described in the first code since I know they work without the watchdog and the code itself is very long. But if you think the problem could be caused by these functions for some reason, I will edit the post and include all the function codes.

If it comes to that do not edit a previous post, just add a new post with the new info.  Editing earlier posts that have been replied to can sow confusion and irritate people.

Then the problem is most likely in the code you did not post. Writing past array bounds comes to mind, which leads to unpredictable errors.

The problem did not lie in the code. It had to do with the watchdog timer looping shorter watchdog times to achieve a longer timer. This does not work if the MCU is put to sleep, it's solved by just disabling the watchdog timer before sleep. But thanks anyway.

Will do that next time. I just didn't want to ask anyone to read thru hundreds of lines of code when the problem probably (and did not) lie there.

Still posting snippets, I see.

Do keep us informed of your adventures!

Apologies for reviving this old thread. Did you find the same issue with the dog going to lowpower.deepsleep() along with the CPU when using hard cycles on your watchdog?

Please note: With SOFT Cycle the SAMD21 is interupted which can lead to data loss from the AT connection to the modem. I learnt it the hard way. Example: If you are downloading data and while receiving the data from the modem (reading the buffer from the TCP connection) the CPU is beeing interupted, some bytes will be lost. I don't recommmend any watchdog with SOFT cycle on MKR1400 or MKR1500.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.