Timer (millis()) overflow - reset ?

Hello,

I have a program I'm using to turn on various relays based off of environmental sensing, and I'd also like to be able to activate these relays for a set amount of time if they have not been active for a little while. I'm not using a clock for anything else in this program/application and I thought the millis() timer would be ideal until I realized that it overflows after some time.

I am curious what solutions there are to this problem? Ideally, I'd like my project to be able to not be touched for much longer than the overflow time (I keep reading 49 days) and be able to work without any need for anything to be manually reset.

I thought of two solutions initially, but would like some feedback.

The tfirst of the two solutions was making a sort of 'pseudo-timer' variable, and the second was using timer interrupts. I thought both of these probably have advantages and disadvantages, but I'm quite sure someone's been through this before and would know which one is better.

Any info would be helpful.

Thanks!

LP

Hello,

jengil:
I am curious what solutions there are to this problem?

Blink-without-delay.

Ideally, I'd like my project to be able to not be touched for much longer than the overflow time (I keep reading 49 days) and be able to work without any need for anything to be manually reset.

Uh huh. Blink-without-delay.

The tfirst of the two solutions was making a sort of 'pseudo-timer' variable...

Don't know what that is.

...the second was using timer interrupts.

Bad choice.

I'm quite sure someone's been through this before...

Yup.

...and would know which one is better.

Neither. Blink-without-delay.

Did I mention blink-without-delay would solve the problem?

unsigned long minutes_since_startup = 0L ;

unsigned long last_time = 0L ;

void loop ()
{
  if (millis () - last_time >= 60000L)  // roll-over safe test
  {
    last_time += 60000L ;
    minutes_since_startup ++ ;   // this variable will take over 8 millenia to overflow
  }
  .....
}

Or you could record seconds and put up with 135 years limit of operation...

60000L

L?

An RTC module has the advantage of keeping the time if you lose power.