analog.c File Reference


Detailed Description

Sampling and calculations.

Application note:
AVR453: Smart Battery Reference Design
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
Original author: Rob G. Fries - Apt Inc.
Revision
URL
Date

Definition in file analog.c.

#include <iom406.h>
#include <inavr.h>
#include "main.h"
#include "pack.h"
#include "analog.h"
#include "calibration.h"
#include "smbus.h"
#include "timer.h"
#include "pwrmgmt.h"
#include "ee.h"

Go to the source code of this file.

Defines

#define ADC0_HI_CAL   (sig_array[0x19])
#define ADC0_LO_CAL   (sig_array[0x18])
#define BG_C_CAL   (sig_array[0x09])
#define CCI_CAL   172
#define CELL1_HI_CAL   (sig_array[0x11])
#define CELL1_LO_CAL   (sig_array[0x10])
#define CELL2_HI_CAL   (sig_array[0x13])
#define CELL2_LO_CAL   (sig_array[0x12])
#define CELL3_HI_CAL   (sig_array[0x15])
#define CELL3_LO_CAL   (sig_array[0x14])
#define CELL4_HI_CAL   (sig_array[0x17])
#define CELL4_LO_CAL   (sig_array[0x16])
#define FAST_RC_CAL   (sig_array[0x01])
#define FixedThermistorPullup   1000
#define MODULE_ANALOG
#define MODULE_CALIBRATION
#define SLOW_RC_HI_CAL   (sig_array[0x07])
#define SLOW_RC_LO_CAL   (sig_array[0x06])
#define VPTAT_HI_CAL   (sig_array[0x1B])
#define VPTAT_LO_CAL   (sig_array[0x1A])

Functions

unsigned int AbsoluteSOC (void)
__interrupt void ADC_INT (void)
void ADCinit (void)
unsigned int AtRateOK (void)
unsigned int AtRateTTE (void)
unsigned int AtRateTTF (void)
unsigned int AvgTimeToFull (void)
void CalculateADCresults (void)
unsigned char CalibrateCCoffset (void)
unsigned char CalibrateVREF (void)
__interrupt void CC_Accumulator_ISR (void)
__interrupt void CC_Instantaneous_ISR (void)
__interrupt void CC_RegularCurrent_ISR (void)
void CCarray_AddSample (signed int newsample)
signed int CCarray_Average (void)
void CCarray_Init (void)
void CCinit (void)
void CCmode (unsigned char mode)
signed int Current1Sec (void)
void DisableCellBalancing (void)
void EnableCellBalancing (void)
void FullChargeReached (void)
unsigned int FullChgCap (void)
void FullDischargeReached (void)
long GetCharge (void)
long GetCharge_mAmins (void)
long GetChgUntilFull_mAmins (void)
unsigned int GetMaxChg (void)
unsigned int GetTemperature (void)
unsigned int GetVoltage (void)
unsigned char ReadCCOffsetCalibration (void)
unsigned int ReadCell (char cell)
void ReadFactoryCalibration (void)
unsigned int ReadTemperature (unsigned char channel)
unsigned char ReadVrefCalibration (void)
unsigned char RelativeSOC (void)
unsigned int RemainingCap (void)
void SetMaxTopAcc (long value)
void StartAdc (unsigned char select)
unsigned int TimeToEmpty (unsigned char avgd)

Variables

unsigned int ADCbuffer [10]
unsigned char ADCchannel
unsigned int ADCgain [4]
unsigned char CC_delay_acc = 0
unsigned char CC_delay_inst = 0
signed int CCarray [64]
char CCindex = 0
char CCvalidsamples = 0
unsigned int CellV [4] = {0}
signed long MaxBottomAcc = 0
signed long MaxTopAcc = 0
unsigned int OnChipTemp = 0
unsigned int Thermistor [4] = {0}
unsigned int VPA4 = 0
unsigned int VTgain


Define Documentation

#define ADC0_HI_CAL   (sig_array[0x19])

Definition at line 469 of file analog.c.

#define ADC0_LO_CAL   (sig_array[0x18])

Definition at line 468 of file analog.c.

#define BG_C_CAL   (sig_array[0x09])

