Inturrupts and millis() function problem

Hi Peter

No, the idea is that I use millis to give a me a "time" from start of program to an interrupt on INT(0) (low)
Then go back to sleep untill the next event.
But the problem is that millis stops in sleep mode, well by the look of things in any sleep mode.....
I have given samples of ISR programs to see if millis would stay running, but alas no.

So the basic question is
Is there a way to use the Arduino compiler to put it into "a sleep" mode but keep Timer 0 running, and an idea of the code would be nice

regards
James

millis is a function.

A function doesn't "stay running".

So you possibly mean "to see if timer 0 stays running".

If timer 0 stayed running, and it generated an interrupt, after 1.024 mS then the processor would wake up.

You can't have the processor stay asleep, and millis() increment. Simple as that.

Further testing appears to indicate that Timer 0 does not run even in IDLE mode, so my page about power may be wrong about that.

According to the datasheet, Timer 2 stays running if using an external clock source, so you may be able to keep timer 2 as a time keeper. However being an 8 bit timer, you would have to wake up pretty quickly when it overflowed or you wouldn't know how many times it overflowed.

Timer 0 stops on ANY sleep function (Arduino compiler problem !!?)

It's absolutely nothing to do with the compiler. It is what the chip is capable of.

jamesvote:
No, the idea is that I use millis to give a me a "time" from start of program to an interrupt on INT(0) (low)

That's the same thing I am saying: you want the value you get back from millis() after the sleep to reflect the duration of the sleep so that you can use it to determine the real-world elapsed time. Normally, when the Arduino sleeps the value of millis() stops incrementing so that millis() shows how long the Arduino has been running, rather than the elapsed time since it started.

If you want to achieve that then one way to do it is to add the sleep duration to timer0_millis each time you perform a sleep. For example you could write a utility function to do that. If you want the value of millis() to be accurate within the interrupt handler that cause the Arduino to wake then it might be best to do the increment immediately before the sleep rather than after.

Thanks for the advice.
I looked around again and found this interesting Application Note from Atmel about RTC and very low power mode

Regards
James