XMEGA Application Note | |||||
#include "avr_compiler.h"
#include "ccpwrite.h"
#include "sleepmgr.h"
#include "lowpower.h"
#include "rtc_driver.h"
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 (RTC_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. |
This file contains a simple program for measuring the current consumption of the XMEGA 128A1 on the Xplain board 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 RTC and external 32 kHz crystal oscillator as clock source, which should result in less than 1 ľA current consumption.
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 xplain_power_consumption.c.
#define F_CPU 2000000 |
Define the CPU frequency, for use with delay_us(). (2 MHz is default clock.).
Definition at line 75 of file xplain_power_consumption.c.
#define RTC_PERIOD 8 |
Configure RTC wakeup period in seconds. (Approximate if ULP is used..).
Definition at line 71 of file xplain_power_consumption.c.
ISR | ( | RTC_COMP_vect | ) |
RTC compare ISR
This ISR simply updates gState so that the device cycles through the different sleep modes.
Definition at line 151 of file xplain_power_consumption.c.
References gState, SLEEPMGR_DOWN, SLEEPMGR_IDLE, SLEEPMGR_Init(), SLEEPMGR_Lock(), SLEEPMGR_SAVE, and SLEEPMGR_Unlock().
00152 { 00153 switch(gState) { 00154 // The device starts out in active mode. Go to Idle. 00155 case 0: 00156 SLEEPMGR_Lock( SLEEPMGR_IDLE ); 00157 ++gState; 00158 break; 00159 00160 // Power-save follows after Idle. 00161 case 1: 00162 SLEEPMGR_Unlock( SLEEPMGR_IDLE ); 00163 SLEEPMGR_Lock( SLEEPMGR_SAVE ); 00164 ++gState; 00165 break; 00166 00167 // Power-down follows after Power-save. The device won't wake up again. 00168 case 2: 00169 SLEEPMGR_Unlock( SLEEPMGR_SAVE ); 00170 SLEEPMGR_Lock( SLEEPMGR_DOWN ); 00171 ++gState; 00172 break; 00173 00174 // Shouldn't end up here.. Go to Idle. 00175 default: 00176 SLEEPMGR_Init(); 00177 SLEEPMGR_Lock( SLEEPMGR_IDLE ); 00178 gState = 1; 00179 } 00180 }
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 90 of file xplain_power_consumption.c.
References CCPWrite(), gState, LOWPOWER_Init(), RTC_Busy, RTC_Initialize(), RTC_PERIOD, RTC_SetCompareIntLevel(), SLEEPMGR_Init(), and SLEEPMGR_Sleep().
00091 { 00092 // Initialize XMEGA to the least power consuming state on the Xplain board. 00093 LOWPOWER_Init(); 00094 00095 // Enable EEPROM and Flash power reduction mode. 00096 CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); 00097 00098 // Enable pull-down on PORTQ3. 00099 PORTQ.PIN3CTRL = PORT_OPC_PULLDOWN_gc; 00100 // Set PORTB1 as input w/ buffer disabled. 00101 PORTB.PIN1CTRL = PORT_ISC_INPUT_DISABLE_gc; 00102 00103 // Initialize the sleep manager. 00104 SLEEPMGR_Init(); 00105 00106 // Clear bit for RTC in PRR (it is set by LOWPOWER_Init()). 00107 PR.PRGEN &= ~PR_RTC_bm; 00108 00109 // Enable external 32 kHz XTAL oscillator in low-power mode for RTC. 00110 OSC.XOSCCTRL = OSC_XOSCSEL_32KHz_gc | OSC_X32KLPM_bm; 00111 OSC.CTRL |= OSC_XOSCEN_bm; 00112 00113 // Wait for oscillator to stabilize. 00114 do { } while (!( OSC.STATUS & OSC_XOSCRDY_bm )); 00115 00116 // Set the oscillator as clock source for RTC. 00117 CLK.RTCCTRL = CLK_RTCSRC_TOSC_gc | CLK_RTCEN_bm; 00118 00119 // Wait until RTC is ready. 00120 do { } while ( RTC_Busy() ); 00121 00122 // Configure RTC wakeup period. 00123 RTC_Initialize( RTC_PERIOD, 0, RTC_PERIOD-1, RTC_PRESCALER_DIV1024_gc ); 00124 00125 // Enable RTC compare interrupts. 00126 RTC_SetCompareIntLevel( RTC_COMPINTLVL_LO_gc ); 00127 PMIC.CTRL |= PMIC_LOLVLEN_bm; 00128 sei(); 00129 00130 // The device should first spend time in ACTIVE, so wait for 00131 // the RTC compare ISR to change the state. 00132 do { } while(gState == 0); 00133 00134 // Disable Flash power reduction mode due to errata. 00135 // (The device will spend most of its time in sleep from now on, so we 00136 // won't bother clearing/setting FPRM before and after sleep.) 00137 CCPWrite(&NVM.CTRLB, NVM_EPRM_bm); 00138 00139 // Go to sleep. The RTC compare ISR configures the sleep modes. 00140 do { 00141 SLEEPMGR_Sleep(); 00142 } while (1); 00143 }
uint8_t gState = 0 |
Global variable to keep track of which state the program is in.
Definition at line 80 of file xplain_power_consumption.c.
Generated on Mon Nov 9 13:44:43 2009 for XMEGA power consumption evaluation code by ![]() |