XMEGA Application Note


xmega_rtc32_power_consumption.c File Reference

XMEGA power consumption validation main program file for 32-bit RTC. More...

#include "avr_compiler.h"
#include "ccpwrite.h"
#include "sleepmgr.h"
#include "lowpower.h"
#include "rtc32_driver.h"

Include dependency graph for xmega_rtc32_power_consumption.c:

Go to the source code of this file.

Defines

#define F_CPU   2000000
 Define the CPU frequency, for use with delay_us(). (2 MHz is default clock.).
#define RTC_PERIOD   8
 Configure RTC wakeup period in seconds. (Approximate if ULP is used..).

Functions

 ISR (RTC32_COMP_vect)
int main (void)
 The main RTC example.

Variables

uint8_t gState = 0
 Global variable to keep track of which state the program is in.


Detailed Description

XMEGA power consumption validation main program file for 32-bit RTC.

This file contains a simple program for measuring the current consumption of XMEGA devices in different sleep modes.
The device cycles through ACTIVE, IDLE, POWER-SAVE and POWER-DOWN modes, spending 8 seconds in each mode.
Note that the device will stay in POWER-DOWN.

The interval timing is done with the 32-bit RTC, clocked by the external 32 kHz crystal oscillator.

Note:
The device is initialized with the LOWPOWER_Init(), which enables pull-up on all I/O pins and disables the JTAG-interface (if configured in lowpower.h). This results in the lowest current consumption if nothing is connected to the I/O pins.
Application note:
AVR1010: Minimizing the power consumption of XMEGA devices
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Revision
2940
Date
2009-11-02 09:55:56 +0100 (ma, 02 nov 2009)

Copyright (c) 2008, Atmel Corporation All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file xmega_rtc32_power_consumption.c.


Define Documentation

#define F_CPU   2000000

Define the CPU frequency, for use with delay_us(). (2 MHz is default clock.).

Definition at line 74 of file xmega_rtc32_power_consumption.c.

#define RTC_PERIOD   8

Configure RTC wakeup period in seconds. (Approximate if ULP is used..).

Definition at line 70 of file xmega_rtc32_power_consumption.c.


Function Documentation

ISR ( RTC32_COMP_vect   ) 

RTC compare ISR

This ISR simply updates gState so that the device cycles through the different sleep modes.

Definition at line 136 of file xmega_rtc32_power_consumption.c.

References gState, RTC32_SetCompareIntLevel(), SLEEPMGR_DOWN, SLEEPMGR_IDLE, SLEEPMGR_Init(), SLEEPMGR_Lock(), SLEEPMGR_SAVE, and SLEEPMGR_Unlock().

00137 {
00138     switch(gState) {
00139         // The device starts out in active mode. Go to Idle.
00140         case 0:
00141             SLEEPMGR_Lock( SLEEPMGR_IDLE );
00142             ++gState;
00143             break;
00144                 
00145         // Power-save follows after Idle.
00146         case 1:
00147             SLEEPMGR_Unlock( SLEEPMGR_IDLE );
00148             SLEEPMGR_Lock( SLEEPMGR_SAVE );
00149             ++gState;
00150             break;
00151                 
00152         // Power-down follows after Power-save.
00153         case 2:
00154             SLEEPMGR_Unlock( SLEEPMGR_SAVE );
00155             SLEEPMGR_Lock( SLEEPMGR_DOWN );
00156             ++gState;
00157 
00158             // Disable interrupt to remain in sleep. (RTC32 will keep running.)
00159             RTC32_SetCompareIntLevel( RTC32_COMPINTLVL_OFF_gc );
00160             break;
00161         
00162         // Shouldn't end up here.. Go to Idle.
00163         default:
00164             SLEEPMGR_Init();
00165             SLEEPMGR_Lock( SLEEPMGR_IDLE );
00166             gState = 1;
00167     }
00168 }

Here is the call graph for this function:

int main ( void   ) 

The main RTC example.

This function initializes the XMEGA to the least power consuming state, before initializing the sleep manager and RTC.
The function waits for gState to change (due to RTC compare ISR), after which an infinite loop is entered in which the device is put to sleep.

Definition at line 89 of file xmega_rtc32_power_consumption.c.

References CCPWrite(), gState, LOWPOWER_Init(), RTC32_Initialize(), RTC32_Reset(), RTC32_SetCompareIntLevel(), RTC32_ToscEnable(), RTC_PERIOD, SLEEPMGR_Init(), and SLEEPMGR_Sleep().

00090 {
00091     // Initialize device to the least power consuming state.
00092     LOWPOWER_Init();
00093     
00094     // Enable Flash and EEPROM power reduction modes.
00095     CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm);
00096     
00097     // Initialize the sleep manager.
00098     SLEEPMGR_Init();
00099 
00100     // Clear bit for RTC in PRR (it is set by LOWPOWER_Init()).
00101     PR.PRGEN &= ~PR_RTC_bm;
00102 
00103     // Reset the battery backup module.
00104     RTC32_Reset();
00105 
00106     // Configure and enable TOSC, then set up and enable the RTC32 module.
00107     RTC32_ToscEnable( false );
00108     RTC32_Initialize( RTC_PERIOD, 0, RTC_PERIOD-1 );
00109 
00110     // Enable RTC compare interrupts.
00111     RTC32_SetCompareIntLevel( RTC32_COMPINTLVL_LO_gc );
00112     PMIC.CTRL |= PMIC_LOLVLEN_bm;
00113     sei();
00114 
00115     // The device should first spend time in ACTIVE, so wait for
00116     // the RTC compare ISR to change the state.
00117     do { } while(gState == 0);
00118     
00119     // Disable Flash power reduction mode due to errata.
00120     // (The device will spend most of its time in sleep from now on, so we
00121     // won't bother clearing/setting FPRM before and after sleep.)
00122     CCPWrite(&NVM.CTRLB, NVM_EPRM_bm);
00123     
00124     // Go to sleep. The RTC compare ISR configures the sleep modes.
00125     do {
00126         SLEEPMGR_Sleep();
00127     } while (1);
00128 }

Here is the call graph for this function:


Variable Documentation

uint8_t gState = 0

Global variable to keep track of which state the program is in.

Definition at line 79 of file xmega_rtc32_power_consumption.c.

@DOC_TITLE@
Generated on Mon Nov 9 13:44:39 2009 for XMEGA power consumption evaluation code by doxygen 1.5.9