calibration.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00024 // Prototypes
00025 unsigned char CalibrateVREF(void);       // calibration routine for VREF
00026 unsigned char CalibrateCCoffset(void);   // calibration routine for CC offset
00027 
00028 
00029 #ifdef MODULE_CALIBRATION
00030 unsigned int calibration_state = 0;
00031 unsigned int calibration_state_req = 0;
00032 #define CCoffset_limit  100            // limit for CCoffset (to be decided)
00033 #define CCIoffset_limit 66             // limit for CCIoffset 10.5*(CCoffset/16)
00034 
00035 // This section is for calibration on CELL1 with 4096mV
00036 #define CAL_CHANNEL             0x01            // Mux value for channel PV1
00037 #define CAL_GAIN            ADCgain[0]  // Gain value for channel PV1
00038 #define CAL_WAIT            10          // Number of VADC cycles (512us) to wait for error from
00039                                                                         // CellBalancing to cancel.
00040 
00041 // Defines for the different temperature dependency calibration settings (thermometer coded)
00042 #define TempCal0                        0x00
00043 #define TempCal1                        0x01
00044 #define TempCal2                        0x03
00045 #define TempCal3                        0x07
00046 #define TempCal4                        0x0F
00047 #define TempCal5                        0x1F
00048 #define TempCal6                        0x3F
00049 #define TempCal7                        0x7F
00050 #define TempCal8                        0xFF
00051 
00053 #define Vcalibration_value      67117056    // input voltage = 4096.5mV*16384/mV = 67117056
00054 //#define Vcalibration_value    67094442        // debug input voltage = 4096.5mV*60BC/mV*1.10055/1.100
00055 #define VLevel0             0                           // padding to enable Tempcal0 if < VLevel1
00056 #define VLevel1                         -615753                 // Preliminary
00057 #define VLevel2                         -491700
00058 #define VLevel3                         -337272
00059 #define VLevel4                         -152886
00060 #define VLevel5                         0
00061 #define VLevel6                         60960
00062 #define VLevel7                         121810
00063 #define VLevel8                         182549
00064 
00065 // This section is for calibration on ADC0 with 0.55V, should be revised when algorithm is decided
00066 /*
00067 #define CAL_CHANNEL             0x07            // Mux value for channel ADC0
00068 #define CAL_GAIN            1           // Added to give compatibility with scaled inputs probably optimized away
00069                                                                                 // by compiler. Routine could be optimized if unscaled input is used.
00070 #define CAL_WAIT            1           // Number of VADC cycles (512us) to wait for error from CellBalancing
00071                                                                         // to cancel. We always Waits 1 cycle for dummy read.
00072 
00073 // Defines for the different temperature dependency calibration settings (thermometer coded)
00074 #define TempCal0                        0x00
00075 #define TempCal1                        0x01
00076 #define TempCal2                        0x03
00077 #define TempCal3                        0x07
00078 #define TempCal4                        0x0F
00079 #define TempCal5                        0x1F
00080 #define TempCal6                        0x3F
00081 #define TempCal7                        0x7F
00082 #define TempCal8                        0xFF
00083 
00084 #define Vcalibration_value      2048                            // Used with input voltage = 0.55V (half range)
00085 #define VLevel1                         -18                     // Used for demonstration, values are TBD
00086 #define VLevel2                         -15
00087 #define VLevel3                         -10
00088 #define VLevel4                         -5
00089 #define VLevel5                         0
00090 #define VLevel6                         2
00091 #define VLevel7                         4
00092 #define VLevel8                         6
00093 */
00094 
00095 __flash unsigned char tempcal[] = {TempCal0,TempCal1,TempCal2,TempCal3,TempCal4,TempCal5,TempCal6,TempCal7,TempCal8};
00096 __flash signed long int vcalibration_level[] = {VLevel0,VLevel1,VLevel2,VLevel3,VLevel4,VLevel5,VLevel6,VLevel7,VLevel8};
00097 
00098 #else
00099   extern unsigned int calibration_state;
00100   extern unsigned int calibration_state_req;
00101 #endif
00102 
00103 
00104 // Defines for calibration variables.
00105 
00106 #define CAL_VREF_BIT_POS 0
00107 #define CAL_CC_BIT_POS   2
00108 
00109 #define NO_CAL     0
00110 #define RUN_CAL    1
00111 #define CAL_FAIL   2
00112 #define CAL_OK     3
00113 
00114 #define CAL_VREF_MASK  (3        << CAL_VREF_BIT_POS)
00115 #define CAL_VREF_RUN   (RUN_CAL  << CAL_VREF_BIT_POS)
00116 #define CAL_VREF_FAIL  (CAL_FAIL << CAL_VREF_BIT_POS)
00117 #define CAL_VREF_OK    (CAL_OK   << CAL_VREF_BIT_POS)
00118 
00119 #define CAL_CC_MASK    (3        << CAL_CC_BIT_POS)
00120 #define CAL_CC_RUN     (RUN_CAL  << CAL_CC_BIT_POS)
00121 #define CAL_CC_FAIL    (CAL_FAIL << CAL_CC_BIT_POS)
00122 #define CAL_CC_OK      (CAL_OK   << CAL_CC_BIT_POS)

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