Sleep modes - how do you set them up and use them?

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a newbie guide to using the sleep functions, ideally including ADC options?
I've got the following code but don't know if it is going to sleep or not:-

set_sleep_mode(SLEEP_MODE_ADC);
	sleep_enable();
	sei();
	sleep_cpu();
	sleep_disable();

Thanks,
Mark

markah

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

if it is going to sleep or not:

The way the ADC sleep mode works is that you set that mode then you set ADSC (as you do for any conversion). That is when it should sleep while the conversion is occurring.

if experimenting with sleep I'd just try "idle" first and measure current.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
The way the ADC sleep mode works is that you set that mode then you set ADSC (as you do for any conversion). That is when it should sleep while the conversion is occurring.
Are you sure?
In the datasheet, Atmel wrote:
If the ADC is enabled, a conversion starts automatically when this mode is entered.

set_sleep_mode(SLEEP_MODE_ADC);
	sleep_enable();
	sei();
	sleep_cpu();
	sleep_disable();

ADC noise reduction mode is generally used when you want to reduce the effects of noise generated by the CPU core. The CPU clock and the I/O clock are stopped. Only a supported and enabled interrupt can wake from this mode. Timer interrupts (except asynchronous TIMER2 interrupts) cannot do so.

Usually you would enable the ADC interrupt and provide an ISR, perhaps only an empty one:

EMPTY_INTERRUPT(ADC_vect)
...
  ADCSRA |= (1<<ADEN) | (1<<ADIE);
  set_sleep_mode(SLEEP_MODE_ADC);
	sleep_enable();
	sei();
	sleep_cpu();
	sleep_disable();

Note that the ADCSRA |= line above assumes previous configuration of ADC prescaler. You may simply wish to combine this with your own ADCSRA = code elsewhere.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Are you sure?

No. Remembered it the wrong way round - should have checked :oops: