Tutorial: Basic Watchdog Timer Setup

Hello!

I was thinking to use the WDT to "reset" the oscillator in Tiny, because my app is using millis() all the time, however, I am wondering, if millis() can take 40 and more days before it goes "ballistic", than I am not worried, however, I am wondering should some kind of a protection with regard to time be put in place, something like the one that is below, or should I not worried, because I expect the user to use the product in 40 days :), and then the mills() is "reseted"... anyway, I would like to have a stable loop !

Any kind of advice would be useful :slight_smile:

Best.

nickgammon:
The millis() overflow can be neatly handled like this:

// static variable

unsigned long lastFiredTime;

...

// in loop or some such place
unsigned long now = millis ();
unsigned long interval = now - lastFiredTime;
lastFiredTime = now;




Because of the way unsigned integers overflow, the variable "interval" will be correct, regardless of whether millis() has overflowed or not. That is, unless the interval itself exceeds 49.7 days (because that is all that will fit in it).

Certainly nothing freezes if it overflows, it is just an integer arithmetic overflow. They happen all the time.