delay overflow

Dear all, I'm starting a project around an Arduino Mega. I have a clock and a compass connected to it. It will be installed in a carousseldoor(big turning one) and will control an art installation with 3 steppermotors and 4 servo's. The installation will be running for months and months.

For interactions I use the connected clock to trigger stuff, but for my pulse generator I'll need some time based way of creating it. This can be timebased on millis() or with the delay() command.

Now for my question; I know that millis() will overflow after +- 50 days. Does the delay() or the delayMicroseconds() command also have a problem like this? Or will arduino be able to 'always run' infinite?

If I may ask, what would you guys recommend?

Thank in advance Rob

While the millis() func overflows, I think you can figure out when it overflows, and then keep track of that. i.e. If you count 5 overflows, system has been running for 5*50 or approx. 250 days.

The delay function, though, does not overflow, as long as the delay is an integer. Same thing for delaymicroseconds. Keep in mind that the delay function disables interrupts, so it basically stops nearly everything else while waiting.

millis() has a rollover because it is running in the background. A delay won't roll over unless you give it a number larger than it can handle. Since delay() uses an unsigned long for the value, it probably has a limit of 50 days or so for the maximum you can delay with a single call.

The millis() rollover can be easily handled with careful programming: http://www.arduino.cc/playground/Code/TimingRollover

I would recommend that you set up all your time based stuff using unsigned long variable_name types, and that you do all your calculations as (later_time - earlier_time), capture the time as time_now = millis(), or time_now = micros(). thus if you do a calculation near a rollover (say at 0x0000 0100) and subtract one from before the rollover (say 0xFFFF FF10), the math will work out correctly: 0000 0100 - FFFF FF10 = 0000 01F0, since only 32 bits are used.

delay(time) is milliseconds of delay delayMicroseconds(time) is microseconds of delay

Thus you could run infinitely.

Dear all, Thank for the super fast reactions!

Delay holds everything as 'baum' mentions. For me that is no problem at all. The delay I'll be using will be just a few milliseconds. What the installation has to do depends on time that comes from an external i2c clock. For other calculations like averages I'll use the mainloop and a few int() counters.

@crossroads: Very nice way of using time based stuff. But hexidecimal is not my thing yet.

Thank you all very much for you expertise. It will make me sleep better at night!

Rob.