/************************************************************************ * * * Basic access to SPI EEPROM 25LC256. * * * * * * Author Date Comment * *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* * Michael Cecere 09/2006 ************************************************************************/ #include "system.h" extern SYS_Config_Struct SYS_Config; extern float DAC_REF; extern float DAC_CEIL; extern float DAC_FLOOR; extern float Gain_Adj[8][8]; Board_Cal_struct Board_Cal; // structure that holds all the calibration // data for all the boards /************************************************************************ * Function: EEPROMInit * * * * Preconditions: SPI module must be configured to operate with * * parameters: Master, MODE16 = 0, CKP = 1, SMP = 1. * * * * Overview: This function setup SPI IOs connected to EEPROM. * * * * Input: None. * * * * Output: None. * * * ************************************************************************/ void EEPROMInit() { char tstr[80]; // uncomment this function call for a new board's (or EEPROM) // initial configuration Init_EEPROM_Parameters(); //DB Load_Cal_Data(); // loads cal data into array structure Board_Cal. Read_Config_EEPROM(); Update_Cal_Data(SYS_Config.Board_ID); // Loads cal data into SYS_Config according to Board_ID sprintf(tstr,"\r\nSYS_Config.Board_ID = %d\n",SYS_Config.Board_ID); UART2PutStr(tstr); //(July) } /************************************************************************ * Function: EEPROMWriteByte() * * * * Preconditions: SPI module must be configured to operate with EEPROM. * * * * Overview: This function writes a new value to address specified. * * * * Input: Data to be written and address. * * * * Output: None. * * * ************************************************************************/ void EEPROMWriteByte(unsigned Data, unsigned Address) { EE_CS=1; NumNops(10); // write enable EE_CS=0; SPI2MPolPut(EEPROM_CMD_WREN); // WREN = "6" SPI2MPolIsTransmitOver(); mSPI2MPolGet(); EE_CS=1; NumNops(10); EE_CS = 0; // send write command, "2" SPI2MPolPut(EEPROM_CMD_WRITE); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); // send high byte SPI2MPolPut(Hi(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); // and then low byte SPI2MPolPut(Lo(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); // then put data byte SPI2MPolPut(Lo(Data)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); EE_CS=1; // wait for completion of previous write operation while(EEPROMReadStatus().Bits.WIP); } /************************************************************************ * Function: EEPROMReadByte() * * * * Preconditions: SPI module must be configured to operate with EEPROM. * * * * Overview: This function reads a value from address specified. * * * * Input: Address. * * * * Output: Data read. * * * ************************************************************************/ unsigned EEPROMReadByte(unsigned Address) { unsigned Temp; EE_CS=0; NumNops(10); SPI2MPolPut(EEPROM_CMD_READ); // READ = "3" SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(Hi(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(Lo(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(0); SPI2MPolIsTransmitOver(); Temp = mSPI2MPolGet(); EE_CS=1; return Temp; } /************************************************************************ * Function: EEPROMWriteEnable() * * * * Preconditions: SPI module must be configured to operate with EEPROM. * * * * Overview: This function allows a writing into EEPROM. Must be called * * before every writing command. * * * * Input: None. * * * * Output: None. * * * ************************************************************************/ void EEPROMWriteEnable() { EE_CS=0; SPI2MPolPut(EEPROM_CMD_WREN); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); EE_CS=1; } /************************************************************************ * Function: EEPROMReadStatus() * * * * Preconditions: SPI module must be configured to operate with EEPROM. * * * * Overview: This function reads status register from EEPROM. * * * * Input: None. * * * * Output: Status register value. * * * ************************************************************************/ union _EEPROMStatus_ EEPROMReadStatus() { char Temp; EE_CS=0; SPI2MPolPut(EEPROM_CMD_RDSR); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(0); SPI2MPolIsTransmitOver(); Temp = mSPI2MPolGet(); EE_CS=1; return (union _EEPROMStatus_)Temp; } /***************************************************************************** * Function: Ptr_To_EEPROM * Preconditions: EEPROM_Init * Overview: Saves data to EEPROM starting at location adr with data pointed * to by p_dat for num_bytes bytes * Input: none * Output: number of bytes written to EEPROM * ******************************************************************************/ unsigned int Ptr_To_EEPROM(unsigned int Address, unsigned char *p_dat, unsigned int NumBytes) { unsigned int n,index; char j, NotDone=1; EE_CS=1; NumNops(10); index = 0; while (NotDone) { // write enable EE_CS=0; NumNops(10); SPI2MPolPut(EEPROM_CMD_WREN); // WREN = "6" SPI2MPolIsTransmitOver(); mSPI2MPolGet(); EE_CS=1; NumNops(10); EE_CS = 0; // send write command, "2" NumNops(10); SPI2MPolPut(EEPROM_CMD_WRITE); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); // send high byte SPI2MPolPut(Hi(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); // and then low byte SPI2MPolPut(Lo(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); for (n=0; nNumBytes) break; } EE_CS=1; // wait to write this last page while(EEPROMReadStatus().Bits.WIP); if (index>NumBytes) NotDone = 0; Address = Address + EEPROM_PAGE_SIZE; } // end while NotDone index--; return index; } /***************************************************************************** * Function: Ptr_From_EEPROM * Preconditions: EEPROM_Init * Overview: Reads data from EEPROM starting at location adr into data pointed * to by p_dat for num_bytes bytes * Input: none * Output: number of bytes written to EEPROM * ******************************************************************************/ unsigned int Ptr_From_EEPROM(unsigned int Address, unsigned char *p_dat, unsigned int NumBytes) { unsigned int i,index=0; char c; EE_CS=0; NumNops(10); SPI2MPolPut(EEPROM_CMD_READ); // READ = "3" SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(Hi(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); SPI2MPolPut(Lo(Address)); SPI2MPolIsTransmitOver(); mSPI2MPolGet(); for (i=0;i22) ndig=23; fstyle = 0; //exponent 'e' if (format == 'f' || format == 'F') fstyle = 1; //normal 'f' if (format=='g' || format=='G') fstyle=2; ie = 0; /* if x negative, write minus and reverse */ // always include leading +/- so same total string length if ( x < 0) { *str++ = '-'; x = -x; } else { *str++ = '+'; } //if (x<0.0) then increment by 10 till betwen 1.0 and 10.0 if (x!=0.0) { while (x < 1.0) { x =x* 10.0; ie--; } } //if x>10 then let's shift it down while (x >= 10.0) { x = x*0.1; ie++; // this won't make it work but it won't hang up for ever either. if (ie>20) x=0; } if (ABS(ie)>MAX_MANTISA) { if (fstyle==1) { fstyle=0; format='e'; //ie=2; } } /* in f format, number of digits is related to size */ if (fstyle) ndig =ndig + ie; if(prec==0 && ie>ndig && fstyle) { ndig=ie; } /* round. x is between 1 and 10 and ndig will be printed to right of decimal point so rounding is ... */ y=1; for (i = 1; i < ndig; i++) //find lest significant digit y = y *0.1; //multiply by 1/10 is faster than divides x = x+ y *0.5; //add rounding /* repair rounding disasters */ if (x >= 10.0) { x = 1.0; ie++; ndig++; } //check and see if the number is less than 1.0 if (fstyle && ie<0) { *str++ = '0'; if (prec!=0) *str++ = '.'; if (ndig < 0) ie = ie-ndig; /* limit zeros if underflow */ for (i = -1; i > ie; i--) *str++ = '0'; } //for each digit for (i=0; i < ndig; i++) { float b; k = x; //k = most significant digit *str++ = k + '0'; //output the char representation if (((!fstyle && i==0) || (fstyle && i==ie)) && prec!=0) *str++ = '.'; //output a decimal point b=(float)k; //multiply by 10 before subtraction to remove //errors from limited number of bits in float. b=b*10.0; x=x*10.0; x =x - b; //subtract k from x //b=x+b; //x =x* 10.0; //get next digit } /* now, in estyle, put out exponent if not zero */ // if (!fstyle && ie != 0) if (!fstyle) { *str++ = format; if (ie < 0) //if number has negative exponent { ie = -ie; *str++ = '-'; } else { *str++ = '+'; } //now we need to convert the exponent to string for (k=1000; k>ie; k=k/10); //find the decade of exponent for (; k > 0; k=k/10) { char t; t=DIV(ie,k); *str++ = t + '0'; ie = ie -(t*k); } } *str++ = '\0'; return (str-start); //return string length } /***************************************************************************** * Function: Load_Cal_Data * Preconditions: none * Overview: loads calibration data for all boards into Board_Cal structure * Input: none * Output: * ******************************************************************************/ void Load_Cal_Data() { int Brd_ID; ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #1 ////////////////////////////////////////////////////////// // calibration constants for Board #1 Brd_ID = 0; // calibration constants for Board #1 Board_Cal.Cal_0pC[0][0] = .35; // was 0.26 before 2/6/2008 see page 50 of my notebook Board_Cal.Cal_0pC[0][1] = 0.0; // was also 0.0 before 2/6/2008 Board_Cal.Cal_0pC[0][2] = 1.8; Board_Cal.Cal_0pC[0][3] = -2.4; Board_Cal.Cal_200pC[0][0] = 205.5; Board_Cal.Cal_200pC[0][1] = 196.25; // was 201.5 before 2/6/2008 Board_Cal.Cal_200pC[0][2] = 193.3; Board_Cal.Cal_200pC[0][3] = 196.9; Board_Cal.Cal_1000pC[0][0] = 1006.2; // was 1005.5 before 2/6/2008 Board_Cal.Cal_1000pC[0][1] = 1006.2; // was 1001.6 b efore 2/6/2008 Board_Cal.Cal_1000pC[0][2] = 1001.6; Board_Cal.Cal_1000pC[0][3] = 993.4; // DAC calibration settings for Board #1 // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .2160; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .2278; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .2248; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .2310; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2260; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2270; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2270; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2221; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.2085; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.1955; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.1955; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.2075; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2211; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2256; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2266; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046339; // Larger gain because layout has more capacitance. Board_Cal.Chan_Gain[Brd_ID][1] = 0.046339; Board_Cal.Chan_Gain[Brd_ID][2] = 0.041872; Board_Cal.Chan_Gain[Brd_ID][3] = 0.041872; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041061; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041061; Board_Cal.Chan_Gain[Brd_ID][6] = 0.042989; Board_Cal.Chan_Gain[Brd_ID][7] = 0.042989; Board_Cal.Chan_Offset[Brd_ID][0] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][1] = -3.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][2] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][3] = -1.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][4] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][5] = -2.5; // offset in pC Board_Cal.Chan_Offset[Brd_ID][6] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][7] = -0.5; // offset in pC ////// end configuration data for Board #1 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #2 ////////////////////////////////////////////////////////// // calibration constants for Board #2 Brd_ID = 1; // calibration constants for Board #2 Board_Cal.Cal_0pC[1][0] = 1.96; Board_Cal.Cal_0pC[1][1] = 0.0; Board_Cal.Cal_0pC[1][2] = 1.8; Board_Cal.Cal_0pC[1][3] = -2.4; Board_Cal.Cal_200pC[1][0] = 204.4; Board_Cal.Cal_200pC[1][1] = 201.5; Board_Cal.Cal_200pC[1][2] = 193.3; Board_Cal.Cal_200pC[1][3] = 196.9; Board_Cal.Cal_1000pC[1][0] = 1005.4; Board_Cal.Cal_1000pC[1][1] = 1001.6; Board_Cal.Cal_1000pC[1][2] = 1001.6; Board_Cal.Cal_1000pC[1][3] = 993.4; // DAC calibration settings for Board #2 // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .2055; //DB Board_Cal.DAC_Act_0pC[Brd_ID][1] = .216; //DB Board_Cal.DAC_Act_0pC[Brd_ID][2] = .217; //DB Board_Cal.DAC_Act_0pC[Brd_ID][3] = .2185; //DB Board_Cal.DAC_Act_0pC[Brd_ID][4] = .1978; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .1978; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .1978; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .1978; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.2035; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.1955; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.2035; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.195; //DB Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.185; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.185; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.185; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.185; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046658; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046658; Board_Cal.Chan_Gain[Brd_ID][2] = 0.041784; Board_Cal.Chan_Gain[Brd_ID][3] = 0.041784; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041869; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041869; Board_Cal.Chan_Gain[Brd_ID][6] = 0.041227; Board_Cal.Chan_Gain[Brd_ID][7] = 0.041227; Board_Cal.Chan_Offset[Brd_ID][0] = 262.0; // offset in pC -4.25pC Board_Cal.Chan_Offset[Brd_ID][1] = 278.0; // offset in pC -5.50pC Board_Cal.Chan_Offset[Brd_ID][2] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][3] = -3.5; // offset in pC Board_Cal.Chan_Offset[Brd_ID][4] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][5] = -2.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][6] = 0.0; // offset in pC Board_Cal.Chan_Offset[Brd_ID][7] = -3.5; // offset in pC ///// end configuration data for Board #2 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #3 ////////////////////////////////////////////////////////// // calibration constants for Board #3 Brd_ID = 2; // calibration constants for Board #3 Board_Cal.Cal_0pC[2][0] = -2.9; Board_Cal.Cal_0pC[2][1] = 2.6; Board_Cal.Cal_0pC[2][2] = -2.6; Board_Cal.Cal_0pC[2][3] = -2.7; Board_Cal.Cal_200pC[2][0] = 194.1; Board_Cal.Cal_200pC[2][1] = 197.8; Board_Cal.Cal_200pC[2][2] = 195.4; Board_Cal.Cal_200pC[2][3] = 198.5; Board_Cal.Cal_1000pC[2][0] = 979.2; Board_Cal.Cal_1000pC[2][1] = 993.6; Board_Cal.Cal_1000pC[2][2] = 992.2; Board_Cal.Cal_1000pC[2][3] = 993.9; // DAC calibration settings for Board #3 // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .1995; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .1990; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .2045; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .2101; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2108; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .1994; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .1995; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .192; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.199; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.189; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.198; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.185; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.204; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.199; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.188; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.177; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046711; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046711; Board_Cal.Chan_Gain[Brd_ID][2] = 0.042427; Board_Cal.Chan_Gain[Brd_ID][3] = 0.042427; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041205; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041205; Board_Cal.Chan_Gain[Brd_ID][6] = 0.041992; Board_Cal.Chan_Gain[Brd_ID][7] = 0.041992; Board_Cal.Chan_Offset[Brd_ID][0] = 0.0; Board_Cal.Chan_Offset[Brd_ID][1] = -3.0; Board_Cal.Chan_Offset[Brd_ID][2] = 0.0; Board_Cal.Chan_Offset[Brd_ID][3] = -1.5; Board_Cal.Chan_Offset[Brd_ID][4] = 0.0; Board_Cal.Chan_Offset[Brd_ID][5] = -2.5; Board_Cal.Chan_Offset[Brd_ID][6] = 0.0; Board_Cal.Chan_Offset[Brd_ID][7] = -3.0; ////// end configuration data for Board #3 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #4 ////////////////////////////////////////////////////////// // calibration constants for Board #4 Brd_ID = 3; // calibration constants for Board #4 Board_Cal.Cal_0pC[2][0] = 0; Board_Cal.Cal_0pC[2][1] = 0; Board_Cal.Cal_0pC[2][2] = 0; Board_Cal.Cal_0pC[2][3] = 0; Board_Cal.Cal_200pC[2][0] = 200.; Board_Cal.Cal_200pC[2][1] = 200.; Board_Cal.Cal_200pC[2][2] = 200.; Board_Cal.Cal_200pC[2][3] = 200.; Board_Cal.Cal_1000pC[2][0] = 1000.; Board_Cal.Cal_1000pC[2][1] = 1000.; Board_Cal.Cal_1000pC[2][2] = 1000.; Board_Cal.Cal_1000pC[2][3] = 1000.; // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .211; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .200; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .203; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .202; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.202; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.175; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.182; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.192; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046242; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046242; Board_Cal.Chan_Gain[Brd_ID][2] = 0.042485; Board_Cal.Chan_Gain[Brd_ID][3] = 0.042485; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041577; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041577; Board_Cal.Chan_Gain[Brd_ID][6] = 0.042010; Board_Cal.Chan_Gain[Brd_ID][7] = 0.042010; Board_Cal.Chan_Offset[Brd_ID][0] = 0.0; Board_Cal.Chan_Offset[Brd_ID][1] = 0.0; Board_Cal.Chan_Offset[Brd_ID][2] = 0.0; Board_Cal.Chan_Offset[Brd_ID][3] = 0.0; Board_Cal.Chan_Offset[Brd_ID][4] = 0.0; Board_Cal.Chan_Offset[Brd_ID][5] = 0.0; Board_Cal.Chan_Offset[Brd_ID][6] = 0.0; Board_Cal.Chan_Offset[Brd_ID][7] = 0.0; ///// End Board Configuration Data Board #4 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #5 ////////////////////////////////////////////////////////// // calibration constants for Board #5 Brd_ID = 4; // calibration constants for Board #5 Board_Cal.Cal_0pC[2][0] = 0; Board_Cal.Cal_0pC[2][1] = 0; Board_Cal.Cal_0pC[2][2] = 0; Board_Cal.Cal_0pC[2][3] = 0; Board_Cal.Cal_200pC[2][0] = 200.; Board_Cal.Cal_200pC[2][1] = 200.; Board_Cal.Cal_200pC[2][2] = 200.; Board_Cal.Cal_200pC[2][3] = 200.; Board_Cal.Cal_1000pC[2][0] = 1000.; Board_Cal.Cal_1000pC[2][1] = 1000.; Board_Cal.Cal_1000pC[2][2] = 1000.; Board_Cal.Cal_1000pC[2][3] = 1000.; // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .204; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .200; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .207; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .208; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.200; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.195; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.203; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.195; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046109; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046109; Board_Cal.Chan_Gain[Brd_ID][2] = 0.041120; Board_Cal.Chan_Gain[Brd_ID][3] = 0.041120; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041728; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041728; Board_Cal.Chan_Gain[Brd_ID][6] = 0.041840; Board_Cal.Chan_Gain[Brd_ID][7] = 0.041840; Board_Cal.Chan_Offset[Brd_ID][0] = 0.; Board_Cal.Chan_Offset[Brd_ID][1] = 0.; Board_Cal.Chan_Offset[Brd_ID][2] = 0.; Board_Cal.Chan_Offset[Brd_ID][3] = 0.; Board_Cal.Chan_Offset[Brd_ID][4] = 0.; Board_Cal.Chan_Offset[Brd_ID][5] = 0.; Board_Cal.Chan_Offset[Brd_ID][6] = 0.; Board_Cal.Chan_Offset[Brd_ID][7] = 0.; ///// End Board Configuration Data Board #5 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #6 ////////////////////////////////////////////////////////// // calibration constants for Board #6 Brd_ID = 5; // calibration constants for Board #6 Board_Cal.Cal_0pC[2][0] = 0; Board_Cal.Cal_0pC[2][1] = 0; Board_Cal.Cal_0pC[2][2] = 0; Board_Cal.Cal_0pC[2][3] = 0; Board_Cal.Cal_200pC[2][0] = 200.; Board_Cal.Cal_200pC[2][1] = 200.; Board_Cal.Cal_200pC[2][2] = 200.; Board_Cal.Cal_200pC[2][3] = 200.; Board_Cal.Cal_1000pC[2][0] = 1000.; Board_Cal.Cal_1000pC[2][1] = 1000.; Board_Cal.Cal_1000pC[2][2] = 1000.; Board_Cal.Cal_1000pC[2][3] = 1000.; // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .199; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .204; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .210; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .200; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.208; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.196; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.194; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.196; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046548; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046548; Board_Cal.Chan_Gain[Brd_ID][2] = 0.041725; Board_Cal.Chan_Gain[Brd_ID][3] = 0.041725; Board_Cal.Chan_Gain[Brd_ID][4] = 0.042076; Board_Cal.Chan_Gain[Brd_ID][5] = 0.042076; Board_Cal.Chan_Gain[Brd_ID][6] = 0.041652; Board_Cal.Chan_Gain[Brd_ID][7] = 0.041652; Board_Cal.Chan_Offset[Brd_ID][0] = 0.; Board_Cal.Chan_Offset[Brd_ID][1] = 0.; Board_Cal.Chan_Offset[Brd_ID][2] = 0.; Board_Cal.Chan_Offset[Brd_ID][3] = 0.; Board_Cal.Chan_Offset[Brd_ID][4] = 0.; Board_Cal.Chan_Offset[Brd_ID][5] = 0.; Board_Cal.Chan_Offset[Brd_ID][6] = 0.; Board_Cal.Chan_Offset[Brd_ID][7] = 0.; ///// End Board Configuration Data Board #6 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #7 ////////////////////////////////////////////////////////// // calibration constants for Board #7 Brd_ID = 6; // calibration constants for Board #7 Board_Cal.Cal_0pC[2][0] = 0; Board_Cal.Cal_0pC[2][1] = 0; Board_Cal.Cal_0pC[2][2] = 0; Board_Cal.Cal_0pC[2][3] = 0; Board_Cal.Cal_200pC[2][0] = 200.; Board_Cal.Cal_200pC[2][1] = 200.; Board_Cal.Cal_200pC[2][2] = 200.; Board_Cal.Cal_200pC[2][3] = 200.; Board_Cal.Cal_1000pC[2][0] = 1000.; Board_Cal.Cal_1000pC[2][1] = 1000.; Board_Cal.Cal_1000pC[2][2] = 1000.; Board_Cal.Cal_1000pC[2][3] = 1000.; // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .202; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .209; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .205; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .214; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.209; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.191; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.206; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.210; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046440; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046440; Board_Cal.Chan_Gain[Brd_ID][2] = 0.041885; Board_Cal.Chan_Gain[Brd_ID][3] = 0.041885; Board_Cal.Chan_Gain[Brd_ID][4] = 0.041812; Board_Cal.Chan_Gain[Brd_ID][5] = 0.041812; Board_Cal.Chan_Gain[Brd_ID][6] = 0.041754; Board_Cal.Chan_Gain[Brd_ID][7] = 0.041754; Board_Cal.Chan_Offset[Brd_ID][0] = 0.; Board_Cal.Chan_Offset[Brd_ID][1] = 0.; Board_Cal.Chan_Offset[Brd_ID][2] = 0.; Board_Cal.Chan_Offset[Brd_ID][3] = 0.; Board_Cal.Chan_Offset[Brd_ID][4] = 0.; Board_Cal.Chan_Offset[Brd_ID][5] = 0.; Board_Cal.Chan_Offset[Brd_ID][6] = 0.; Board_Cal.Chan_Offset[Brd_ID][7] = 0.; ///// End Board Configuration Data Board #7 ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // BOARD #8 ////////////////////////////////////////////////////////// // calibration constants for Board #8 Brd_ID = 7; // calibration constants for Board #8 Board_Cal.Cal_0pC[2][0] = 0; Board_Cal.Cal_0pC[2][1] = 0; Board_Cal.Cal_0pC[2][2] = 0; Board_Cal.Cal_0pC[2][3] = 0; Board_Cal.Cal_200pC[2][0] = 200.; Board_Cal.Cal_200pC[2][1] = 200.; Board_Cal.Cal_200pC[2][2] = 200.; Board_Cal.Cal_200pC[2][3] = 200.; Board_Cal.Cal_1000pC[2][0] = 1000.; Board_Cal.Cal_1000pC[2][1] = 1000.; Board_Cal.Cal_1000pC[2][2] = 1000.; Board_Cal.Cal_1000pC[2][3] = 1000.; // measured by setting DAC to 0pC Board_Cal.DAC_Act_0pC[Brd_ID][0] = .208; Board_Cal.DAC_Act_0pC[Brd_ID][1] = .210; Board_Cal.DAC_Act_0pC[Brd_ID][2] = .210; Board_Cal.DAC_Act_0pC[Brd_ID][3] = .207; Board_Cal.DAC_Act_0pC[Brd_ID][4] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][5] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][6] = .2; Board_Cal.DAC_Act_0pC[Brd_ID][7] = .2; // measured by setting DAC to 1000pC Board_Cal.DAC_Act_1000pC[Brd_ID][0] = 3.212; Board_Cal.DAC_Act_1000pC[Brd_ID][1] = 3.178; Board_Cal.DAC_Act_1000pC[Brd_ID][2] = 3.183; Board_Cal.DAC_Act_1000pC[Brd_ID][3] = 3.189; Board_Cal.DAC_Act_1000pC[Brd_ID][4] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][5] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][6] = 3.2; Board_Cal.DAC_Act_1000pC[Brd_ID][7] = 3.2; // Channel Gains and offsets as determined on bench for calibration Board_Cal.Chan_Gain[Brd_ID][0] = 0.046693; Board_Cal.Chan_Gain[Brd_ID][1] = 0.046693; Board_Cal.Chan_Gain[Brd_ID][2] = 0.042313; Board_Cal.Chan_Gain[Brd_ID][3] = 0.042313; Board_Cal.Chan_Gain[Brd_ID][4] = 0.042120; Board_Cal.Chan_Gain[Brd_ID][5] = 0.042120; Board_Cal.Chan_Gain[Brd_ID][6] = 0.042017; Board_Cal.Chan_Gain[Brd_ID][7] = 0.042017; Board_Cal.Chan_Offset[Brd_ID][0] = 0.; Board_Cal.Chan_Offset[Brd_ID][1] = 0.; Board_Cal.Chan_Offset[Brd_ID][2] = 0.; Board_Cal.Chan_Offset[Brd_ID][3] = 0.; Board_Cal.Chan_Offset[Brd_ID][4] = 0.; Board_Cal.Chan_Offset[Brd_ID][5] = 0.; Board_Cal.Chan_Offset[Brd_ID][6] = 0.; Board_Cal.Chan_Offset[Brd_ID][7] = 0.; ///// End Board Configuration Data Board #8 } /***************************************************************************** * Function: Update_Cal_Data * Preconditions: Load_Cal_Data has been called * Overview: Loads the cal data into SYS_Config for the board ID set by Board_ID * Input: none * Output: none * ******************************************************************************/ void Update_Cal_Data(int ID) { int Chan; char tstr[80]; ID = ID - 1; for (Chan=0;Chan<8;Chan++) { // load in channel gain/offset coefficients SYS_Config.Chan_Gain[Chan] = Board_Cal.Chan_Gain[ID][Chan]; SYS_Config.Chan_Offset[Chan] = Board_Cal.Chan_Offset[ID][Chan]; SYS_Config.DAC_Err_Gain[Chan] = Board_Cal.DAC_Act_1000pC[ID][Chan]; //DB SYS_Config.DAC_Err_Offset[Chan] = Board_Cal.DAC_Act_0pC[ID][Chan]; //DB } sprintf(tstr,"\r\nSYS_Config.Chan_Gain[0] = %f\n",(double)SYS_Config.Chan_Gain[0] ); UART2PutStr(tstr); //(July) } //////////////////////////////////////////////////////////////////////////////// // ////// // Parameter Initilization Values ////// // ////// // Run this function once for a board's initial EEPROM configuration ////// // uncomment-out this function call in EEPROM_Init() ////// // Adjust MPS parameters as needed, possibly others ////// // which can be adjusted and saved later individually anyways ////// //////////////////////////////////////////////////////////////////////////////// void Init_EEPROM_Parameters() { int Chan; SYS_Config.NumDataAvg = 8; // # times to average acquired data SYS_Config.NumCalAvg = 8; // # times to average calibration data samples SYS_Config.CalRingBufSize = 8; // # times to average cal values SYS_Config.Chan_ON[0] = 1; // all chans enabled by default SYS_Config.Chan_ON[1] = 1; SYS_Config.Chan_ON[2] = 1; SYS_Config.Chan_ON[3] = 1; // Location "0" Gain_Adj[0][0] = 1.0; // IMO1: Gain_Adj[0][1] = 1.04; // IMO2: To correct gain error. Gain_Adj[0][2] = 1.0; // IMO3: Gain_Adj[0][3] = 1.0; // IMS1: // Location "1" Gain_Adj[1][0] = 1.0; // IMBC1I: Gain_Adj[1][1] = 1.0; // IMBC1O: Gain_Adj[1][2] = 1.0; // FC01: No Correction Gain_Adj[1][3] = 1.0; // FCG1: No Correction // Location "2" Gain_Adj[2][0] = 1.0667; // IMBC2I: Correction because gate width smaller Gain_Adj[2][1] = 1.0667; // IMBC2O: to avoid the bump. Gain_Adj[2][2] = 1.0667; // XXXXXX: Not Used Gain_Adj[2][3] = 1.0667; // XXXXXX: Not Used // Location "3" Gain_Adj[3][0] = 0.950000; // IM31: Correction for 521-ft of cable. Gain_Adj[3][1] = 0.983607; // IM36: Correction for 293-ft of cable. Gain_Adj[3][2] = 1.0; // XXXX: Not Used Gain_Adj[3][3] = 1.0; // XXXX: Not Used // Location "4" Gain_Adj[4][0] = 0.987654; // IMUNDI: 497-ft of cable. Preamp 9-22-10 Gain_Adj[4][1] = 0.995355; // IMUNDO: 142-ft of cable. Preamp 9-23-10 Gain_Adj[4][2] = 1.053371; // IMDUMP: Correction for 295-ft of cable. Gain_Adj[4][3] = 1.0; // XXXXXX: Not Used // Location "5" Gain_Adj[5][0] = 0.962406; // Modified for lab calibration plot 3-7-13 Gain_Adj[5][1] = 1.0; // Gain_Adj[5][2] = 1.0; // Gain_Adj[5][3] = 1.0; // for (Chan=0;Chan<4;Chan++) { SYS_Config.Chan_Cal[Chan] = 1.0; SYS_Config.Cal_Delay[Chan] = 93; // gets set by Init_Delays anyway SYS_Config.Cal_Pre_Trig[Chan] = 5; // delay after beginning of int window SYS_Config.Reset_Delay[Chan] = 20; // default. if(SYS_Config.Location_ID == 2) { SYS_Config.INT1_Width[Chan] = 14; // 117.6ns Sector 24 because of hump SYS_Config.INT2_Width[Chan] = 31; // 260.4ns Sector 24 because of hump SYS_Config.Reset_Delay[Chan] = 20 + 30 - SYS_Config.INT1_Width[Chan]; } else { SYS_Config.INT1_Width[Chan] = 30; // 252.0ns default value. SYS_Config.INT2_Width[Chan] = 62; // 520.8ns default value. } } for (Chan=0;Chan<4;Chan++) { CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_INT1); // set Integration #1 delay CPLD_Set_Data(SYS_Config.INT1_Width[Chan]); Latch_CPLD(); CPLD_Set_Mode(CPLD_INT2); // set Integration #2 delay CPLD_Set_Data(SYS_Config.INT2_Width[Chan]); Latch_CPLD(); CPLD_Set_Mode(CPLD_RESET); // set Reset delay CPLD_Set_Data(SYS_Config.Reset_Delay[Chan]); Latch_CPLD(); } // Get board ID. Get_Board_ID(0); /*SYS_Config.Firmware_Version = 2.25; // "2.00" Starts version numbers by David Brown. */ //SYS_Config.Firmware_Version = 2.30; // Adds MPS Comparison. //SYS_Config.Firmware_Version = 2.31; // Only corrects IM01 for Dark Current //SYS_Config.Firmware_Version = 2.40; // INT1->30,INT2->62, Cable delay factored in /*SYS_Config.Firmware_Version = 2.50; // Trigers -> 360, Cal Trig triggers write strobe. */ /*SYS_Config.Firmware_Version = 2.51; // Back to "INT2 - 2 * INT1" & undoes Cal Trig triggers write strobe. */ /*SYS_Config.Firmware_Version = 2.60; Adds Gain_Adj "G" from terminal port and location gain for LI24. Also adjusts the Reset Delay to compensate when Delay_1 is changed so the timing does not have to be moved. */ /*SYS_Config.Firmware_Version = 2.70; Adds Dark_Current_Corr array and eliminates the "2 * INT1". */ //SYS_Config.Firmware_Version = 2.80; // 1.) Goes back to "INT2 - 2 * INT1". // 2.) Dark_Current_Array goes away. // 3.) Gain_Adj now 2 dimensional array. //SYS_Config.Firmware_Version = 2.81; // 1.) IM31 Gain_Adj added for 521-ft of cable. //SYS_Config.Firmware_Version = 2.82; // 1.) Gain_Adj added Menu. // 2.) IM36 Gain_Adj added for 293-ft of cable. //SYS_Config.Firmware_Version = 2.83; // 1.) IM???? Gain_Adj added for xxx-ft of cable. //SYS_Config.Firmware_Version = 2.90; // 1.) Changed the 10% trip level to 20% for IM31/IM36, IMUNDI/IMUNDO and // IMUNDO/IMDUMP Because of the noise problem. DGB //SYS_Config.Firmware_Version = 3.00; // 1.) Changed greater then 50% level to set both bits. // 2.) Added if downstream is greater then upstream (due to spray) set both bits. //SYS_Config.Firmware_Version = 3.10; // 1.) Changed trip from 10%/50% to 3*10^8 electrons or 50pC. //SYS_Config.Firmware_Version = 3.20; // 1.) Trip on TWO consecutive bad pulses instead of ONE. //SYS_Config.Firmware_Version = 3.30; // 1.) while (!CAL_DONE) {} ; loop until CAL_DONE = 1 // changed to (!CAL_DONE && !CHAN_RDY_ALL) {} ; loop until CAL_DONE or CHAN_RDY_ALL = 1 // This needed to be done to work with my CPLD code instead of John's //SYS_Config.Firmware_Version = 3.40; // 1.) Changed from 2-consecutive errors to 5-consecutive errors before it trips because of IMUNDI noise. //SYS_Config.Firmware_Version = 3.41; // 1.) IMUNDI: Added preamp and recalibrated. //SYS_Config.Firmware_Version = 3.42; // 1.) IMUNDO: Added preamp and recalibrated. //SYS_Config.Firmware_Version = 3.43; // 1.) IM36: Added preamp and recalibrated. //SYS_Config.Firmware_Version = 3.44; // 1.) IM31: Added preamp and recalibrated. SYS_Config.Firmware_Version = 3.45; // 1.) IM31: Tweeked calibration. SYS_Config.LowerLimit_pC = 100; // 100pC Save_Config_EEPROM(); //////////////////////////////////////////////////////////////////////////////// ///// ////// ///// End parameter initialization section ////// ///// ////// //////////////////////////////////////////////////////////////////////////////// } // end Init_EEPROM_Parameters() /************************************************************************ * EOF ************************************************************************/