Definition at line 459 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CCI_CAL   172

Definition at line 906 of file analog.c.

Referenced by CC_Instantaneous_ISR().

#define CELL1_HI_CAL   (sig_array[0x11])

Definition at line 461 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL1_LO_CAL   (sig_array[0x10])

Definition at line 460 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL2_HI_CAL   (sig_array[0x13])

Definition at line 463 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL2_LO_CAL   (sig_array[0x12])

Definition at line 462 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL3_HI_CAL   (sig_array[0x15])

Definition at line 465 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL3_LO_CAL   (sig_array[0x14])

Definition at line 464 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL4_HI_CAL   (sig_array[0x17])

Definition at line 467 of file analog.c.

Referenced by ReadFactoryCalibration().

#define CELL4_LO_CAL   (sig_array[0x16])

Definition at line 466 of file analog.c.

Referenced by ReadFactoryCalibration().

#define FAST_RC_CAL   (sig_array[0x01])

Todo:
NOTE: the signature/fab.calibration bytes definitions assume Rev *E* silicon ONLY. Earlier revisions will require changes.

Definition at line 456 of file analog.c.

Referenced by ReadFactoryCalibration().

#define FixedThermistorPullup   1000

Definition at line 117 of file analog.c.

#define MODULE_ANALOG

Definition at line 62 of file analog.c.

#define MODULE_CALIBRATION

Definition at line 65 of file analog.c.

#define SLOW_RC_HI_CAL   (sig_array[0x07])

Definition at line 458 of file analog.c.

Referenced by ReadFactoryCalibration().

#define SLOW_RC_LO_CAL   (sig_array[0x06])

Definition at line 457 of file analog.c.

Referenced by ReadFactoryCalibration().

#define VPTAT_HI_CAL   (sig_array[0x1B])

Definition at line 471 of file analog.c.

Referenced by ReadFactoryCalibration().

#define VPTAT_LO_CAL   (sig_array[0x1A])

Definition at line 470 of file analog.c.

Referenced by ReadFactoryCalibration().


Function Documentation

unsigned int AbsoluteSOC ( void   ) 

Definition at line 333 of file analog.c.

Referenced by SMBR_AbsSOC().

__interrupt void ADC_INT ( void   ) 

Definition at line 1126 of file analog.c.

References ADC0_READINGS, ADCbuffer, cell_current, DisableCellBalancing(), EnableCellBalancing(), LatestCCI, SetADCScanDone, and VPTAT_READINGS.

void ADCinit ( void   ) 

Definition at line 1088 of file analog.c.

Referenced by InitAll().

unsigned int AtRateOK ( void   ) 

Definition at line 280 of file analog.c.

Referenced by SMBR_AtRateOK().

unsigned int AtRateTTE ( void   ) 

Definition at line 252 of file analog.c.

Referenced by SMBR_AtRateTTE().

unsigned int AtRateTTF ( void   ) 

Definition at line 226 of file analog.c.

Referenced by SMBR_AtRateTTF().

unsigned int AvgTimeToFull ( void   ) 

Definition at line 410 of file analog.c.

Referenced by SMBR_AvgTTF().

void CalculateADCresults ( void   ) 

Todo:
Code could be added HERE to do something with the cell_current[] array, for the purpose of determining cell impedances.

Definition at line 1176 of file analog.c.

Referenced by main().

unsigned char CalibrateCCoffset ( void   ) 

Definition at line 679 of file analog.c.

Referenced by DoCalibrate().

unsigned char CalibrateVREF ( void   ) 

Definition at line 603 of file analog.c.

Referenced by DoCalibrate().

__interrupt void CC_Accumulator_ISR ( void   ) 

Todo:
If using IAR3.20, the following lines need to be enabled and the one below disabled.

Definition at line 1019 of file analog.c.

References CC_delay_acc, and RunningAcc.

__interrupt void CC_Instantaneous_ISR ( void   ) 

Definition at line 909 of file analog.c.

References CCarray_AddSample(), CCI_CAL, LatestCCI, PowerMode, POWERMODE_IDLE, and RunningAcc.

__interrupt void CC_RegularCurrent_ISR ( void   ) 

