00001 /* This file has been prepared for Doxygen automatic documentation generation.*/ 00025 //Prototypes 00026 00027 void SetMaxTopAcc(long value); 00028 00029 void CalculateADCresults(void); 00030 00031 void CCinit(void); //call this at startup 00032 enum CC_MODE {CC_DISABLED = 0, CC_ACCUMULATE, CC_REGULAR}; 00033 void CCmode(unsigned char mode); //call this to switch modes 00034 00035 00036 void ADCinit(void); //call this at startup ASAP to cal the osc's. 00037 void StartAdc(unsigned char select); //starts a scan of all ADC channels. 00038 unsigned int ReadTemperature(unsigned char channel); //1-4 = thermistors 00039 00040 void FullChargeReached(void); //call this when detect ChargingComplete condition 00041 void FullDischargeReached(void); //call this when detect DischargeComplete condition 00042 unsigned int GetVoltage(void); //also serves as "cmd = 9" 00043 unsigned int ReadCell(char); //Returns individual cell V in mV (cell = 1-4) 00044 00045 void DisableCellBalancing(void); 00046 void EnableCellBalancing(void); //if CellToBalance = 0, no balancing req'd. 00047 00048 unsigned char ReadVrefCalibration(void); // read VREF calibration constants from eeprom or use factory defaults 00049 unsigned char ReadCCOffsetCalibration(void); // read C offset constants from eeprom or use 0 00050 00051 00052 // Analog calculations to support specific SMBus Slave Read commands 00053 unsigned int AtRateTTF(void); // cmd = 5 00054 unsigned int AtRateTTE(void); // cmd = 6 00055 unsigned int AtRateOK(void); // cmd = 7 00056 unsigned int GetTemperature(void); // cmd = 8 00057 signed int Current1Sec(void); // cmd = 10 // positive value means Charging, negative means Discharging. 00058 signed int CCarray_Average(void); // cmd = 11 // positive value means Charging, negative means Discharging. 00059 unsigned char RelativeSOC(void); // cmd = 13 00060 unsigned int AbsoluteSOC(void); // cmd = 14 00061 unsigned int RemainingCap(void); // cmd = 15 00062 unsigned int FullChgCap(void); // cmd = 16 00063 unsigned int TimeToEmpty(unsigned char avgd); // cmd = 17,18 00064 unsigned int AvgTimeToFull(void); // cmd = 19 00065 00066 00067 //Variables 00068 00069 #ifdef MODULE_ANALOG 00070 00071 volatile signed int LatestCCI = 0; // most recent value of Instantaneous CC conversion 00072 signed long CCoffset = 0x0000; // this is SUBTRACTED to EACH sample from the CC Accum. 00073 signed int CCIoffset = 0; // this is in mA and is ONLY SUBTRACTED to the 1-second total, NOT TO EACH SAMPLE. 00074 00075 unsigned char FastRCCal = 0; 00076 unsigned int SlowRCCal = 0; 00077 unsigned char BGCCRCal = 0; 00078 unsigned char ThermistorSelect = 0; 00079 unsigned char CellToBalance = 0; 00080 unsigned int cell_current[4]; //used for impedance measurement 00081 signed long RunningAcc = 0; 00082 00083 #else 00084 00085 extern volatile signed int LatestCCI; 00086 extern unsigned char FastRCCal; 00087 extern unsigned int SlowRCCal; 00088 extern unsigned char BGCCRCal; 00089 extern unsigned char ThermistorSelect; 00090 extern unsigned char CellToBalance; 00091 extern unsigned int cell_current[4]; 00092 extern signed long RunningAcc; 00093 00094 #endif 00095 00096 00097 00098 //Defines 00099 00100 #define ACCUM_CONV_TIME_125 ((0<<CADAS1) | (0<<CADAS0)) 00101 #define ACCUM_CONV_TIME_250 ((0<<CADAS1) | (1<<CADAS0)) 00102 #define ACCUM_CONV_TIME_500 ((1<<CADAS1) | (0<<CADAS0)) 00103 #define ACCUM_CONV_TIME_1000 ((1<<CADAS1) | (1<<CADAS0)) 00104 00105 #define ACCUM_CONV_TIME ACCUM_CONV_TIME_1000 00106 00107 00108 #define REG_CONV_TIME_250 ((0<<CADSI1) | (0<<CADSI0)) 00109 #define REG_CONV_TIME_500 ((0<<CADSI1) | (1<<CADSI0)) 00110 #define REG_CONV_TIME_1000 ((1<<CADSI1) | (0<<CADSI0)) 00111 #define REG_CONV_TIME_2000 ((1<<CADSI1) | (1<<CADSI0)) 00112 00113 #define REG_CONV_TIME REG_CONV_TIME_1000 00114 00115 //The following is the amount that the Instantaneous reading must 00116 // be shifted up to correspond to an Accumulator reading. It is 00117 // dependent on the REG_CONV_TIME parameter. The delta if a one-second 00118 // rate is used is a factor of 16. 00119 #define REGULAR_CURRENT_SCALE_VALUE 4 00120 00121 00122 //Since this is detected using the Instantaneous conversion, 00123 // each count is 10.7mA if a 5mOhm sense resistor is used. 00124 // A value of 9 corresponds to just under 100mA. 00125 #define ACTIVE_CURRENT_THRESHOLD 9 00126 00127 00128 //The following is to handle rev.E errata concerning VPTAT reading 00129 #define VPTAT_READINGS 10 // to ensure correct VPTAT readings 00130 #define ADC0_READINGS 10 // to ensure correct readings after VPTAT readings, if the 00131 // ADC0-3 values are not used we could decrease this to 6. 00132 00133 00134
1.5.3