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 main.c.
#include <ioavr.h>
#include <inavr.h>
#include <stdint.h>
#include "ccadc.h"
#include "main.h"

Go to the source code of this file.
Defines | |
| #define | ICC_TEST |
| #define | REGULAR_CURRENT_LEVEL 10 |
| #define | SLEEP_MODE_ADC 1 |
| #define | SLEEP_MODE_IDLE 0 |
| #define | SLEEP_MODE_POWER_OFF 3 |
| #define | SLEEP_MODE_POWER_SAVE 2 |
Functions | |
| void | CCADC_select_sleep_mode (uint8_t sleep_mode) |
| CCADC_select_sleep_mode(). | |
| void | main (void) |
| Main loop. | |
| #define SLEEP_MODE_ADC 1 |
| #define SLEEP_MODE_IDLE 0 |
| #define SLEEP_MODE_POWER_OFF 3 |
| #define SLEEP_MODE_POWER_SAVE 2 |
| void CCADC_select_sleep_mode | ( | uint8_t | sleep_mode | ) |
This function programs the sleep mode and enables it. The microcontroller will enter in this sleep mode after a call of the __sleep() function.
| sleep_mode | (SLEEP_MODE_IDLE, SLEEP_MODE_ADC, SLEEP_MODE_POWER_SAVE or SLEEP_MODE_POWER_OFF) |
Definition at line 77 of file main.c.
References SLEEP_MODE_ADC, SLEEP_MODE_IDLE, SLEEP_MODE_POWER_OFF, and SLEEP_MODE_POWER_SAVE.
Referenced by main().
00078 { 00079 switch(sleep_mode){ 00080 case SLEEP_MODE_IDLE: 00081 00082 // Select SLEEP mode (idle mode SM[2:0] = 000) 00083 SMCR &= ~((1<<SM2)|(1<<SM1)|(1<<SM0)); 00084 00085 //Enable SLEEP mode (set SE to enable) 00086 SMCR |= (1<<SE); 00087 break; 00088 00089 case SLEEP_MODE_ADC: 00090 //select SLEEP mode (idle mode SM[2:0] = 001) 00091 SMCR &= ~((1<<SM2)|(1<<SM1)); 00092 SMCR |= (1<<SM0); 00093 00094 //enable SLEEP mode (set SE to enable) 00095 SMCR |= (1<<SE); 00096 break; 00097 00098 case SLEEP_MODE_POWER_SAVE: 00099 //select SLEEP mode (idle mode SM[2:0] = 011) 00100 SMCR &= ~(1<<SM2); 00101 SMCR |= ((1<<SM0)|(1<<SM0)); 00102 00103 //enable SLEEP mode (set SE to enable) 00104 SMCR |= (1<<SE); 00105 break; 00106 00107 case SLEEP_MODE_POWER_OFF: 00108 //select SLEEP mode (idle mode SM[2:0] = 100) 00109 SMCR &= ~((1<<SM1)|(1<<SM0)); 00110 SMCR |= (1<<SM2); 00111 00112 //enable SLEEP mode (set SE to enable) 00113 SMCR |= (1<<SE); 00114 break; 00115 00116 default: 00117 //disable SLEEP mode (reset SE to disable) 00118 SMCR &= ~(1<<SE); 00119 break; 00120 } 00121 }
| void main | ( | void | ) |
Main loop.
The code provided in the main() function is intended as example of how to use the CC-ADC and call the driver functions provided in the AVR352 driver files (ccadc.c and ccadc.h).
The example is not a complete application intended for use with smart batteries, and it would most likely be desirable to do use the CC-ADC somewhat different in a smart battery application. It is e.g. expected that interrupts would be used instead of polling the interrupt flags in a real application. However, in this example the polling makes the code flow more obvious.
Definition at line 137 of file main.c.
References ACCT_1024, CCADC_ACC, CCADC_GetAccResult(), CCADC_GetIccResult(), CCADC_ICC, CCADC_Init(), CCADC_RCC, CCADC_select_sleep_mode(), CCADC_SetMode(), RCCI_2048, REGULAR_CURRENT_LEVEL, and SLEEP_MODE_IDLE.
00138 { 00140 int16_t lastCurrentReading; 00141 00144 CCADC_Init( ACCT_1024, RCCI_2048, REGULAR_CURRENT_LEVEL ); 00145 00146 #ifdef ICC_TEST 00147 CCADC_SetMode( CCADC_ICC ); 00148 #endif 00149 00150 #ifdef ACC_TEST 00151 CCADC_SetMode( CCADC_ACC ); 00152 #endif 00153 00154 #ifdef RCC_TEST 00155 CCADC_SetMode( CCADC_RCC ); 00156 #endif 00157 00158 __enable_interrupt(); 00159 00160 CCADC_select_sleep_mode(SLEEP_MODE_IDLE); 00161 00162 while(1) 00163 { 00164 #ifdef ICC_TEST 00165 lastCurrentReading = CCADC_GetIccResult(); 00166 #endif 00167 00168 #ifdef ACC_TEST 00169 lastCurrentReading = CCADC_GetAccResult(); 00170 #endif 00171 00172 if (lastCurrentReading > REGULAR_CURRENT_LEVEL) 00173 { 00174 #ifndef RCC_TEST 00175 __sleep(); 00176 #endif 00177 } 00178 } 00179 }

1.5.6