Definition at line 987 of file analog.c.

References ChangePowerMode(), and POWERMODE_ACTIVE.

void CCarray_AddSample ( signed int  newsample  ) 

Definition at line 809 of file analog.c.

References CC_delay_inst, CCarray, CCindex, and CCvalidsamples.

Referenced by CC_Instantaneous_ISR().

signed int CCarray_Average ( void   ) 

Definition at line 841 of file analog.c.

Referenced by SMBR_AvgCurrent(), and TimeToEmpty().

void CCarray_Init ( void   ) 

Definition at line 801 of file analog.c.

References CCindex, and CCvalidsamples.

Referenced by CCmode().

void CCinit ( void   ) 

Definition at line 785 of file analog.c.

Referenced by InitAll().

void CCmode ( unsigned char  mode  ) 

Todo:
See ANALOG.H to choose your interval for CC_ACCUMULATE

Todo:
See ANALOG.H to choose your interval for CC_REGULAR

Definition at line 742 of file analog.c.

Referenced by CCinit(), SetActiveMode(), SetIdleMode(), and SetPowerSaveMode().

signed int Current1Sec ( void   ) 

Todo:
NOTE: This could produce a bad result within the first 1Sec of operation.

Definition at line 826 of file analog.c.

Referenced by AtRateOK(), AvgTimeToFull(), ChargeCheck(), SMBR_Current(), and TimeToEmpty().

void DisableCellBalancing ( void   ) 

Definition at line 1261 of file analog.c.

Referenced by ADC_INT(), BalanceCheck(), and DoCalibrate().

void EnableCellBalancing ( void   ) 

Definition at line 1267 of file analog.c.

Referenced by ADC_INT(), BalanceCheck(), and DoCalibrate().

void FullChargeReached ( void   ) 

Definition at line 131 of file analog.c.

Referenced by ChargeCheck().

unsigned int FullChgCap ( void   ) 

Todo:
This implementation does not take into account C/5 vs 1C capacity delta.

Definition at line 357 of file analog.c.

Referenced by SMBR_FullChgCap().

void FullDischargeReached ( void   ) 

Definition at line 144 of file analog.c.

Referenced by ChargeCheck().

long GetCharge ( void   ) 

Definition at line 174 of file analog.c.

References RunningAcc.

Referenced by AbsoluteSOC(), and RemainingCap().

long GetCharge_mAmins ( void   ) 

Definition at line 181 of file analog.c.

References RunningAcc.

Referenced by AtRateOK(), AtRateTTE(), AtRateTTF(), and TimeToEmpty().

long GetChgUntilFull_mAmins ( void   ) 

Definition at line 188 of file analog.c.

References MaxTopAcc, and RunningAcc.

Referenced by AvgTimeToFull().

unsigned int GetMaxChg ( void   ) 

Definition at line 195 of file analog.c.

References MaxTopAcc.

Referenced by FullChgCap().

unsigned int GetTemperature ( void   ) 

Definition at line 318 of file analog.c.

Referenced by SMBR_Temperature(), and ThermalCheck().

unsigned int GetVoltage ( void   ) 

Definition at line 160 of file analog.c.

Referenced by AtRateOK(), AvgTimeToFull(), RemainingCap(), SMBR_Voltage(), and TimeToEmpty().

unsigned char ReadCCOffsetCalibration ( void   ) 

Definition at line 566 of file analog.c.

Referenced by DoCalibrate(), and ReadFactoryCalibration().

unsigned int ReadCell ( char  cell  ) 

Definition at line 1252 of file analog.c.

Referenced by BalanceCheck(), ChargeCheck(), and GetVoltage().

void ReadFactoryCalibration ( void   ) 

Definition at line 488 of file analog.c.

References ADCgain, BG_C_CAL, BGCCRCal, CAL_CC_MASK, CAL_CC_OK, CAL_VREF_MASK, CAL_VREF_OK, calibration_state, CELL1_HI_CAL, CELL1_LO_CAL, CELL2_HI_CAL, CELL2_LO_CAL, CELL3_HI_CAL, CELL3_LO_CAL, CELL4_HI_CAL, CELL4_LO_CAL, FAST_RC_CAL, FastRCCal, ReadCCOffsetCalibration(), ReadVrefCalibration(), SLOW_RC_HI_CAL, SLOW_RC_LO_CAL, SlowRCCal, VPTAT_HI_CAL, VPTAT_LO_CAL, and VTgain.

