However, @MGeo restarts the timer without ensuring the new values have been first written to SRAM. That's why volatile is necessary.
Thank you, that adds much clarity to the subject.
About this insistence that the millisecond timer be reset: expect the Arduino to react about as violently as I would react if you grabbed my wrist and tried setting the time on my watch.
That's a bit much, particularly considering as programmer it is in the end my watch to set.
------------------------------------
In case others come across this thread with the same question:
After all the input here and my testing and studying of wiring.c, I'm realizing you can in fact reset millis, mostly. The fractional counter variable timer0_fract within wiring.c is used for the microseconds calculation and is declared as follows (in bold italic):
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0;This can not be reached from a sketch. So you can clear most but not all of the counter state variables from a sketch. The only way I can see around this is to modify wiring.c. If that is the case, one would be better off placing a custom millis_reset() in the modified wiring.c. All a bit much for the casual user.
George