Time Since Start

A sketch to illustrate keeping track of real world time since the board was started or reset. The sketch is based on the millis() function, which returns the number of milliseconds since the Freeduino was reset.

One problem with millis() is that the unsigned long variable it returns will overflow every 9.3 hours. If this overflow is not managed, math in a sketch will break.

Re: Millis Rollover Workaround Reply #1 - 06.09.2007 at 01:06:47 Quote You can access it by putting:

extern unsigned long timer0_overflow_count;

at the top of your sketch. However, there's probably a better way to deal with the overflow. For example, if you just need to be able to get the duration between multiple calls to millis(), you should be able to do a millis() - previous_millis (which should work past the rollover).

Or, you could do something like:

current_millis_value = millis(); m += current_millis_value - previous_millis_value; // should work even when millis rolls over seconds += m / 1000; m = m % 1000; minutes += seconds / 60; seconds = seconds % 60; hours += minutes / 60; minutes = minutes % 60; previous_millis_value = current_millis_value;