XMEGA_power_consumption.c File Reference

XMEGA power consumption main program file. More...

#include "avr_compiler.h"
#include "lowpower.h"
#include "rtc_driver.h"
#include "clksys_driver.h"
#include <avr/sleep.h>
Include dependency graph for XMEGA_power_consumption.c:

Go to the source code of this file.

Defines

#define F_CPU   2000000UL
#define LEDPORT   PORTD
#define SWITCHPORT   PORTC

Functions

void ASYNC_Init (void)
 Init function for Asynchonous I/O interrupt.
void Disable_RTC (void)
 Disable RTC module.
void Enable_RTC (void)
 Enabel RTC module.
 ISR (PORTC_INT0_vect)
void LED_Init (void)
 LED Blink.
int main (void)
 This is the main routine.
void RTC_Init (void)
 RTC Init.

Variables

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

Detailed Description

XMEGA power consumption main program file.

This file contains a simple program for measuring the current consumption of the ATxmega32A4 on the picoPower board in Active,Idle, Power save and Power down modes.

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).
Application note:
AVR32917: picoPower board
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

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_power_consumption.c.


Define Documentation

#define F_CPU   2000000UL

Definition at line 64 of file XMEGA_power_consumption.c.

#define LEDPORT   PORTD

Definition at line 62 of file XMEGA_power_consumption.c.

Referenced by LED_Init(), and main().

#define SWITCHPORT   PORTC

Definition at line 61 of file XMEGA_power_consumption.c.

Referenced by ASYNC_Init().


Function Documentation

void ASYNC_Init ( void   ) 

Init function for Asynchonous I/O interrupt.

Definition at line 76 of file XMEGA_power_consumption.c.

References SWITCHPORT.

Referenced by main().

00077 {
00078     /* Pin 2 is used as source for interrupt */
00079     SWITCHPORT.INT0MASK  = PIN2_bm;
00080 
00081     /* Input configuaratin as low level */
00082     SWITCHPORT.PIN2CTRL  =  PORT_ISC_LEVEL_gc | PORT_OPC_PULLUP_gc; 
00083       
00084     /* Enable low level interrupt */
00085     SWITCHPORT.INTCTRL   = PORT_INT0LVL_LO_gc;
00086 
00087     /* Enable low leverl interrutp excute */
00088     PMIC.CTRL |= PMIC_LOLVLEX_bm; 
00089 }

void Disable_RTC ( void   ) 

Disable RTC module.

Definition at line 130 of file XMEGA_power_consumption.c.

Referenced by main().

00131 {
00132     PR.PRGEN |= PR_RTC_bm;
00133 }

void Enable_RTC ( void   ) 

Enabel RTC module.

Definition at line 122 of file XMEGA_power_consumption.c.

Referenced by main().

00123 {
00124     /* Clear bit for RTC in PRR (it is set by LOWPOWER_Init()).*/
00125     PR.PRGEN &= ~PR_RTC_bm;
00126 }

ISR ( PORTC_INT0_vect   ) 

Asychronous ISR port C

This ISR simply updates run flag and wake up chip

Definition at line 220 of file XMEGA_power_consumption.c.

References run.

00221 {
00222     run = true;
00223 }

void LED_Init ( void   ) 

LED Blink.

Definition at line 93 of file XMEGA_power_consumption.c.

References LEDPORT.

Referenced by main().

00094 {
00095     LEDPORT.DIR = PIN3_bm | PIN4_bm | PIN5_bm | PIN6_bm; 
00096     LEDPORT.OUT |= PIN3_bm | PIN4_bm | PIN5_bm | PIN6_bm;//on  
00097     delay_us( 500000 ); 
00098     LEDPORT.OUT &= ~(PIN3_bm | PIN4_bm | PIN5_bm | PIN6_bm);//off
00099 }

int main ( void   ) 

This is the main routine.

Definition at line 139 of file XMEGA_power_consumption.c.

