Negative timer numbers in logs + Feather M0 not waking from sleep using RTCZero #588
Replies: 11 comments 1 reply
-
https://arduino.stackexchange.com/questions/12587/how-can-i-handle-the-millis-rollover |
Beta Was this translation helpful? Give feedback.
-
@salvagione, totally, I understand. But in this case I am not doing any manipulation of Perhaps that is being done by one of the previously stated libraries? Using RTCZero, I am sleeping using the code rtc.begin(true); // Initialize RTC
rtc.setEpoch(0); // Use RTC as a second timer instead of calendar
rtc.setAlarmEpoch(rtc.getEpoch() + numSecondsToSleepFor );
rtc.enableAlarm(rtc.MATCH_YYMMDDHHMMSS);
rtc.attachInterrupt(alarmMatch); //just an empty function, to satisfy compiler
rtc.standbyMode(); //going to sleep with this command The sleep time is based on epoch (at least the API) |
Beta Was this translation helpful? Give feedback.
-
@pomplesiegel, the LMIC assumes that micros() and millis() increment and match real time. The Adafruit BSP doesn't give you a way to do this, and the RTC lib doesn't do it either. So... this is not going to work well for you. The primary reason for MCCI having our own BSP for the M0 was to add the required API. If you wait until the LMIC says it's ok to delay for The hack would be to change |
Beta Was this translation helpful? Give feedback.
-
Hmm, have a look at this line and the type/size of the variables that hold the values. rtc.setAlarmEpoch(rtc.getEpoch() + numSecondsToSleepFor ); Does it overflow in about 2 days? |
Beta Was this translation helpful? Give feedback.
-
@salvagione, Thank you for your response. Epoch is set to rtc.setEpoch(0); // Use RTC as a second timer instead of calendar |
Beta Was this translation helpful? Give feedback.
-
@terrillmoore, thank you for the reply! Some (much) of this is a bit over my head :) Our strategy for the last two years (worked well until recently) has been to take this approach: Sleep when we know the transmit has been successful, at the end of os_setTimedCallback(&sendjob, os_getTime() + sec2osticks(1), do_send); Is this strategy no longer functional? Or is the answer already in your response and I'm too thick to figure it out? :) Thank you, |
Beta Was this translation helpful? Give feedback.
-
To clarify, is millis overflow the underlying problem? Also, I searched for |
Beta Was this translation helpful? Give feedback.
-
Sorry, the earlier comment about The LMIC uses Since you are using code from two years ago, it's almost certain that you are being bit by things that have changed.
There are probably two issues.
And maybe:
|
Beta Was this translation helpful? Give feedback.
-
@terrillmoore, got it, thank you! In a way, this issue is actually about two separate things:
As I mentioned earlier, this was a sudden and recent occurrence. In fact, it seems the problem is totally irradiated (crossing fingers) by downgrading RTCZero library from 1.6 to 1.5.2. The time values are now also staying positive, and the device continues to wake up from every sleep. I'm planning to post an issue on RTC, but FYI, downgrading RTCZero solved this particular problem on this particular board. |
Beta Was this translation helpful? Give feedback.
-
@terrillmoore, FYI for good measure I am implementing what you mentioned here. Thank you! I've added this to hal.cpp: static uint32_t addition_in_seconds = 0; //state for our offset
void AddOffsetInSecondsToMicros(uint32_t offsetInSeconds) {
addition_in_seconds = (addition_in_seconds + offsetInSeconds) % UINT_MAX;
}
uint32_t ModifiedMicros(){
return (micros() + addition_in_seconds * 1000000) % UINT_MAX;
} and have changed the usage of uint32_t scaled = ModifiedMicros() >> US_PER_OSTICK_EXPONENT; In my code, after each sleep I call AddOffsetInSecondsToMicros( localCopyOfPersistentData.getTransmitInterval() ); //Advance the clock for LMIC Think that should do the trick? Thanks again for your help |
Beta Was this translation helpful? Give feedback.
-
@pomplesiegel it looks right to me... |
Beta Was this translation helpful? Give feedback.
-
Issue
Adafruit Feather M0 now consistently fails to wake from sleep after many transmits (a day or two of transmits + sleeps every ~10 seconds). Previously this was not an issue, and may be due to an interaction between LMIC + RTCZero's sleep (standbyMode) functionality.
NOTE: This one is a bit complicated, as it involves interaction between various libraries, but represents a common use case, and I'm hoping folks can help.
Strange observation: Seconds before this occurs, negative timestamps can be seen in the logs. See log file below (note that our program prints dots every second for logging purposes):
Are these negative values a clue of something which could be going on, or are they just red herrings?
This exact code used to run fine indefinitely, and the failure (with my test method) often takes more than a day to reproduce, so I'm having a hard time narrowing down the exact culprit.
Thank you for your help!!
Environment
Beta Was this translation helpful? Give feedback.
All reactions