XMEGA Application Note | |||||
#include "avr_compiler.h"
#include "ccpwrite.h"
#include "rtc32_driver.h"
#include "sleepmgr.h"
#include "lowpower.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 5 |
Configure RTC wakeup period in seconds. | |
#define | SLEEP_MODE SLEEPMGR_DOWN |
#define | USE_RTC |
Functions | |
ISR (RTC32_COMP_vect) | |
int | main (void) |
The main RTC example. |
This file contains an example program which initializes the XMEGA to the least power consuming state, and puts the device to sleep.
By default, the XMEGA is put in POWER-DOWN mode, and wakes up every five seconds. The device stays in ACTIVE mode for 0.5 sec before going back to sleep. This gives a duty cycle of 10%.
The interval timing is done with the 32-bit RTC, clocked by the external 32 kHz crystal oscillator.
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_sleep_example.c.
#define F_CPU 2000000 |
Define the CPU frequency, for use with delay_us(). (2 MHz is default clock.).
Definition at line 99 of file xmega_rtc32_sleep_example.c.
#define RTC_PERIOD 5 |
#define SLEEP_MODE SLEEPMGR_DOWN |
Specify which sleep mode to use.
The default alternatives are:
SLEEPMGR_IDLE - Idle SLEEPMGR_ESTDBY - Extended standby SLEEPMGR_SAVE - Power-save SLEEPMGR_STDBY - Standby SLEEPMGR_DOWN - Power-down
The device can wake itself up from Power-down due to the battery backup module leaving the RTC32 running in all sleep modes.
Definition at line 83 of file xmega_rtc32_sleep_example.c.
Referenced by main().
#define USE_RTC |
Configure if RTC should be used. (Comment out otherwise.)
This wakes the device up at intervals with the specified number of seconds.
Definition at line 92 of file xmega_rtc32_sleep_example.c.
ISR | ( | RTC32_COMP_vect | ) |
int main | ( | void | ) |
The main RTC example.
This function initializes the XMEGA to the least power consuming state, before initializing the sleep manager and RTC32 as configured above.
The main loop doesn't do anything but put the device back to the configured sleep mode after a delay of 0.5 second.
Definition at line 110 of file xmega_rtc32_sleep_example.c.
References CCPWrite(), LOWPOWER_Init(), RTC32_Initialize(), RTC32_Reset(), RTC32_SetCompareIntLevel(), RTC32_ToscEnable(), RTC_PERIOD, SLEEP_MODE, SLEEPMGR_Init(), SLEEPMGR_Lock(), and SLEEPMGR_Sleep().
00111 { 00112 // Initialize to the least power consuming state. 00113 LOWPOWER_Init(); 00114 00115 // Enable EEPROM and Flash power reduction mode. 00116 CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); 00117 00118 // Initialize the sleep manager, lock a sleep mode if configured. 00119 SLEEPMGR_Init(); 00120 #ifdef SLEEP_MODE 00121 SLEEPMGR_Lock( SLEEP_MODE ); 00122 #endif // SLEEP_MODE 00123 00124 // If use of the RTC as interval timer is configured, set it up. 00125 #ifdef USE_RTC 00126 // Clear bit for RTC in PRR (it is set by LOWPOWER_Init()). 00127 PR.PRGEN &= ~PR_RTC_bm; 00128 00129 // Reset the battery backup module. 00130 RTC32_Reset(); 00131 00132 // Configure and enable TOSC, then set up and enable the RTC32 module. 00133 RTC32_ToscEnable( false ); 00134 RTC32_Initialize( RTC_PERIOD, 0, 0 ); 00135 00136 // Enable RTC compare interrupts. 00137 RTC32_SetCompareIntLevel( RTC32_COMPINTLVL_LO_gc ); 00138 PMIC.CTRL |= PMIC_LOLVLEN_bm; 00139 sei(); 00140 #endif // USE_RTC 00141 00142 // Main loop. 00143 do { 00144 /* On wake-up, stay in ACTIVE mode for 0.5 s and then go back to sleep. 00145 * 00146 * In an actual application, you would process events/data here. 00147 */ 00148 delay_us(500000); 00149 00150 // Due to errata, disable Flash power reduction before sleep. 00151 CCPWrite(&NVM.CTRLB, NVM_EPRM_bm); 00152 00153 SLEEPMGR_Sleep(); 00154 00155 // Re-enable Flash power reduction mode after sleep. 00156 CCPWrite(&NVM.CTRLB, NVM_EPRM_bm | NVM_FPRM_bm); 00157 } while (1); 00158 }
Generated on Mon Nov 9 13:44:40 2009 for XMEGA power consumption evaluation code by ![]() |