00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef _FEB64_H
00013 #define _FEB64_H
00014
00015
00016
00017 #define ADT7486A_ADDR0 0x49
00018 #define ADT7486A_ADDR1 0x48
00019 #define ADT7486A_ADDR2 0x4B
00020 #define ADT7486A_ADDR3 0x4A
00021 #define ADT7486A_ADDR4 0x48
00022 #define SST_LINE1 1
00023 #define SST_LINE2 2
00024
00025
00026 #define SST_TIME 2 //In us
00027
00028
00029
00030 #define BIAS_OUTPUT_ENABLE ADDR_PCA9539, PCA9539_CONFIG0, PCA9539_ALL_OUTPUT
00031 #define BIAS_DISABLE ADDR_PCA9539, PCA9539_OUTPUT0, 0xFF
00032 #define BIAS_ENABLE ADDR_PCA9539, PCA9539_OUTPUT0, 0x00
00033 #define BIAS_READ ADDR_PCA9539, PCA9539_INPUT0
00034 #define BIAS_WRITE ADDR_PCA9539, PCA9539_OUTPUT0
00035
00036 #define BACKPLANE_INPUT_ENABLE ADDR_PCA9539, PCA9539_CONFIG1, PCA9539_ALL_INPUT
00037 #define BACKPLANE_READ ADDR_PCA9539, PCA9539_INPUT1
00038
00039
00040
00041 #define N_RB_CHANNEL 16
00042 #define EXT_VREF 1.25f // 2.4989f actually 1/2 of the number here
00043 #define CURR_MEASURE 0x04
00044 #define V_A2MTABLE 0
00045 #define I_A2MTABLE 1
00046 #define VOLT_MEASURE 0x04
00047 #define GAIN1 0 // actually x1
00048 #define GAIN4 1 // actually x4
00049 #define GAIN8 2 // actually x8
00050 #define GAIN16 3 // actually x16
00051 #define GAIN32 4 // actually x32
00052 #define GAIN64 5 // actually x64
00053
00054 #define CONVER_FAC2 65536.0f
00055
00056
00057
00058 struct ADC2MSCB_TABLE {
00059 int gain;
00060 int mscbIdx;
00061 int current;
00062 float Coef;
00063 signed int Offst;
00064 };
00065
00066 struct ADC2MSCB_TABLE xdata adc2mscb_table[16] = {
00067 {GAIN32, 1, I_A2MTABLE, 1000, 22}, {GAIN32, 3, I_A2MTABLE, 1000, 127}
00068 , {GAIN32, 5, I_A2MTABLE, 1000, 7176}, {GAIN32, 7, I_A2MTABLE, 1000, 1840}
00069 , {GAIN1 , 7, V_A2MTABLE, 101.1, 230}, {GAIN1 , 5, V_A2MTABLE, 101.1, 230}
00070 , {GAIN1 , 3, V_A2MTABLE, 101.1, 230}, {GAIN1 , 1, V_A2MTABLE, 101.1, 230}
00071 , {GAIN32, 0, I_A2MTABLE, 1000, 3178}, {GAIN32, 2, I_A2MTABLE, 1000, 1800}
00072 , {GAIN32, 4, I_A2MTABLE, 1000, 925}, {GAIN32, 6, I_A2MTABLE, 1000, 4895}
00073 , {GAIN1 , 6, V_A2MTABLE, 101.1, 24}, {GAIN1 , 4, V_A2MTABLE, 101.1, 230}
00074 , {GAIN1 , 2, V_A2MTABLE, 101.1, 225}, {GAIN1 , 0, V_A2MTABLE, 101.1, 230}
00075 };
00076 #define CONVER_FAC1 0xFFFFFFFF // Force large number in case of OR or UR
00077
00078
00079
00080 #define Q_PUMP_INIT 1
00081 #define Q_PUMP_OFF 2
00082 #define Q_PUMP_ON 3
00083
00084
00085
00086 #define INT_VREF 2.44f // Internal uC Vref
00087 #define IntGAIN1 0
00088 #define IntGAIN2 1
00089 #define IntGAIN4 2
00090 #define IntGAIN8 3
00091 #define IntGAIN16 4
00092
00093 struct IADC_TABLE {
00094 char gain;
00095 float coeff;
00096 float offset;
00097 };
00098
00099
00100
00101 struct IADC_TABLE xdata iadc_table[8] = {
00102 {IntGAIN2, 50.5, 0.0}, {IntGAIN8, 10000.0/8.0, 0.0}
00103 , {IntGAIN1, 3.980132, 0}, {IntGAIN1, 3.980132, 0}
00104 , {IntGAIN1, 8.5, -18.751}, {IntGAIN1, 0.1, 0}
00105 , {IntGAIN1, 0.4, 0}, {IntGAIN1, 0.1, 0}
00106 };
00107
00108
00109
00110
00111
00112
00113
00114
00115 unsigned char rEER;
00116
00117 #define EEP_CTRL_KEY 0x3C000000
00118 #define EEP_CTRL_READ 0x00110000
00119 #define EEP_CTRL_WRITE 0x00220000
00120 #define EEP_CTRL_INVAL_REQ 0xff000000
00121 #define EEP_CTRL_INVAL_KEY 0x00ff0000
00122 #define EEP_CTRL_OFF_RANGE 0x0000ff00
00123 #define PAGE_SIZE sizeof(eepage) // 300 for now
00124 #define EEP_RW_IDX 0x06 // (I*4) but use 0x17 for normal operation
00125 #define EEP_RW_LAST_IDX PAGE_SIZE/4
00126
00127
00128 struct EEPAGE {
00129 unsigned long SerialN;
00130 unsigned int structsze;
00131 unsigned int rasum[8];
00132 unsigned int rqpump;
00133 unsigned int SWbias;
00134 unsigned int calQpump;
00135 unsigned char rbias [64];
00136
00137 float lVIlimit[8];
00138 float uVIlimit[8];
00139 float luCTlimit, uuCTlimit;
00140 float lSSTlimit, uSSTlimit;
00141 float lVQlimit, uVQlimit;
00142 float lIQlimit, uIQlimit;
00143 float lVBiaslimit, uVBiaslimit;
00144 float lIBiaslimit, uIBiaslimit;
00145 float ext1offset[4];
00146 float ext2offset[4];
00147 float iBiasOffset[8];
00148 float vBiasOffset[8];
00149 };
00150
00151
00152 struct EEPAGE xdata eepage = {
00153
00154 0x00000000
00155
00156 , 110
00157
00158 , 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
00159
00160 , 0x0000
00161
00162
00163 , 0x0000
00164
00165 , 800
00166
00167 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00168 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00169 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00170 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00171 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00172 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00173 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00174 , 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
00175
00176
00177 ,30.0, 0.0, 5.5, 5.5, -6.5, 0.0, 0.0, 0.0
00178
00179 ,73.0, 0.1, 6.5, 6.5, -5.5, 0.2, 0.8, 0.2
00180
00181 ,10., 50.
00182
00183 ,10. ,30.
00184
00185 ,-1.0 ,1.0
00186
00187 ,-0.1 ,1.0
00188
00189 ,0.0 ,73.0
00190
00191 ,0.0 ,10.0
00192
00193 ,0.0, 0.0, 0.0, 0.0
00194
00195 ,0.0, 0.0, 0.0, 0.0
00196
00197 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
00198
00199 , 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
00200 };
00201
00202
00203 struct EEPAGE xdata eepage2;
00204
00205
00206
00207 #define NCHANNEL_BIAS 64
00208 #define NCHANNEL_ASUM 8
00209 #define NCHANNEL_SST 8
00210 #define NCHANNEL_ADT7486A 4
00211
00212
00213 #define IDXEER 1
00214 #define IDXCTL 2
00215 #define IDXQVOLT 6
00216 #define IDXBSWITCH 5
00217 #define IDXASUM 47
00218 #define IDXSST 19
00219 #define IDXBIAS 55
00220 #define IDXEEP_CTL 144
00221 #define IDXASUM_CTL 145
00222
00223 #define SERIALN_LENGTH (unsigned int) 4
00224 #define SERIALN_ADD (unsigned int) (0x600) // Fixed as sitting at the first byte of the EEPROM
00225
00226
00227 unsigned int xdata PageAddr[]={0x000, 0x200, 0x400, 0x600};
00228
00229 #define FIRST_BIAS IDXBIAS
00230 #define LAST_BIAS FIRST_BIAS + NCHANNEL_BIAS
00231
00232 #define FIRST_ASUM IDXASUM
00233 #define LAST_ASUM FIRST_ASUM + NCHANNEL_ASUM
00234
00235
00236 #define ADDR_LTC1669 0x20
00237 #define ADDR_PCA9539 0x74
00238 #define ADDR_LTC2497 0x14
00239 #define ADDR_LTC2495 0x14
00240
00241
00242 unsigned char xdata ltc1665mirror [64];
00243 unsigned int xdata ltc2600mirror [8];
00244
00245
00246 #define ON 1
00247 #define DONE 1
00248 #define OFF 0
00249 #define FAILED 0
00250 #define CLEAR 0
00251
00252
00253 unsigned char bdata rCTL;
00254 sbit CPup = rCTL ^ 0;
00255
00256 sbit CAsum = rCTL ^ 2;
00257 sbit Ccal = rCTL ^ 3;
00258 sbit CeeS = rCTL ^ 4;
00259 sbit CeeR = rCTL ^ 5;
00260 sbit CeeClr = rCTL ^ 6;
00261 sbit CmSd = rCTL ^ 7;
00262
00263
00264
00265 unsigned char bdata rCSR;
00266 sbit SPup = rCSR ^ 0;
00267 sbit SqPump = rCSR ^ 1;
00268 sbit SAsum = rCSR ^ 2;
00269 sbit Scal = rCSR ^ 3;
00270 sbit SeeS = rCSR ^ 4;
00271 sbit SeeR = rCSR ^ 5;
00272 sbit SsS = rCSR ^ 6;
00273 sbit SmSd = rCSR ^ 7;
00274
00275
00276
00277
00278
00279
00280 unsigned int bdata rESR;
00281 sbit vQpump = rESR ^ 8;
00282 sbit iQpump = rESR ^ 9;
00283 sbit vReg1 = rESR ^ 10;
00284 sbit vReg2 = rESR ^ 11;
00285
00286 sbit vReg3 = rESR ^ 12;
00287 sbit iReg1 = rESR ^ 13;
00288 sbit iReg2 = rESR ^ 14;
00289 sbit iReg3 = rESR ^ 15;
00290
00291 sbit uCT = rESR ^ 0;
00292 sbit IntssTT = rESR ^ 1;
00293 sbit ExtssTT = rESR ^ 2;
00294 sbit EEPROM = rESR ^ 3;
00295
00296 sbit pcbssTT = rESR ^ 4;
00297 sbit RdssT = rESR ^ 5;
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 #define UCTEMPERATURE_MASK 0x0100
00308 #define BTEMPERATURE_MASK 0x1000 // ADC Temp internal SST_LINE2
00309 #define FGDTEMPERATURE_MASK 0x0400
00310 #define VOLTAGE_MASK 0x001C
00311 #define CURRENT_MASK 0x0040
00312
00313
00314
00315
00316
00317
00318
00319
00320 struct user_data_type {
00321 unsigned long SerialN;
00322 unsigned int error;
00323 unsigned char control;
00324 unsigned char status;
00325 unsigned char eepage;
00326 unsigned char swBias;
00327 unsigned int rQpump;
00328 unsigned int spare;
00329 float VBias;
00330 float IBias;
00331 float pDVMon;
00332 float pAVMon;
00333 float nAVMon;
00334 float nAIMon;
00335 float pAIMon;
00336 float pDIMon;
00337 float uCTemp;
00338 float adcTemp;
00339 float afterTemp;
00340 float regTemp;
00341 float Temp[8];
00342 float VBMon[8];
00343 float IBMon[8];
00344 float ssTemp[4];
00345 unsigned int rAsum[8];
00346 unsigned char rBias [64];
00347
00348 unsigned int rVBias;
00349 unsigned int rIBias;
00350 unsigned int rpDV;
00351 unsigned int rpAV;
00352 unsigned int rnAV;
00353 unsigned int rnAI;
00354 unsigned int rpAI;
00355 unsigned int rpDI;
00356 signed long rVBMon[8];
00357 signed long rIBMon[8];
00358
00359 float eepValue;
00360 unsigned long eeCtrSet;
00361 unsigned long asumCtl;
00362 unsigned long watchdog;
00363 unsigned long debugsmb;
00364
00365 unsigned int geoadd;
00366 };
00367 struct user_data_type xdata user_data;
00368
00369
00370 sbit timing = P2 ^ 7;
00371 unsigned long xdata smbdebug;
00372
00373
00374
00375
00376 void user_init(unsigned char init);
00377 void user_loop(void);
00378 void user_write(unsigned char index) reentrant;
00379 unsigned char user_read(unsigned char index);
00380 unsigned char user_func(unsigned char *data_in, unsigned char *data_out);
00381 float read_voltage(unsigned char channel,unsigned int *rvalue, float coeff, float offset, unsigned char gain);
00382 void switchonoff(unsigned char command);
00383 int eepageAddrConvert(unsigned int index);
00384 #endif