Embedded Freaks..

September 20, 2008

AVR Asynchronous Timer: How low can you go ?

Filed under: avr — Tags: — kunilkuda @ 1:17 pm

So, here’s the situation: I need asynchronous timer for the RTC all the time, but I also need the MCU to save its power. How low can the AVR go with just one asynchronous timer (Timer 0) on ?

I’m using this program to test the current consumption


/**
 * AVR asynchronous timer / RTC demo
 *
 * Tested with ATMega128L with:
 * - RTC xtal (32.768 kHz) at TOSC1/PG4 and TOSC2/PG3 pins
 * - Red LED at PA2
 * - Green LED at PA1
 * - Yellow LED at PA0
 */
#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>

/**
 * Initialize Timer 0 as async clock
 */
void initAsyncTimer(void)
{
  // Enable output compare interrupt
  TIMSK |= (1 << OCIE0);

  // Set mode to CTC
  TCCR0 |= (1 << WGM01);

  // Enable asynchronous mode
  ASSR |= (1 << AS0);
}

/**
 * Start timer 0.
 * Enable it to shot periodically with x second interval
 *
 * \param second Interval, from 1 to 7 seconds
 */
void startTimer(uint8_t second)
{
  // We use 32.768kHz / 1024 prescaled clock
  uint16_t temp = second * 32;
  OCR0 = (uint8_t) temp;

  // Start timer with 1024 prescaler
  TCCR0 |= (7 << CS00);
}

/**
 * Stop timer 0.
 */
void stopTimer(void)
{
  TCCR0 &= ~(7 << CS00);
  OCR0 = 0;
}

/**
 * Toggle Yellow LED
 */
void toggleYellowLed(void)
{
  DDRA |= (1 << PA0);

  if ((PORTA & (1 << PA0)) > 0) {
    PORTA &= ~(1 << PA0);
  }
  else {
    PORTA |= (1 << PA0);
  }
}

int main(void)
{
  initAsyncTimer();

  // Start the timer with 7-sec interval
  startTimer(7);
  // Replace with the tested sleep mode
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sei();

  while(1)
  {
    sleep_mode();
  }

  return 0;
}

SIGNAL(SIG_OUTPUT_COMPARE0)
{
  toggleYellowLed();
}

The test needs one thing: the asynchronous timer still works (proved by the LED that blinks every 7-seconds). So, here’s the result for ATMega128L@3.3V – 7.3728Mhz:

  • Without sleeping : 10.6mA
  • Sleeping with IDLE mode : 6.4mA
  • Sleeping with ADC mode: 3.1mA
  • Sleeping with EXT STANDBY mode: 0.5mA
  • Sleeping with POWER SAVE mode: 0.4mA
  • Sleeping with STANDBY mode: 0.5mA (Asynchronous timer no longer works)
  • Sleeping with POWER DOWN mode: 0.3mA (Asynchronous timer no longer works)

Conclusion

  • My board consumes around 300 uA (the power down mode should consumes around couple of uA for the MCU, the rest comes from the board)
  • The lowest current consumption that I can get is: 400 uA (for board + AVR + Asynchronous timer 0).
  • I need better measurement tools other than this multimeter =)
Advertisements

1 Comment »

  1. […] init the timer to shoot periodically using async mode (refer to this post). According to AVR’s datasheet, async clock is enabled until POWER_SAVE mode. So, everytime […]

    Pingback by AVR Uart Library with Auto Power Saving Mode « Embedded Freaks.. — October 3, 2008 @ 8:54 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: