Samd21 (Adafruit Feather M0) rebooting when sleeping for less than 1000 ms

Hi all,

Overview

I'm trying to develop a low-power IoT project using an Adafruit Feather M0 board in conjunction with the Adafruit_SleepyDog library which uses the watchdog timer. In my project, I'd like to sleep the Samd21 at the end of each loop for 45 ms. However, I find that the microcontroller will reset and go through Setup() again typically within 10 minutes of running. When I change the sleep time to 1000 ms, I haven't noticed any issues with resetting.

Detailed expierment

I wrote a small snippet of code to try and debug this. Below you can see we have the SleepyDog library and SD card library. This code initializes the SD card and then moves onto the main loop, where it will constantly blink an LED and sleep in between toggling (aka. the "heartbeat signal"). Once the program has entered the main loop, I then physically removed the SD card from the board. That way, if and when the program crashes it will fail to initialize the SD card and will be stuck in a while() loop with the LED solid on -- it's kind of like a programming mouse trap :slight_smile:

Note that I had to resort to debugging with the LED rather than the serial monitor because sleeping appears to disable the serial monitor.

I tested four different sleep values with this code: 45, 50, 200, and 1000 ms. The first three all would reset within approximately 10 minutes, while the 1000 ms sleep period kept blinking for greater than 1 hour. It appears that there's something wrong when trying to sleep for short durations on the order of 10's of milliseconds.

The code

#include <Adafruit_SleepyDog.h>     // https://github.com/adafruit/Adafruit_SleepyDog
#include <SPI.h>                    // SPI and SD libraries for SD card
#include <SD.h>

const int period = 45;              // sleep time in milliseconds. values that have crashed within 10 min: 45, 50, 200

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);                                 // setup the "debug" LED, on pin 13
  digitalWrite(LED_BUILTIN, LOW);

  if (!SD.begin(4)) {                                           // initialize SD card with chip select (CS) on pin 4
    digitalWrite(LED_BUILTIN, HIGH);                            // if it detected no SD card, turn LED solid on
    while(1) {}
  }

}

void loop() {                                                   // heartbeat signal

  digitalWrite(LED_BUILTIN, HIGH);
  Watchdog.sleep(period);

  digitalWrite(LED_BUILTIN, LOW);
  Watchdog.sleep(period);

}

Any ideas what's going on, or advice for modifying the SleepyDog library? Appreciate any help on the subject, thanks!

Lili <3

That may just be a characteristic of the hardware, which seems only able to sleep for a limited time:

Read the comments in that example. You' have to study the SAMD data sheet to understand the reason....

Regards,
Ray L.

Hi Ray,

Thanks for the comments!

I wasn't able to gleam any additional insight from the documentation in the sleepdog library, so I'll do more studying of the datasheet.

Best,
Lili