00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <stdio.h>
00012 #include <stdlib.h>
00013 #include <string.h>
00014 #include "mscbemb.h"
00015
00016 #ifdef _ADT7486A_
00017 #include "Devices/ADT7486A_tsensor.h"
00018 #endif
00019
00020 #ifdef _LTC2605_
00021 #include "Devices/LTC2605CGN.h"
00022 #endif
00023
00024 #ifdef _LTC2489_
00025 #include "Devices/LTC2489_adc.h"
00026 #endif
00027
00028 #ifdef _PCA9536_
00029 #include "Devices/PCA9536.h"
00030 #endif
00031
00032
00033
00034
00035
00036
00037
00038
00039 char code node_name[] = "GENERIC310_REV1";
00040 char idata svn_rev_code[] = "$Rev: 57 $";
00041
00042
00043 unsigned char idata _n_sub_addr = 1;
00044 extern SYS_INFO sys_info;
00045
00046
00047 unsigned char xdata ADT7486A_addrArray[] = {0x48, 0x4A};
00048 unsigned char xdata ADDR_LTC2489 [] = {0x24, 0x17};
00049 unsigned char xdata DAQ_ADDRESS = 0x42;
00050 unsigned char xdata PCA9536_ADD = 0x41;
00051
00052 unsigned char xdata FCS_Mismatch;
00053 unsigned char xdata BiasIndex;
00054
00055 #define FIRST_DAQ 18
00056 #define LAST_DAQ FIRST_DAQ + 8
00057 #define N_CHANNEL 4 //Number of ADC Channels
00058 #define VREF 2.4986f
00059 #define CONVER_FAC1 65536.0f
00060 #define CONVER_FAC2 131072.0f
00061 #define CLEAR 0
00062 #define PCA_OUT 0x00
00063 #define PCA_INDEX 1
00064 #define SST_LINE 1
00065
00066 unsigned char bdata bChange;
00067 sbit LTC2605_Flag = bChange ^ 0;
00068 sbit PCA9536_Flag = bChange ^ 1;
00069
00070
00071 unsigned char bdata rErr;
00072 sbit adc = rErr ^ 0;
00073 sbit INTtemp = rErr ^ 1;
00074 sbit EXTtemp = rErr ^ 2;
00075
00076
00077
00078
00079
00080 struct
00081 {
00082 unsigned char error;
00083 unsigned char pca9536;
00084 float volt[8];
00085 signed long adc[8];
00086 unsigned int daq[8];
00087 float intemp[2];
00088 float temp[4];
00089 } xdata user_data;
00090
00091 MSCB_INFO_VAR code vars[] = {
00092 1, UNIT_BYTE, 0, 0, 0, "Error" , &user_data.error,
00093 1, UNIT_BYTE, 0, 0, 0, "MUX" , &user_data.pca9536,
00094 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt0" , &user_data.volt[0],
00095 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt1" , &user_data.volt[1],
00096 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt2" , &user_data.volt[2],
00097 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt3" , &user_data.volt[3],
00098 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt4" , &user_data.volt[4],
00099 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt5" , &user_data.volt[5],
00100 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt6" , &user_data.volt[6],
00101 4, UNIT_VOLT, 0, 0, MSCBF_FLOAT, "Volt7" , &user_data.volt[7],
00102 4, UNIT_BYTE, 0, 0, 0, "ADC0" , &user_data.adc[0],
00103 4, UNIT_BYTE, 0, 0, 0, "ADC1" , &user_data.adc[1],
00104 4, UNIT_BYTE, 0, 0, 0, "ADC2" , &user_data.adc[2],
00105 4, UNIT_BYTE, 0, 0, 0, "ADC3" , &user_data.adc[3],
00106 4, UNIT_BYTE, 0, 0, 0, "ADC4" , &user_data.adc[4],
00107 4, UNIT_BYTE, 0, 0, 0, "ADC5" , &user_data.adc[5],
00108 4, UNIT_BYTE, 0, 0, 0, "ADC6" , &user_data.adc[6],
00109 4, UNIT_BYTE, 0, 0, 0, "ADC7" , &user_data.adc[7],
00110 2, UNIT_BYTE, 0, 0, 0, "DAQ0" , &user_data.daq[0],
00111 2, UNIT_BYTE, 0, 0, 0, "DAQ1" , &user_data.daq[1],
00112 2, UNIT_BYTE, 0, 0, 0, "DAQ2" , &user_data.daq[2],
00113 2, UNIT_BYTE, 0, 0, 0, "DAQ3" , &user_data.daq[3],
00114 2, UNIT_BYTE, 0, 0, 0, "DAQ4" , &user_data.daq[4],
00115 2, UNIT_BYTE, 0, 0, 0, "DAQ5" , &user_data.daq[5],
00116 2, UNIT_BYTE, 0, 0, 0, "DAQ6" , &user_data.daq[6],
00117 2, UNIT_BYTE, 0, 0, 0, "DAQ7" , &user_data.daq[7],
00118 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T0int", &user_data.intemp[0],
00119 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T1int", &user_data.intemp[1],
00120 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T00ext", &user_data.temp[0],
00121 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T01ext", &user_data.temp[1],
00122 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T10ext", &user_data.temp[2],
00123 4, UNIT_CELSIUS, 0, 0, MSCBF_FLOAT, "T11ext", &user_data.temp[3],
00124 0
00125 };
00126
00127 MSCB_INFO_VAR *variables = vars;
00128
00129 char xdata flag = 0;
00130
00131
00132
00133
00134
00135
00136
00137
00138 #define P1_DATA P1
00139 sbit LED_GREEN = LED_1;
00140 sbit LED_RED = LED_0;
00141 sbit SST = MSCB_SST1;
00142
00143 sbit P1_0 = P1 ^ 0;
00144 sbit P1_1 = P1 ^ 1;
00145 sbit P1_2 = P1 ^ 2;
00146 sbit P1_3 = P1 ^ 3;
00147 sbit P1_4 = P1 ^ 4;
00148 sbit P1_5 = P1 ^ 5;
00149 sbit P1_6 = P1 ^ 6;
00150 sbit P1_7 = P1 ^ 7;
00151
00152 sbit P2_0 = P2 ^ 0;
00153 sbit P2_1 = P2 ^ 1;
00154 sbit P2_2 = P2 ^ 2;
00155 sbit P2_3 = P2 ^ 3;
00156 sbit P2_4 = P2 ^ 4;
00157 sbit P2_5 = P2 ^ 5;
00158 sbit P0_1 = P0 ^ 1;
00159 sbit P0_2 = P0 ^ 2;
00160
00161
00162
00163 void user_write(unsigned char index) reentrant;
00164
00165
00166
00167 void user_init(unsigned char init)
00168 {
00169 idata char i;
00170
00171
00172 for (i=0;i<4;i++) {
00173 if (svn_rev_code[6+i] < 48) {
00174 svn_rev_code[6+i] = '0';
00175 }
00176 }
00177
00178 sys_info.svn_revision = (svn_rev_code[6]-'0')*1000+
00179 (svn_rev_code[7]-'0')*100+
00180 (svn_rev_code[8]-'0')*10+
00181 (svn_rev_code[9]-'0');
00182
00183
00184 REF0CN = 0x00;
00185
00186
00187
00188 P0MDIN = 0xFF;
00189 P1MDIN = 0xFF;
00190 P2MDIN = 0x3F;
00191 P3MDIN = 0xFF;
00192
00193
00194
00195 P0MDOUT = 0x10;
00196 P1MDOUT = 0xFF;
00197 P2MDOUT = 0x3F;
00198 P3MDOUT = 0x10;
00199
00200
00201 XBR0 |=0x04;
00202 XBR1 |=0x40;
00203 P0SKIP = 0x0f;
00204
00205
00206 CPT1CN = 0x80;
00207 CPT1MX = 0x33;
00208
00209
00210
00211
00212
00213 CPT1MD = 0x02;
00214
00215
00216
00217
00218 P2MDOUT &= 0x3F;
00219 P2MDIN &= 0x3F;
00220
00221
00222
00223 ADT7486A_Init(SST_LINE);
00224
00225 #ifdef _LTC2489_
00226 LTC2489_Init();
00227 #endif
00228
00229 #ifdef _LTC2605_
00230 LTC2605_Init();
00231 #endif
00232
00233 #ifdef _PCA9536_
00234 PCA9536_Init();
00235 PCA9536_WriteByte (PCA9536_ADD,CMD_CONFIG_REG,PCA_OUT);
00236 #endif
00237
00238
00239 if (init) {
00240 }
00241
00242 for (i=0;i<8;i++)
00243 user_data.adc [i] = 0.0;
00244 rErr = 0x00;
00245 user_data.error = rErr;
00246 user_data.pca9536 = 0;
00247
00248 user_data.intemp[0] = 0;
00249 user_data.intemp[1] = 0;
00250 memset (&user_data.temp[0], 0, sizeof(user_data.temp));
00251 }
00252
00253
00254
00255 void user_write(unsigned char index) reentrant{
00256
00257
00258
00259
00260 if ((index >= FIRST_DAQ) && (index < LAST_DAQ)) {
00261 BiasIndex = (index - FIRST_DAQ);
00262 LTC2605_Flag = 1;
00263 }
00264
00265 if (index == PCA_INDEX)
00266 PCA9536_Flag = 1;
00267 return;
00268 }
00269
00270
00271
00272 unsigned char user_read(unsigned char index)
00273 {
00274 if(index);
00275
00276 return 0;
00277 }
00278
00279
00280
00281 unsigned char user_func(unsigned char *data_in, unsigned char *data_out)
00282 {
00283
00284 data_out[0] = data_in[0];
00285 data_out[1] = data_in[1];
00286 return 2;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295
00296 void user_loop(void)
00297 {
00298 unsigned char xdata i,channel;
00299 float xdata volt1, volt2;
00300 signed long xdata result1, result2;
00301 static unsigned char xdata adcChannel = N_CHANNEL;
00302
00303 if(adcChannel == N_CHANNEL) {
00304 adcChannel = CLEAR;
00305 LTC2489_StartConversion(ADDR_LTC2489[0], adcChannel);
00306 LTC2489_StartConversion(ADDR_LTC2489[1], adcChannel);
00307 } else {
00308 adcChannel++;
00309 adcChannel %= N_CHANNEL;
00310 if (!LTC2489_ReadConversion(ADDR_LTC2489[0], adcChannel, &result1)){
00311 result1 = -CONVER_FAC1;
00312 adc = 1;
00313 }
00314 if (!LTC2489_ReadConversion(ADDR_LTC2489[1], adcChannel, &result2)){
00315 result2 = -CONVER_FAC1;
00316 adc = 1;
00317 }
00318 volt1 = ((float)(result1 + CONVER_FAC1) * (float)(VREF /CONVER_FAC2));
00319 volt2 = ((float)(result2 + CONVER_FAC1) * (float)(VREF /CONVER_FAC2));
00320 channel = (adcChannel + (N_CHANNEL-1)) % N_CHANNEL;
00321 DISABLE_INTERRUPTS;
00322 user_data.volt[channel] = volt1;
00323 user_data.volt[channel+4]= volt2;
00324 user_data.adc[channel] = result1;
00325 user_data.adc[channel+4] = result2;
00326 ENABLE_INTERRUPTS;
00327 }
00328
00329 for (i=0;i<2;i++) {
00330 if (ADT7486A_Cmd(ADT7486A_addrArray[i], GetIntTemp, SST_LINE, &user_data.intemp[i])!= SUCCESS)
00331 INTtemp = 1;
00332 }
00333 if (ADT7486A_Cmd(ADT7486A_addrArray[0], GetExt1Temp, SST_LINE, &user_data.temp[0])!= SUCCESS)
00334 EXTtemp = 1;
00335 if(ADT7486A_Cmd(ADT7486A_addrArray[0], GetExt2Temp, SST_LINE, &user_data.temp[1])!= SUCCESS)
00336 EXTtemp = 1;
00337 if(ADT7486A_Cmd(ADT7486A_addrArray[1], GetExt1Temp, SST_LINE, &user_data.temp[2])!= SUCCESS)
00338 EXTtemp = 1;
00339 if(ADT7486A_Cmd(ADT7486A_addrArray[1], GetExt2Temp, SST_LINE, &user_data.temp[3]) != SUCCESS)
00340 EXTtemp = 1;
00341
00342 #ifdef _LTC2605_
00343 if (LTC2605_Flag){
00344 LTC2605_WriteByte(DAQ_ADDRESS,((WREG_n_UPDATE_n << 4) | BiasIndex),user_data.daq[BiasIndex]);
00345 LTC2605_Flag = 0;
00346 }
00347 #endif
00348
00349 #ifdef _PCA9536_
00350 if (PCA9536_Flag){
00351 PCA9536_WriteByte (PCA9536_ADD,CMD_OUTPUT_REG,user_data.pca9536);
00352 PCA9536_Flag = 0;
00353 }
00354 #endif
00355
00356 led_blink(1, 1, 250);
00357
00358 }