Go Down

Topic: Sleep mode - what can be done with Arduino? (Read 8 times) previous topic - next topic

ionito

Context: I have Arduino DueMilaNove, Freeduino, Seeeduino, Mega, and my customized boards. Arduino IDE 0021. Involved processors: ATmega1280 and ATmega328P.

I am very disappointed with the lack of proper power management support of Arduino. I mean, I do not know if I understood correctly the messages related to this topic, but it seems to me that only external events can interrupt the processor.  OK, this is what we expect, but the CLOCK/TIMER... it is always something that we want...

I read a huge number of messages asking for a simple solution, such as, go to sleep (and a start a kind of timer) / the timer timeouts and interrupts the processor / you main application resumes its operation, check stuff, performs actions and go to sleep again...

What I am asking here is the confirmed answers for these questions:

1) If I am using millis() and I RESET the processor, the reference counter is reseted also. If the processor enters into sleep mode for 1minute and wakes up, what occurs with the millis() reference? Is it reseted? Is it resumes from the last counting, therefore causing a real delay of 1min.? Or it continues the correct counting, also considering the 1min-time when the processor was sleeping?

2) Is there "an internal" clock/timer that can be used for sleeping purposes? More specifically, a timer that we can program a certain value for timeout and continues working in sleep mode (eventually waking up the processor)?

3) Assuming that answer (3) is negative, what kind of "feasible" solution (simple to develop and/or cheap to purchase) exists to realize the above scenario?

Thanks for any suggestion or hint!!


Coding Badly

Quote
1) If I am using millis() and I RESET the processor, the reference counter is reseted also. If the processor enters into sleep mode for 1minute and wakes up, what occurs with the millis() reference?

Depends on the sleep mode.  Most modes stop the processor's clock which stops all timer / counters including the one used for millis.

Quote
Is it reseted?

No.  If the processor's clock is stopped, millis is frozen until the processor wakes.  If the processor's clock is not stopped, millis continues counting.

Quote
2) Is there "an internal" clock/timer that can be used for sleeping purposes?

The watchdog timer can be enabled to run independently from the processor's clock.  But the watchdog is very inaccurate.

Quote
More specifically, a timer that we can program a certain value for timeout and continues working in sleep mode (eventually waking up the processor)?

In Idle mode, the clocks run.  In all other modes they do not run except the watchdog timer.

Quote
3) Assuming that answer (3) is negative, what kind of "feasible" solution (simple to develop and/or cheap to purchase) exists to realize the above scenario?

Real time clock.  Watchdog timer.  Or, external crystal driving a timer...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1273507808

MarkT

The 328p datasheet says that the current consumption in power down mode with watchdog timer running is about 6uA at 5V supply, and in idle mode with 16MHz clock about 2.4mA - not so impressive but timers all work.  I don't know why the implementation of delay() doesn't use idle mode - see Enerlib, this seems to give a simple interface to idle mode.

Switching to the internal 128kHz clock gives about 20uA for idle mode - however millis() and delay() will run 128 times slower - possibly this could be made to work with software changes if you don't want accurate clock.

The DS1307 RTC chip might be a nice addition to future Arduino board?

[Of course micropower isn't really attainable on standard Arduino hardware with USB interface chips - but standalone projects and boards like the Mini and Mini Pro could really benefit from some improvement here I think]
[ I won't respond to messages, use the forum please ]

ionito

#3
Dec 04, 2010, 06:10 pm Last Edit: Dec 04, 2010, 06:15 pm by ionito Reason: 1
Thanks for all comments.

After reading the suggestions and mentioned links, I am convinced that the watchdog option is the best general option. It is only a matter of selecting a factor of sleeping/total time. Due to the fact that you are using Timer2 with its known inaccuracy, such solution lacks precision and your application must work well with such clock variation. For instance, does not matter if the factor is actually, say 94%, instead of the planned 95% value.

However, it is not an option for my project. I am heavily millis()-addicted and all my solution is based on this function. Also, my final solution will work with low voltage/low clock (2V @ 2MHz) in a customized board and many of the external clock/timers solutions are still not feasible for me. For instance, many of the RTC solutions work with 3.3 and 5V and I really need to be able to run the ATmega328P under low-battery situation if necessary (normal operation is actually is around 2.7V - nominal voltage of 2 AA batteries).

Therefore, the questions for the forum are very specific now. The sleep modes available at the Arduino IDE are:
    *     SLEEP_MODE_IDLE - the least power savings
    *     SLEEP_MODE_ADC
    *     SLEEP_MODE_PWR_SAVE
    *     SLEEP_MODE_STANDBY
    *     SLEEP_MODE_PWR_DOWN - the most power savings
In order to use millis(), just the SLEEP_MODE_IDLE works OK.

Question 1) If using SLEEP_MODE_IDLE mode, is it possible to individually disable functions such as ADC? If positive, can you give a small code example? What are the functions that we can disable?

Question 2) What is the clock used by millis()? If using SLEEP_MODE_PWR_DOWN mode, is it possible to only enable the clock used by millis()?

Thanks


Coding Badly

Quote
Question 1) If using SLEEP_MODE_IDLE mode, is it possible to individually disable functions such as ADC?

Yes.  Don't forget about the UART, Timer 1, Timer 2, and the BOD.

Quote
If positive, can you give a small code example?

I can't.

Quote
What are the functions that we can disable?

Search for "arduino narcoleptic".
Search this forum for "PRR".
Search this forum for "aden disable adc power"

Quote
Question 2) What is the clock used by millis()?

Timer 0 (zero).

Quote
If using SLEEP_MODE_PWR_DOWN mode, is it possible to only enable the clock used by millis()?

No.  Once you stop the processor's clock, all the timers stop.  Search the datasheet for "9.1 Sleep Modes".

Go Up