Author Topic: How to do put the Mega into a 1 millisecond low power /sleep mode?  (Read 3145 times)

EdM

  • NewMember
  • *
  • Posts: 33
I have a data logger project, and wherever possible I have been replaced 'delay' statements with 15ms sleeps using the rocket scream library that was modified by one of the forum members here to support the 1284p. This works well for anything 15ms or longer, but I still have a few 1 to 5ms delays in the scrip for things like eeprom page writes, analog reads, etc. 

Is there any way to put these units into low power/sleep modes for times as short as one millisecond?

TomWS

  • Hero Member
  • *****
  • Posts: 1930
Re: How to do put the Mega into a 1 millisecond low power /sleep mode?
« Reply #1 on: May 20, 2015, 06:53:26 PM »
I have a data logger project, and wherever possible I have been replaced 'delay' statements with 15ms sleeps using the rocket scream library that was modified by one of the forum members here to support the 1284p. This works well for anything 15ms or longer, but I still have a few 1 to 5ms delays in the scrip for things like eeprom page writes, analog reads, etc. 

Is there any way to put these units into low power/sleep modes for times as short as one millisecond?
The shortest WDT timeout on the ATmega328P is 16mS.  I suspect it's the same on the 1284P.

T
« Last Edit: May 20, 2015, 06:56:24 PM by TomWS »

EdM

  • NewMember
  • *
  • Posts: 33
Re: How to do put the Mega into a 1 millisecond low power /sleep mode?
« Reply #2 on: May 25, 2015, 02:32:36 AM »
I think I might have found one answer over at:

http://donalmorrissey.blogspot.com/2011/11/sleeping-arduino-part-4-wake-up-via.html

where he lists a Timer1 no prescaler overflow period of 4.09 milliseconds

and

"that timer1's lowest running power mode is IDLE, so when we put the micro-controller to sleep, we need to make sure we don't enter a sleep mode below this, or the timer will be disabled"

I am still trying to understand all the details, but it it looks like at least "idle" modes sleep can be entered for very brief amounts of time. Have not tried it yet though.

EdM

  • NewMember
  • *
  • Posts: 33
Re: How to do put the Mega into a 1 millisecond low power /sleep mode?
« Reply #3 on: May 25, 2015, 02:45:32 AM »
and this might be the next part of the puzzle:

http://www.engblaze.com/microcontroller-tutorial-avr-and-arduino-timer-interrupts/

"there’s another mode of operation for AVR timers. This mode is called Clear Timer on Compare Match, or CTC. Instead of counting until an overflow occurs, the timer compares its count to a value that was previously stored in a register. When the count matches that value, the timer can either set a flag or trigger an interrupt, just like the overflow case."

So I think this means I can get timer 1 down to 1ms in CTC mode...