Watchdog reset when arduino hangs longer than 5 minutes

Hi there!

I am creating a sketch that needs to be completely fail-proof, since the arduino will be put in a place that isn't easily accessible. It measures the delay between 2 points using a Ethernet shield and a 4G wireless to ethernet converter, Since the connection to the main server might be unstable, the arduino might become unstable too (Unexpected incoming data for example). And then it might lock up. That is a problem when i can't access it. So i need to add a watchdog timer. But you can only go up to a max of 8 seconds! The arduino needs to ping stuff while in the loop and the ping might timeout, which takes like 30 seconds before it says it failed. during that time the arduino won't respond to anything else. Including resetting the watchdog timer. So in case if i do a traceroute from the arduino and it takes a bit long, would mean it would just suddenly restart the arduino. So i need the watchdog to be something like 5 minutes before it resets the arduino. How can i do this when it goes only to a max of 8 seconds?

Thanks in advance! :)

The most obvious method is to set the watchdog timer in interrupt only mode. In watchdog timer Handler (every 8 seconds):

  • you will increment a volatile variable
  • reset watchdog timer whenever this variable is less than a constant corresponding to 5 minutes
  • when (if) this variable is above the constant, you reset the uc.

In your loop, you set the volatile variable to 0 at each beginning of the loop.

ard_newbie: The most obvious method is to set the watchdog timer in interrupt only mode.

AVR watchdogs have a "both" mode which is well suited to solve this problem. The technique is exactly as you described. When the timer reaches zero, don't execute a watchdog reset. The next time around, instead of an interrupt, the processor resets.

Thanks guys!

I'll set the watchdog timer to 1 second and then make it do a interrupt each time it isn't reset, And i'll put that in a integer. Then when the integer is 300 i'll make it do a reset. But i do have one question, can the interrupt break the code while it is for example doing a traceroute? will it mess up the timing of it? I am using a library for the traceroute called PingTrace (link: https://github.com/Tomas-Dolezel/Arduino---TraceRoute)

Wow. He actually put three dashes in the repository name. That is surprisingly annoying.

CrazyVito11: I'll set the watchdog timer to 1 second...

But i do have one question, can the interrupt break the code while it is for example doing a traceroute?

#define PING_TIMEOUT 5000

So that would be at the most six interrupts during the ping timeout period.

~50 machine instrutions / 16000000 instructions per second * 1000000 microseconds per second = ~4µs per interrupt

Over the timeout period the processor will spend ~24µs in the interrupt service routine. That comes out to 4.8e-7% of the processor time spent servicing the interrupt and 99.99999952% of the processor time available for other things like handling the traceroute.

I'm going with "no".

Okay thanks!

I'll update you if i get it to work or not :) Thanks for the help so far!

CrazyVito11: I am creating a sketch that needs to be completely fail-proof

It might be possible to create such a sketch, but of course you could never know if its 'completely fail-proof' as you would need an infinite amout of time to test it.

I suspect you really mean a sketch that is fairly reliable.

Using the processor internal watchdog can help, but if something goes wrong (with the code) before that is setup the internal watchdog is not going to work as required.

An additional independant, timer based watchdog, such as the MAX6369 makes a lot of sense in such applications.