arduino-libraries / RTCZero

RTC Library for SAMD21 based boards
http://arduino.cc/en/Reference/RTC
GNU Lesser General Public License v2.1
77 stars 78 forks source link

Freeze after Standby #33

Closed jamesfahlbusch closed 5 years ago

jamesfahlbusch commented 6 years ago

After waking from the RTCZero Standby the system freezes when I attempt to use interrupts. Is something not being reset after standby? I am using a library called Retick that throttles the loop and utilizes TCC1 and it is getting stuck at the first instance of _WFI() after standby. Are the interrupts not being cleared?

include

include "Arduino.h"

include "retick.h"

define RED 13 // Red LED on Pin #13

define GREEN 8 // Green LED on Pin #8

define VBATPIN A7 // Battery Voltage on Pin A7

// re-defines USB serial from M0 chip so it appears as regular serial

if defined(ARDUINO_SAMD_ZERO) && defined(SERIAL_PORT_USBVIRTUAL)

// Required for Serial on Zero based boards

define Serial SERIAL_PORT_USBVIRTUAL

endif

/////////////// Key Settings ///////////////////

byte hours = 0; byte minutes = 0; byte seconds = 0; byte day = 1; byte month = 1; byte year = 17; byte Start = 0; byte retickRate = 2000;

/////////////// Global Objects //////////////////// RTCZero rtc; // Create RTC object

////////////// Setup /////////////////// void setup() { rtc.begin(); // initialize RTC Serial.begin(9600); while (!Serial); Serial.println("Setup"); rtc.begin(); // initialize RTC rtc.setTime(hours, minutes, seconds); rtc.setDate(day, month, year); rtc.setAlarmTime(hours, minutes, seconds + 20); rtc.setAlarmDate(day, month, year); rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS);

Serial.println("Entering Standby");

rtc.standbyMode();

rtc.disableAlarm(); rtc.detachInterrupt(); rtc.updateAlarms(); delay(5000);

}

///////////////////// Loop ////////////////////// void loop() { //Serial.begin(9600); Serial.println("Entering Loop"); /* Each run-through of tick will be 20ms (50Hz)

///////////////////// ReTick ////////////////////// void tick() {

Serial.println("Entering retick loop");
while(1) {
uint8_t i;
for (i=0; i<2; i++) {
  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
  delay(500);
}
for (i=2; i<10; i++) {
  delay(300);
}

}

}

wjpavalko commented 6 years ago

I'm having a very similar issue. I built a bunch of ocean buoys with the SAMD21 chip on a Adafruit Feather M0. Each buoy will work fine for hrs then eventually hang after going into standby sleep mode. Oddly, some buoys with different hardware configurations (additional sensors) experience this much less often (need to run for weeks).

Any ideas?

` //Put Feather M0 in Standby for 30 sec

Alarm_Time += 30; Alarm_Time = Alarm_Time % 60; rtc1.setAlarmSeconds(Alarm_Time); rtc1.enableAlarm(rtc1.MATCH_SS); rtc1.standbyMode(); // Sleep until next alarm match `

marcobrianza commented 5 years ago

I had similar periodic random issues and proposed this fix https://github.com/arduino-libraries/RTCZero/pull/42

can you please try it?

wjpavalko commented 5 years ago

Ok. I'll see if I can.

I was able to prevent the problem by inserting a short delay (10 ms) into the code right before the call for sleep. Not sure why it works, but it solved the problem I was having. All buoys with that code have now worked continuously without the hang I was seeing.

--Wayne

On Wed, Jan 16, 2019 at 8:42 AM Marco Brianza notifications@github.com wrote:

I had similar periodic random issues and proposed this fix

42 https://github.com/arduino-libraries/RTCZero/pull/42

can you please try it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/arduino-libraries/RTCZero/issues/33#issuecomment-454782692, or mute the thread https://github.com/notifications/unsubscribe-auth/Ae_slvtMuTZvFQSMiOqfd6jJz4hJ6Bowks5vDywxgaJpZM4Q2-25 .