References ASYNC_Init(), Disable_RTC(), Enable_RTC(), gState, LED_Init(), LEDPORT, LOWPOWER_Init(), RTC_Init(), and run.

00140 {
00141 
00142     RTC_Init();
00143     LOWPOWER_Init();    
00144     ASYNC_Init();
00145     LED_Init();
00146 
00147     /* ATxmega32a4 A version bug, see Errata */
00148     CCP = 0xd8;
00149     NVM.CTRLB |= 0x06;
00150 
00151     for(;;) {
00152         switch(gState) {
00153             case 0:
00154                 LEDPORT.OUT = (PIN6_bm);
00155                 break;
00156             /* Idle */ 
00157             case 1:
00158                 set_sleep_mode(SLEEP_MODE_IDLE); 
00159                 LEDPORT.OUT = (PIN5_bm);
00160                 break;
00161             /* Power-save */
00162             case 2:
00163                 set_sleep_mode(SLEEP_MODE_PWR_SAVE); 
00164                 LEDPORT.OUT = (PIN4_bm);
00165                 Enable_RTC();
00166                 break;
00167             /* Power-down */
00168             case 3:
00169                 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
00170                 LEDPORT.OUT = (PIN3_bm);
00171                 break;
00172             /* Shouldn't go to here. Go to Idle.*/
00173             default:
00174                 set_sleep_mode(SLEEP_MODE_IDLE); 
00175                 LEDPORT.OUT = (PIN5_bm);
00176     }
00177     sei(); 
00178 
00179     delay_us( 250000 );
00180 
00181     LEDPORT.OUT &= ~(PIN3_bm | PIN4_bm | PIN5_bm | PIN6_bm);//turn off
00182     /* Set pull down to avode light LED */
00183     LEDPORT.PIN3CTRL = 0X0;
00184     LEDPORT.PIN4CTRL = 0X0;
00185     LEDPORT.PIN5CTRL = 0X0;
00186     LEDPORT.PIN6CTRL = 0X0;
00187 
00188     LEDPORT.DIR = 0x0;
00189 
00190     run = false;
00191     if (gState != 0) {
00192         sleep_enable();
00193         sleep_cpu();
00194         sleep_disable();
00195         cli();
00196         /* Wake up from RTC */
00197         if (gState == 2) {
00198             Disable_RTC();
00199         }
00200     } else {
00201         /* Active mode */
00202         while(!run){
00203         };
00204         cli();
00205     }
00206 
00207     LEDPORT.DIR = PIN3_bm | PIN4_bm | PIN5_bm | PIN6_bm;//Pin output
00208     
00209     /* switch status */
00210     gState++;
00211     if (gState > 3) gState =0;      
00212     };
00213 }

Here is the call graph for this function:

void RTC_Init ( void   ) 

RTC Init.

Definition at line 104 of file XMEGA_power_consumption.c.

References RTC_Busy.

Referenced by main().

00105 {
00106     /* Enable external 32 kHz XTAL oscillator in low-power mode for RTC */
00107     OSC.XOSCCTRL = OSC_XOSCSEL_32KHz_gc | OSC_X32KLPM_bm;
00108     OSC.CTRL |= OSC_XOSCEN_bm;
00109 
00110     /* Wait for oscillator to stabilize */
00111     do { } while (!( OSC.STATUS & OSC_XOSCRDY_bm ));
00112     
00113     /* Set the oscillator as clock source for RTC */
00114     CLK.RTCCTRL = CLK_RTCSRC_TOSC_gc | CLK_RTCEN_bm;
00115 
00116     /* Wait until RTC is ready */
00117     do { } while ( RTC_Busy() );
00118 }


Variable Documentation

uint8_t gState = 0

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

Definition at line 69 of file XMEGA_power_consumption.c.

Referenced by main().

volatile bool run = false

Definition at line 70 of file XMEGA_power_consumption.c.

Referenced by ISR(), and main().


Generated on Tue Dec 15 08:39:07 2009 for AVR32917: picoPower borad by  doxygen 1.6.1