Teensy 4.1: WDT_T4 - Explanation of settings

jimmie

Well-known member
Teensy 4.1: WDT_T4 watchdog library - Explanation of settings

I have been using the watchdog Timer library (WDT_4) and find it to be indispensable especially in remote installations.

The library seems to be working but I have never been able to find a good explanation of its settings.

There are basically three settings as you can see below (30, 40, 5500). What is the definition of these settings and their relationship to each other? What are typical values for a Teensy 4.1 application?

Thanks in advance for the community's help.

Code:
  //------------------------------------------
  WDT_timings_t config;
  config.trigger = 30;      
  config.timeout = 40;  
  config.callback = myCallback;
  //------------------------------------------
void feedTheDog()
{
  static uint32_t callback_test = millis();
  if (millis() - callback_test > 5500) {
    callback_test = millis();
    //Serial.println("Feeding ....");
    wdt.feed();       /* comment to stop feeding the watchdog */
  }
}
  //------------------------------------------
 
Last edited:
Two numbers control the function.

That third 5500 is just to limit the repeat calls to wdt.feed() to no more often than 5.5 seconds

Source comments show:
Code:
  config.timeout = constrain(config.timeout, 0.5f, 128.0f); /* timeout to reset */
  config.trigger = constrain(config.trigger, 0.0f, 127.5); /* callback trigger before timeout */

Where timeout is the number of seconds when if not given a wdt.feed the watchdog will reset the Teensy. :: /* timeout to reset */

And trigger is the number of seconds between calling the callback function if provided. :: /* callback trigger before timeout */

If relying on an automated interrupt callback { like feedTheDog() above } it must be called sooner than the timeout to be effective.

Though that callback may still function when the system itself is no longer actually in a fully functional state.
 
Thank you very much @defragster for responding.

So in the code above, feedTheDog() is called by the loop every 5500 ms. If 30 seconds go by and the automated interrupt callback had not been called, the Teensy will reset itself.

I still do not understand how the trigger (in my case (40 sec) works? Is it in this case superfluous since the call will be every 5.5 seconds?

My Teensy is resetting every few hours but I have no practical way of finding out what is causing it because my installation is at a remote location. Could these settings be responsible? How does one select appropriate numbers? In my application, the longest process should not last more than about 3 seconds.

Thanks again.
 
The sample code shows "config.callback = myCallback;" - so the feedTheDog() isn't used as the callback. Seems that was misstated ...

The example feedTheDog() says if called sooner that 5.5 seconds since the last call - do not call wdt.feed.

In this case some place(s) in the code where the system is known to be running it would call feedTheDog() - if that happens at least every 40 seconds the watchdog won't restart. However, some locations may call it 2, 2000 or 20000 times per second - and that 5.5 limit makes sure not to call wdt.feed() TOO often.


The trigger=30 says: execute the callback every 30 seconds.

That would allow the code to 'ignore' calling wdt.feed() and have the callback code take care of that. Having that 'automated' by interrupt relieves the code of doing it - but it also means the callback must have some way of knowing the code is still running as expected and not just always call wdt.feed() as it is possible the program may stop running but that simple interrupt code could keep 'feeding the dog' and not reset when it should.
 
Back
Top