Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Watchdog reset fails on quick repeats - Teensy 3.5

  1. #1

    Watchdog reset fails on quick repeats - Teensy 3.5

    Hi

    Teensy 3.5

    I'm using the watchdog timer on a project and find issues with the reset failing when the loop function runs quickly, code example as follows:
    Code:
    void setup() {
      Serial.begin(115200);
      while(!Serial);
    
      noInterrupts();
      WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
      WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
      delayMicroseconds(1);
      WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN;
      WDOG_TOVALH = 0;
      WDOG_TOVALL = 10000;
      WDOG_PRESC = 0;
      interrupts();
    }
    
    void loop() {
      noInterrupts();
      WDOG_REFRESH = 0xA602;
      WDOG_REFRESH = 0xB480;
      interrupts();
    
      Serial.println(WDOG_RSTCNT);
      delayMicroseconds(400);
    }
    The serial monitor reports the restart count due to watchdog timeouts - it will increment every 10 seconds as WDOG_TOVALL is set to 10000 (watchdog clock is 1khz).

    I have found that to get this working I need to put a guard around the reset as follows:
    Code:
      if(WDOG_TMROUTL > 1)
      {
        noInterrupts();
        WDOG_REFRESH = 0xA602;
        WDOG_REFRESH = 0xB480;
        interrupts();
      }
    Not sure this is right - any help welcomed.
    Last edited by David Pinball; 05-11-2021 at 10:11 PM.

  2. #2
    I found the following thread about this:
    https://forum.pjrc.com/threads/25370...Watchdog-Timer

    Maybe an issue with the watchdog sync using the low power oscillator (LPO) - it runs at 1kHz which is slow compared to a program looping not doing much. Ths solution in the thread above guards against quick refreshes using millis > 5 - maybe my solution using WDOG_TMROUTL is a bit tidier?

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    15,067
    Feeding the dog too fast is as bad as not feeding it in time. It seems a delay is required, and noted in the linked thread.
    * update: I must have been Kicking the dog too quickly. Added in conditions for limiting how quickly I could kick the dog and everything works fine. I'll make a little guide for anyone who needs to use a watchdog timer with the Teensy 3.1/3.0 soon.
    This repository has library for watchdog - though readme is sparse the examples show usage:
    github.com/tonton81/WDT_T4

    @luni - is there enough info around to make an appropriate WATCHDOG entry in github.com/TeensyUser/doc/wiki

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •