AVR Sleep mode and indicator LEDs

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

I was just messing with putting my AVR to sleep and I noted that an indicator LED did not turn off. Then I used my brain for a moment and thought, 'Well why would it?' But I also thought that maybe I'm missing something.

So is it general practice to have a special pre-sleep routine to go around and shut off all the lights before going to sleep? Or am I missing something.

Smiley

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

From the Mega168 Data Sheet:

Quote:
10.10.6 Port Pins
When entering a sleep mode, all port pins should be configured to use minimum power. The most important is then to ensure that no pins drive resistive loads.

When the LED(s) is drawing several orders of magnitude more than the micro then its gotta be lights out if you want to see any power savings.

JC

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

Especially on deep sleep modes (CPU clock off), naturally you must switch off all not needed internal and external loads.
Also it may be needed to check, that some functions are finished prior sleep (e.g. UART transmit).
All these actions I place inside the function "try_sleep()".

An example can be seen here:

http://www.mikrocontroller.net/a...

It's also very important, that you write the complete application at first.
Only, if this was finished and tested, you can start to add power saving modes.

In general I use this 3 step approach on every project:
1. implement the complete function
2. if wanted, add power saving
3. if wanted, add watchdog

If you try to intermix all together at the same time, you are in big trouble and lost completely the control.

Peter

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

smileymicros wrote:
So is it general practice to have a special pre-sleep routine to go around and shut off all the lights before going to sleep? Or am I missing something.
I couldn't say if it's general practice or not but here's an example of what I use. This piece of code does the pre-sleep shutdown thing and put the controller to sleep.

Don

/********************************************************************************

                                     sleep

Note: sleep does not return.  The processor will wakeup from sleep mode via a
watchdog timer reset.

********************************************************************************/

static
void
sleep(
  uint8_t watchdogTimeout
)
{

  // disable interrupts
  cli( );

  // power-down Timer/Counter0
  PRR |= ( 1 << PRTIM0 );

  // disable external interrupt 0
  GIMSK &= ~( 1 << INT0 );

  // turn-off all output pins (except TX_PIN) and pull-ups
  SLEEP_REQ_DDR &= ~( 1 << SLEEP_REQ_BIT );
  DDRB = 0;
  PORTA &= DDRA;
  PORTB &= DDRB;

  // enable watchdog timer
  wdt_enable( watchdogTimeout );

  // sleep
  set_sleep_mode( SLEEP_MODE_PWR_DOWN );
  sleep_mode( );

  // execution doesn't continue from here; watchdog timer reset will wakeup
  // microcontroller
  while( true );

} // end sleep
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it better to turn the pins as output and set them to 0, or as an input with pullup enabled?

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

Depends very much on your hardware but generally i'd say neither . Switch them to input with pullups disabled. The more recent AVRs have a bit in MCUCR to disable all pullups in a row.