Watch dog timer along with RTC and sleep...?

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
bretthoward
 
Posts: 37
Joined: Thu Dec 21, 2017 8:47 pm

Watch dog timer along with RTC and sleep...?

Post by bretthoward »

So I have a project that is going to be installed at the top of a sailboat mast and I'd like for it to be brick 54!7house reliable. I also need it to be fairly low power especially when not in use. The unit will be battery powered with a very small solar panel to keep things topped up.

The board I'm using is a RF95 Lora M0 feather. Currently the unit wakes up transmits a single message and waits for a reply. If it gets a reply it goes into a high frequency transmission of data. If it doesn't hear back it sets an alarm in the RTC for 1 minute later and goes back to sleep.

Code: Select all

void isrRTC() {
  //update the alarmtime and return to loop (which will put us to sleep again).
  rtc.setAlarmTime(rtc.getHours(), (rtc.getMinutes()+SLEEPMINS)%60, (rtc.getSeconds()+SLEEPSECS)%60);
  awake = false;
  firstDatum = true;
  messagesMissed = 0;
  messagesMissedAlotment = MISSED_BEFORE_SLEEP_DOZE;
}
My RTC handler is as follows it essentially hits the snooze button by setting the alarm to a later time based on what is in SLEEPMINS and SLEEPSECS. It then makes sure that the awake bool is set to false. It turns on firstDatum which is used to throwout the first set of data because usually the timers are confused when waking up from standby mode. Then it resets the missed message allotments. Essentially if we're awake it takes 60 messages to be missed before going to sleep but if we were asleep it only takes 1 or 2 tries before giving up. That is done because sometimes the base unit is too busy to reply. Also 60 is high enough that I can upload a new version and still have the transmitter awake by the time I get back around...

Anyway so far this all works pretty well.... What I wonder.... Is there any way to have a watch dog added to this that can detect if things have gone sideways at a long time interval and reset the system to ensure it continues running reliably or am I kind of no longer able to really use the watch dog because of the standby mode stuff.

I'm using the RTCZero library from here (https://github.com/arduino-libraries/RTCZero) to use the built in RTC and using the rtc.standbyMode(); along with rf95.sleep(); in order to get into my low power mode which draws about 4mA. Still wish to get that lower but I think it'll take a lot of power supply changes.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Watch dog timer along with RTC and sleep...?

Post by adafruit_support_mike »

You'll probably have better luck with the TPL5110 breakout:

https://www.adafruit.com/product/3435

It's designed for exactly that kind of application, but has a couple of advantages over running a microcontroller in a low-power mode:


First, it uses a lot less power. If you cut the trace to the 'power on' LED, it draws less than 100nA while waiting. That's at least a couple orders of magnitude below what a microcontroller can do.

Second, the microcontroller powers up fresh every time. If something does go wrong and the microcontroller hangs, the TPL5110 will eventually time out, cut power, and reboot the board for another counting cycle.

User avatar
bretthoward
 
Posts: 37
Joined: Thu Dec 21, 2017 8:47 pm

Re: Watch dog timer along with RTC and sleep...?

Post by bretthoward »

I don't see a way for the processor to disable the timer while it is inits running mode. Essentially what I need is the ability to go to sleep and wake up a minute later then try something if it works then I wake up and stay awake until I'm no longer getting ACK's to transmitted messages. As long as ACKs are coming back it will stay on for ever in high speed transmission mode. I already have this all working perfectly with the RTC in the Zero and I get fairly low power but what I'm looking for is a trustworthy backup because this will be mounted in a very difficult to get to location. That board is close but I need a way to programmatically keep kicking it if I want to stay awake.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Watch dog timer along with RTC and sleep...?

Post by adafruit_support_mike »

Ah, I see what you're doing.

The M0 does have an internal watchdog timer that forces a reset if it times out. The basic idea is to set the timer before doing an operation that can hang, start the operation, then disable the timer as soon as the operation is done. As long as you shut it off before it trips, nothing happens. If the system hangs, the watchdog will time out and reboot the microcontroller.

Our SleepyDog library provides convenient wrappers for the watchdog:

https://github.com/adafruit/Adafruit_SleepyDog

User avatar
bretthoward
 
Posts: 37
Joined: Thu Dec 21, 2017 8:47 pm

Re: Watch dog timer along with RTC and sleep...?

Post by bretthoward »

Hrm. Still doesn't look like it'll get me there.... The RTC and the WDT are separate so I can use the WDT and the RTC at the same time but the longest configurable WDT timeout is 16 seconds. Considering that I put the unit to sleep and it doesn't wake up until the RTC alarm a minute later it'll never wake up and will just get kicked in the head by the WDT even if its functioning properly. I suppose I could however start the WDT while I'm awake and turn it off when I go to sleep and that will give me an ever so slight improvement in reliability. I'll take whatever I can get so it'll totally be worth the time for me to implement that! Looks like sleepy dog will be the next inclusion into that piece of the puzzle!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Watch dog timer along with RTC and sleep...?

Post by adafruit_support_mike »

It sounds like the operating conditions you've described will be impossible to bulletproof completely: if the microcontroller can decide to remain active in a way that overrides any external signal, it can hang in that state and be impossible to recover.

If you want bulletproof recovery, you need a signal the code can't override.

User avatar
bretthoward
 
Posts: 37
Joined: Thu Dec 21, 2017 8:47 pm

Re: Watch dog timer along with RTC and sleep...?

Post by bretthoward »

Yea maybe I should just try and build a little analog circuit that resets when it detects an RF transmission from the LoRa radio. If it stops transmitting that should at least kick it in the head if its quiet for too long...

Thanks for the ideas!

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”