Sleep command(s)

Some sleep commands would be handy things to have. Maybe one that used timer interrupts and one that used external interrupts to come out of sleep - perhaps both could be implemented together. There also seems to be some choices as to the level of shutdown one wants to implement.

I've had students who would like to try this out but are put off diving into the AVR code.

This seems like another thing that is implemented on other entry-level microcontroller environments, that seems to be basically worked out, but languishing, in the Arduino environment.

There's a lot of work to do and only so much time to do it. Unfortunately, that means that sometimes things don't get done as quickly as I'd like them to.

If anyone wants to take this up, there's code that should get you started on the playground. You'll need to figure which level(s) of sleep people would like to be able to use and what the API (functions) should be to enable them. Then work out the best way to add it to the core libraries (in the hardware/cores/arduino sub-directory of the Arduino application directory). In addition to discussing it here, you should probably email the developers list to hammer out the final details.

I'm happy to help out and answer questions if someone wants to work on this but is intimidated by the AVR code / datasheet. It would probably be a great learning experience.

I had a quick look at this and noticed that to exit sleep on a timeout requires the use of timer2. Are there guidelines for re-allocating resources in new core functions that are already allocated to exisiting functions?

Not really.

If you put the chip into a sleep mode that exits w/ a timeout using timer 2, do the PWM outputs continue to function while the chip is sleeping? If not, it shouldn't be too hard to use timer 2 for both PWM but also to wake from a timed sleep. If I remember right, the core doesn't actually define any ISR's for the timer 2 overflow (or other) routines, so you could probably use those. In any case, I imagine that the sleep function would be part of the core, if that makes things easier.

For sleep and PWM to use the same timer, the timer PWM register initialisation code would need to be called on wakeup to ensure that the registers have not been changed when setting the sleep timeout period.

Its not obvious to me how one would cleanly reinitialise the timer registers. Wiring.c initialises all the timers in a lump so calling Init is not a good idea once the program is running.I am relatively new to AVRs, is it relatively easy to save and restore all registers for a particular timer?

It should be, I think you can just read them into normal variables and write them back. Or we could split up the init() function so that there are separate initialization functions for each timer. Still it might be better to save and restore in case some has done their own writing to the registers.

I am a bit of a newbie here but in the playground I can only see sleep examples which wake the Arduio up using an external signal and not an internal timer signal. Am I wrong here? I am trying to find a sketch which will allow me to put the Arduino into sleep and then periodically wake up using a timer on the AVR? Any help appreciated.

pp