Referenced by ADCinit().

unsigned int ReadTemperature ( unsigned char  channel  ) 

Todo:
Insert calculations here to convert voltage reading(s) to temperature(s).

Definition at line 1229 of file analog.c.

Referenced by GetTemperature().

unsigned char ReadVrefCalibration ( void   ) 

Definition at line 543 of file analog.c.

Referenced by DoCalibrate(), and ReadFactoryCalibration().

unsigned char RelativeSOC ( void   ) 

Definition at line 325 of file analog.c.

Referenced by ChargeCheck(), and SMBR_RelSOC().

unsigned int RemainingCap ( void   ) 

Todo:
This implementation does not take into account C/5 vs 1C capacity delta.

Definition at line 341 of file analog.c.

Referenced by AlarmConditionsCheck(), and SMBR_RemCap().

void SetMaxTopAcc ( long  value  ) 

Definition at line 126 of file analog.c.

Referenced by InitSMBvariables().

void StartAdc ( unsigned char  select  ) 

Todo:
NOTE: If not using ADC0-3 exclusively as analog inputs, you MUST modify the following code.

Definition at line 1103 of file analog.c.

Referenced by main().

unsigned int TimeToEmpty ( unsigned char  avgd  ) 

Definition at line 372 of file analog.c.

Referenced by AlarmConditionsCheck(), SMBR_AvgTTE(), and SMBR_RunTTE().


Variable Documentation

unsigned int ADCbuffer[10]

Definition at line 111 of file analog.c.

Referenced by ADC_INT(), and CalculateADCresults().

unsigned char ADCchannel

Definition at line 114 of file analog.c.

unsigned int ADCgain[4]

Definition at line 112 of file analog.c.

Referenced by CalculateADCresults(), and ReadFactoryCalibration().

unsigned char CC_delay_acc = 0

Definition at line 87 of file analog.c.

Referenced by CalibrateCCoffset(), CC_Accumulator_ISR(), and CCmode().

unsigned char CC_delay_inst = 0

Definition at line 88 of file analog.c.

Referenced by CCarray_AddSample(), and CCmode().

signed int CCarray[64]

Definition at line 103 of file analog.c.

Referenced by CalibrateCCoffset(), CCarray_AddSample(), CCarray_Average(), and Current1Sec().

char CCindex = 0

Definition at line 104 of file analog.c.

Referenced by CalibrateCCoffset(), CCarray_AddSample(), CCarray_Init(), and Current1Sec().

char CCvalidsamples = 0

Definition at line 105 of file analog.c.

Referenced by CCarray_AddSample(), CCarray_Average(), and CCarray_Init().

unsigned int CellV[4] = {0}

Definition at line 91 of file analog.c.

Referenced by CalculateADCresults(), and ReadCell().

signed long MaxBottomAcc = 0

Definition at line 85 of file analog.c.

Referenced by FullChargeReached(), and FullDischargeReached().

signed long MaxTopAcc = 0

Definition at line 84 of file analog.c.

Referenced by FullChargeReached(), FullDischargeReached(), GetChgUntilFull_mAmins(), GetMaxChg(), RelativeSOC(), and SetMaxTopAcc().

unsigned int OnChipTemp = 0

Definition at line 92 of file analog.c.

Referenced by CalculateADCresults(), and ReadTemperature().

unsigned int Thermistor[4] = {0}

Definition at line 95 of file analog.c.

Referenced by CalculateADCresults(), and ReadTemperature().

unsigned int VPA4 = 0

Definition at line 96 of file analog.c.

Referenced by CalculateADCresults().

unsigned int VTgain

Definition at line 113 of file analog.c.

Referenced by CalculateADCresults(), and ReadFactoryCalibration().


Generated on Mon Nov 12 15:59:58 2007 for AVR453 Smart Battery Reference Design by  doxygen 1.5.3