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

Thread: Teensy 4.1 deep sleep and watchdog

  1. #1
    Junior Member
    Join Date
    Mar 2021
    Posts
    3

    Teensy 4.1 deep sleep and watchdog

    I'm using a Teensy 4.1 with a watchdog timer set.

    Code:
    WDT_T4<WDT1> wdt;
    I also need to have the Teensy sleep for extended periods so I'm using deepSleep from the Snooze library. The watchdog timer is causing the device to reset when it is put to sleep. Is there a way to disable the watchdog after it has been configured?

    Thanks
    Allan

  2. #2
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,830
    try setting
    Code:
    config.lp_suspend = 1;
    (it's already implemented in the library)

  3. #3
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Snooze has not been implemented for Teensy 4.1. Also I believe that for Teensy 4.0 wake from deep-sleep is via a Teensy Reset.

  4. #4
    Junior Member
    Join Date
    Mar 2021
    Posts
    3
    Quote Originally Posted by BriComp View Post
    Snooze has not been implemented for Teensy 4.1. Also I believe that for Teensy 4.0 wake from deep-sleep is via a Teensy Reset.
    Snooze::deepSleep() seems to be working fine for me. It looks like you must include an instance of SnoozeUSBSerial in the SnoozeBlock but otherwise it appears to work as expected (I'm using the 4_0 version from the hal). I couldn't get hibernate() to work - it seems to hibernate but not wake up - haven't had time to investigate.

  5. #5
    Junior Member
    Join Date
    Mar 2021
    Posts
    3
    That doesn't seem to work. I've tried to make a minimum example, once started I use a serial input to trigger the sleep. With the watchdog removed the sleep works fine. With the watchdog in place the sleep is interrupted and the device resets.
    Code:
    #include <Watchdog_t4.h>
    #include <Snooze.h>
    
    WDT_T4<WDT1> wdt;
    
    SnoozeUSBSerial usb;
    SnoozeAlarm  alarm;
    SnoozeBlock config_teensy40(usb, alarm);
    
    void setup() {
      WDT_timings_t config;
      config.lp_suspend = 1;
      wdt.begin(config);
    
      alarm.setRtcTimer(0, 10, 0);// hour, min, sec
      
      Serial.begin(57600);
      pinMode(LED_BUILTIN, OUTPUT);
      delay(5000);
      Serial.println("Start");
    }
    
    void loop() {
      wdt.feed();
    
      Serial.println("Start loop..");
     
      int who = 0;
      // Sleep when serial input received..
      if (Serial.available())
        who = Snooze.deepSleep(config_teensy40);
      
      // Just so we can see something happening..
      for (int i = 0; i < 4; ++i) {
        digitalWrite(LED_BUILTIN, HIGH);
        delay(200);
        digitalWrite(LED_BUILTIN, LOW);
        delay(200);
      }
    }

  6. #6
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,830
    the suspend function enables it on watchdog register but i think the deepsleep has to stop the clock it uses as well. I am not sure what clocks deepsleep turns off, or if the wdt one is still active (aka not suspended)

  7. #7
    Senior Member duff's Avatar
    Join Date
    Jan 2013
    Location
    Las Vegas
    Posts
    1,027
    Most likely Snooze is turning off the enables for the watchdog clock. Watchdog is not something I took into account when writing the T4 sleep code. I'm sure there are other things that are getting in the way with these two libraries.

    Also the system clocks that get activated in sleep modes are not ones that ever get used in non sleep code, those might not be usable for the watchdog.

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Location
    Cheltenham, UK
    Posts
    298
    Did you have any luck trying to find out why Teensy 4.0 freezes using Snooze and EEPROM.put?

  9. #9
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,830
    I think the alarm is resetting the T4.0, I am using the timer and it is working correctly with the latest commit to WDT_T4:
    Code:
    https://github.com/tonton81/WDT_T4
    Snooze has not been implemented for Teensy 4.1. Also I believe that for Teensy 4.0 wake from deep-sleep is via a Teensy Reset.
    Teensy 4.0/4.1 is same processor, so it'll work on both.

    With the code below, Teensy sees the millis() counter incrementing on a timer wakeup correctly. Using the alarm wakeup version, in about 40 seconds irregardless of alarm value set, Teensy does a complete reset.
    The watchdog config.timeout is set to 1 second, and does not interfere or cause resets with the 5 second timer wakeup

    Code:
    #include <Watchdog_t4.h>
    #include <Snooze.h>
    
    WDT_T4<WDT1> wdt;
    
    SnoozeUSBSerial usb;
    SnoozeTimer     timer;
    //SnoozeAlarm  alarm;
    SnoozeBlock config_teensy40(usb, timer);
    
    void setup() {
      WDT_timings_t config;
      config.lp_suspend = 1;
      config.timeout = 1;
      wdt.begin(config);
    
      //  alarm.setRtcTimer(0, 10, 0);// hour, min, sec
      timer.setTimer(5);// seconds
      Serial.begin(115200);
      pinMode(LED_BUILTIN, OUTPUT);
      delay(2000);
      Serial.println("Start");
    }
    
    void loop() {
      wdt.feed();
      Serial.println(millis());
      int who = 0;
      if (Serial.available()) {
        who = Snooze.deepSleep(config_teensy40);
        delay(500);
        Serial.println(who);
      }
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delay(200);
    }
    EDIT, I'll come back to this tonight don't bother, I broke something :P
    Last edited by tonton81; 03-30-2021 at 06:38 PM.

  10. #10
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,830
    Ok, I had to rush out to work today which is why I said I'll be on this later. I reverted the changes and fixed the library, watchdog is firing at 1second timeout resets if i dont feed it now so thats good, and the 5 second deep sleep does not affect the watchdog, no resets occur and 5 seconds later teensy wakes up to continue printing the millis() counter

    Try the repo again with the sketch above. Let me know

  11. #11
    Senior Member
    Join Date
    Dec 2016
    Location
    Montreal, Canada
    Posts
    3,830
    The alarm one is working as well! I set the alarm for 10 seconds:

    Code:
    #include <Watchdog_t4.h>
    #include <Snooze.h>
    
    WDT_T4<WDT1> wdt;
    
    SnoozeUSBSerial usb;
    SnoozeTimer     timer;
    SnoozeAlarm  alarm;
    SnoozeBlock config_teensy40(usb, alarm);
    //SnoozeBlock config_teensy40(usb, timer);
    
    void setup() {
      WDT_timings_t config;
      config.lp_suspend = 1;
      config.timeout = 1;
      wdt.begin(config);
    
      alarm.setRtcTimer(0, 0, 10);// hour, min, sec
      timer.setTimer(5);// seconds
      Serial.begin(115200);
      pinMode(LED_BUILTIN, OUTPUT);
      //  delay(2000);
      Serial.println("Start");
    }
    
    void loop() {
      wdt.feed();
      Serial.println(millis());
      int who = 0;
      if (Serial.available()) {
        who = Snooze.deepSleep(config_teensy40);
        delay(500);
        Serial.println(who);
      }
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delay(200);
    }

Posting Permissions

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