Go Down

Topic: Sleep Function (not delay) (Read 869 times) previous topic - next topic

chrios

I was wondering if anyone knew how one might program a sleep function that actually sleeps the arduino microprocessor and wakes up after a preset number of milliseconds or clock cycles.  I would imagine this could be done with the watchdog timer.  Basically, I don't want to use the delay function, as that is just a while loop. I really want to sleep the chip (for power saving reasons) and wait for a timed interrupt.

Any advice or code would be greatly appreciated,
Chris



trialex

Hey.

I had the same request...

Matthias really helped me out. The code he posted (and I adapted for my project) is here

http://gonium.net/md/2006/12/27/i-will-think-before-i-code/

It's not technically a "sleep" state, but it's relatively low power, and then a timer interrupt is used to run a function at regular intervals.

Have a look at the code, I'd be happy to try to answer any questions using my limited experience.

Note the code is for ATMega8, some of the register names would need to be changed to get it working with a Mega168

Cheater

Not sure about waking up at a certain time but there is code to sleep the processor on the playground and wake it up with a interrupt.

Go Up