/***************************************************************************** * * UART Driver for PIC24. * *****************************************************************************/ #include "system.h" /***************************************************************************** * U2BRG register value *****************************************************************************/ #define BAUDRATEREG2 SYSCLK/4/BAUDRATE2-1 extern SYS_Config_Struct SYS_Config; extern float LINmAvg[]; extern float LINoffAvg[]; extern int PRINTON; extern int EXT_TRIG; extern float pC_Adj[]; extern float Gain_Adj[8][8]; extern unsigned long Data_Raw[]; extern int Cal_Charge_Delay; extern char Trig_Mask; extern float OC_THRESHOLD; unsigned int CAL_Reset[256]; int Force_MPSLevel = 4; int Force_MPSChan = 0; int Force_DAC_0pC, Force_DAC_200pC, Force_DAC_1000pC; /***************************************************************************** * Function: UART2Init * * Precondition: None. * * Overview: Setup UART2 module. * * Input: None. * * Output: None. * *****************************************************************************/ void UART2Init() { // Set directions of UART IOs UART2_TX_TRIS = 0; UART2_RX_TRIS = 1; U2BRG = BAUDRATEREG2; U2MODE = 0; U2STA = 0; U2MODEbits.UARTEN = 1; U2MODEbits.BRGH = 1; U2STAbits.UTXEN = 1; // reset RX flag IFS1bits.U2RXIF = 0; Force_DAC_0pC = 0; Force_DAC_200pC = 0; Force_DAC_1000pC = 0; } /***************************************************************************** * Function: UART2PutChar * * Precondition: UART2Init must be called before. * * Overview: Wait for free UART transmission buffer and send a byte. * * Input: Byte to be sent. * * Output: None. * *****************************************************************************/ void UART2PutChar(char Ch){ // wait for empty buffer while(U2STAbits.UTXBF == 1); U2TXREG = Ch; while(U2STAbits.UTXBF == 1); } /***************************************************************************** * Function: UART2IsPressed * * Precondition: UART2Init must be called before. * * Overview: Check if there's a new byte in UART reception buffer. * * Input: None. * * Output: Zero if there's no new data received. * *****************************************************************************/ char UART2IsPressed() { if(IFS1bits.U2RXIF == 1) return 1; return 0; } /***************************************************************************** * Function: UART2GetChar * * Precondition: UART2Init must be called before. * * Overview: Wait for a byte. * * Input: None. * * Output: Byte received. * *****************************************************************************/ char UART2GetChar(){ char Temp; while(IFS1bits.U2RXIF == 0); Temp = U2RXREG; IFS1bits.U2RXIF = 0; return Temp; } /***************************************************************************** * Function: UART2PutDec * * Precondition: UART2Init must be called before. * * Overview: This function converts decimal data into a string * and outputs it into UART. * * Input: Binary data. * * Output: None. * *****************************************************************************/ void UART2PutDec(unsigned Dec){ unsigned Res; int j; Res = Dec; j=Res/10000; if(j) UART2PutChar(j+'0'); else {UART2PutChar('0');} // leading zero Res = Res - j*10000; j=Res/1000; if(j) UART2PutChar(j+'0'); else {UART2PutChar('0');} // leading zero Res = Res - j*1000; j=Res/100; if(j) UART2PutChar(j+'0'); else {UART2PutChar('0');} // leading zero Res = Res - j*100; j=Res/10; if(j) UART2PutChar(j+'0'); else {UART2PutChar('0');} // leading zero Res = Res - j*10; UART2PutChar(Res+'0'); } /***************************************************************************** * Function: UART2PutStr * * Precondition: UART2Init must be called before. * * Overview: Sends a null terminated string through UART2PutChar * * Input: Null-terminated string to be sent. * * Output: None. * *****************************************************************************/ void UART2PutStr(char *str){ char tchar; while (*str) { tchar = *str++; UART2PutChar(tchar); while(U2STAbits.UTXBF == 1); } return; } /***************************************************************************** * Function: ProcessKeys() * * Precondition: UART2Init must be called before. * * Overview: unending scan for console keys * * Input: None. * * Output: None. * *****************************************************************************/ void ProcessKeys() { //static char L1=0,L2=0,L3=0; int i,j,k,Chan=4; unsigned long val1 = 0; unsigned long val2 = 0; unsigned long val3 = 0; float f1,f2; int index; unsigned int uint; char tchar; char tstr[100]=" "; static unsigned modetog=1; static unsigned enabletog=1; unsigned int Delay_End, Delay_Start, Peak_Start, Reset_peak_pos, Reset_peak_val; unsigned int Reset_min_pos, Reset_min_val, Reset_Avg, Delay; unsigned long Baseline1, Baseline2, Sig1, Sig2; unsigned long Data_Raw_Avg[8]; static int Man_MPS_T1 = 0; //static int Man_MPS_T2 = 0; //static int Man_MPS_T3 = 0; //static int Man_MPS_T4 = 0; //static int Man_MPS_C1 = 0; //static int Man_MPS_C2 = 0; //static int Man_MPS_C3 = 0; //static int Man_MPS_C4 = 0; float Temp_Err_Gain[8]; float Temp_Err_Offset[8]; ////////////////////////////////////////////////////////////////////////// // // see command "h" for a description of options // ////////////////////////////////////////////////////////////////////////// if (UART2IsPressed()) { tchar = UART2GetChar(); UART2PutChar(tchar); //hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh if (tchar=='h') { UART2PutStr("\n\r"); UART2PutStr("0 = Toggle DAC outputs to 0pC or free running\n\r"); UART2PutStr("1 = Toggle DAC outputs to 200pC or free running\n\r"); UART2PutStr("2 = Toggle DAC outputs to 1000pC or free running\n\r"); UART2PutStr("t = triggers all chans, then clears them 1mS later\n\r"); UART2PutStr("r = repeatedly trigger all channels, 20 times, every 500mS\n\r"); UART2PutStr("C = Sets Cal Delay, expects three decimal digits to follow\n\r"); UART2PutStr("R = Sets Reset Delay, expects three decimal digits to follow\n\r"); UART2PutStr("I = Sets INT1 Delay, expects three decimal digits to follow\n\r"); UART2PutStr("J = Sets INT2 Delay, expects three decimal digits to follow\n\r"); UART2PutStr("m = toggles through the 3 acq modes, Norm, 0pC, 200pC, 1000pC\n\r"); UART2PutStr("c = generate cal pulses @ 0,200, or 1000pC \n\r"); UART2PutStr("s = Saves SYS_Config array to EEPROM \n\r"); UART2PutStr("l = Loads SYS_Config array to EEPROM \n\r"); UART2PutStr("i = Init_Delays routine, resets CAL_DELAY, all channels \n\r"); UART2PutStr("u = Test Over Threshold Limit \n\r"); UART2PutStr("p = Toggles Un-solicited printing or not \n\r"); UART2PutStr("g = gets normal acq and writes to DAC \n\r"); UART2PutStr("e = toggles Ext Trigger Enable/Disable \n\r"); UART2PutStr("x = set the Trigger Mask with 00 to 32 \n\r"); UART2PutStr("0 = toggle ALL channels ON and OFF \n\r"); UART2PutStr("v = Display and Change Firmware Version # \n\r"); UART2PutStr("n = Set MPS Overcharge byte \n\r"); UART2PutStr("w = Set MPS Comparator byte \n\r"); UART2PutStr("b = Display and Set Board ID Number \n\r"); UART2PutStr("d = DAC calibration routine \n\r"); UART2PutStr("f = Set which channel is connected to a Faraday Cup \n\r"); UART2PutStr("q = Scan a Faraday Cup Channel for time delay \n\r"); UART2PutStr("z = Set each channels pC calibration factor \n\r"); UART2PutStr("k = Waits (for ever) for trigger and displays on console \n\r"); UART2PutStr("a = manual, benchtop calibration routine \n\r"); UART2PutStr("9 = set location ID \n\r"); UART2PutStr("8 = Init MPS Parameters \n\r"); UART2PutStr("7 = Manually set MPS outputs, followed by another digit, toggles \n\r"); UART2PutStr("6 = Force MPS output levels \n\r"); UART2PutStr("5 = Set LowerLimit_pC for no signal threshold level \n\r"); UART2PutStr("4 = Traveling '1' through MPS bits, use space bar to move. \n\r"); //DGB UART2PutStr("G = Set Gain Adjust. \n\r"); // DGB UART2PutStr("! = Resets all parameters stored in EEPROM to defaults!!!!!!\n\r"); } //000000000000000000000000000000000000000000000000000000000000000000000000000000 if (tchar=='0') { // toggle DAC outputs to 0pC or normal Force_DAC_0pC = !Force_DAC_0pC; if (Force_DAC_0pC) { UART2PutStr("DACs are being forced now at 0pC, ignoring ext triggers \n\r"); } else { UART2PutStr("Triggers free, no DAC driving \n\r"); } } //111111111111111111111111111111111111111111111111111111111111111111111111111111 if (tchar=='1') { // toggle DAC outputs to 200pC or normal trigs Force_DAC_200pC = !Force_DAC_200pC; if (Force_DAC_200pC) { UART2PutStr("DACs are being forced now at 200pC, ignoring ext triggers \n\r"); } else { UART2PutStr("Triggers free, no DAC driving \n\r"); } } //222222222222222222222222222222222222222222222222222222222222222222222222222222 if (tchar=='2') { // toggle DAC outputs to 1000pC or normal trigs Force_DAC_1000pC = !Force_DAC_1000pC; if (Force_DAC_1000pC) { UART2PutStr("DACs are being forced now at 1000pC, ignoring ext triggers \n\r"); } else { UART2PutStr("Triggers free, no DAC driving \n\r"); } } //333333333333333333333333333333333333333333333333333333333333333333333333333333 if (tchar=='3') // { } //444444444444444444444444444444444444444444444444444444444444444444444444444444 if (tchar=='4') { // Traveling '1' bit trough MPS bits. MPS_OverCharge(0); MPS_Comparator(0); j = 0; UART2PutStr("\n\n"); for(i=0; i<=4; i++) { MPS_OverCharge(j); sprintf(tstr, "\rMPS bits = %x\n\r", j); UART2PutStr(tstr); UART2PutStr("hit any key"); UART2GetChar(); j = j << 1; if(i == 0) j = 1; } MPS_OverCharge(0); j = 1; for(i=1; i<=8; i++) { MPS_Comparator(j); sprintf(tstr, "\rMPS bits = %x\n\r", j); UART2PutStr(tstr); UART2PutStr("hit any key"); UART2GetChar(); j = j << 1; } UART2PutStr("\rback to free run...\n\n\r"); } //tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt if (tchar=='t') { // manual trigger, once i=0; CPLD_Clr_All(); Set_ACQ_Mode(ACQ_MODE_1000pC, 0); // set for large calibration signal, no preset NumNops(Cal_Charge_Delay); i=0; while (i==0) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='3')) { index=tchar-'0'; i=1; } } } CPLD_Trig_All(); while (!CAL_DONE && !CHAN_RDY_ALL) {} val1 = 0; val2 = 0; MUX_Chan(index*2); for (i=0;i<8;i++) { uint = ADC_Chan(); val1 = val1 + uint; } MUX_Chan(index*2+1); for (i=0;i<8;i++) { uint = ADC_Chan(); val2 = val2 + uint; } CPLD_Clr_All(); val1 = val1 / 8; val2 = val2 / 8; val3 = val2 - val1; UART2PutStr("\r\nINT1 = "); UART2PutDec(val1); UART2PutStr(", "); f1=Clin(val1, index*2); ftoa(f1, tstr, 3, 'f'); UART2PutStr(tstr);UART2PutChar(13);UART2PutChar(10); UART2PutStr("\r\nINT2 = "); UART2PutDec(val2); UART2PutStr(", "); f2 = Clin(val2, index*2+1); ftoa(f2, tstr, 3, 'f'); UART2PutStr(tstr);UART2PutChar(13);UART2PutChar(10); UART2PutStr("\r\nDiff = "); UART2PutDec(val3); UART2PutStr(", "); ftoa(f2-f1, tstr, 3, 'f'); UART2PutStr(tstr);UART2PutChar(13);UART2PutChar(10); // restore acquisition mode for CPLD readiness Set_ACQ_Mode(ACQ_MODE_1000pC, 1); // set for large calibration signal, no preset NumNops(Cal_Charge_Delay); } //ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc if (tchar=='c') { // generate cal pulses UART2PutStr("\r\nGenerate a Calibration pulse \r\n"); UART2PutStr("Enter 1=0pC, 2=200pC, 3=1000pC\r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); tchar = tchar - '0'; if ((tchar>0) & (tchar<4)) { UART2PutStr("Acquisition mode set to "); UART2PutChar(tchar+'0'); UART2PutStr("\n\r"); Set_ACQ_Mode(tchar, 0); NumNops(Cal_Charge_Delay); } for (i=0;i<100;i++) { CPLD_Trig_All(); while (!CAL_DONE && !CHAN_RDY_ALL) {} Get_Data_ADC(); CPLD_Clr_All(); Delay_mS(10); } UART2PutStr("c function done\r\n"); UART2PutStr("press any key to continue\r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); UART2PutStr("Now back to your regular programming\r\n"); } // end 'c' function //rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr if (tchar=='r') { // auto trigger for 20 seconds for (i=0;i<40;i++) { CPLD_Trig_All(); Delay_mS(1); CPLD_Clr_All(); Delay_mS(500); } } //sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss if (tchar=='s') { // save configuration data to EEPROM UART2PutStr("Do you really want to Save Configuration to EEPROM ????? (y/n)\r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar=='y') | (tchar=='Y')) { i = Save_Config_EEPROM(); UART2PutDec(i); UART2PutStr("Configuration Bytes saved to EEPROM\r\n"); } else { UART2PutStr("Configuration Data NOT Saved to EEPROM !!! \r\n"); } tchar = ' '; } //lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll if (tchar=='l') { // load configuration data to EEPROM UART2PutStr("Do you really want to Load Configuration from EEPROM ????? (y/n)\r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar=='y') | (tchar=='Y')) { i=Read_Config_EEPROM(); UART2PutDec(i); UART2PutStr("Configuration Bytes Loaded from EEPROM\r\n"); } else { UART2PutStr("Configuration Bytes NOT Loaded from EEPROM !!!! \r\n"); } tchar = ' '; } //iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii if (tchar=='i') { // runs Init_Delays() routine to determince CAL_DELAY UART2PutStr("\r\n Really do a Init_Delays ??? (y/n) "); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar=='y') | (tchar=='Y')) { Init_Delays(); UART2PutStr("\r\n Init_delays() done \r\n"); } else { UART2PutStr("\r\n Init_Delays() NOT Done \r\n"); } } //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC // set cal delay, expects 'C' followed by three digits, 0-9, representing // digital value to send as delay setting if (tchar=='C') { UART2PutStr("\r\n the Calbration Delays are \r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutDec(Chan);UART2PutStr(" = "); UART2PutDec(SYS_Config.Cal_Delay[Chan]); UART2PutStr("\r\n"); } UART2PutStr("enter the channel # to change the cal delay for or 'x' for no changes "); i=0; while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<'4')) { Chan = tchar-'0'; UART2PutStr("\r\nNow enter three decimal digits, 0-9, with leading zeros as necessary\r\n"); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if ((j>=0) && (j<256)) { SYS_Config.Cal_Delay[Chan] = j; CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_CAL); CPLD_Set_Data(SYS_Config.Cal_Delay[Chan]); Latch_CPLD(); } UART2PutStr("\n\rCal Delay set\n\r"); } // end if good char UART2PutStr("\r\n the Calbration Delays are \r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutDec(Chan);UART2PutStr(" = "); UART2PutDec(SYS_Config.Cal_Delay[Chan]); UART2PutStr("\r\n"); } UART2PutStr("\n\rCal Delay DONE\n\r"); tchar = 0; } // end 'C' function //RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR // set Reset delay, expects 'R' followed by three digits, 0-9, representing // digital value to send as delay setting if (tchar=='R') { UART2PutStr("\r\nNow enter three decimal digits, 0-9, with leading zeros as necessary"); UART2PutStr("\r\nor 'x' to leave as it is\r\n"); UART2PutStr("Chan 1 - 4 = ");UART2PutChar(13);UART2PutChar(10); for (i=0;i<4;i++) { UART2PutDec(SYS_Config.Reset_Delay[i]); } UART2PutChar(10);UART2PutChar(13); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if (tchar=='x') { i=3; j=1000; } if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if ((j>=0) && (j<256)) for (i=0;i<4;i++) { SYS_Config.Reset_Delay[i] = j; CPLD_Set_Chan(i); CPLD_Set_Mode(CPLD_RESET); CPLD_Set_Data(j); Latch_CPLD(); } UART2PutStr("\n\rReset Delay set\n\r"); tchar = 0; } // end 'R' function //IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII // set INT1 delay, expects 'I' followed by three digits, 0-9, representing // digital value to send as delay setting if (tchar=='I') { UART2PutStr("\r\nNow enter three decimal digits, 0-9, with leading zeros as necessary"); UART2PutStr("\r\nor 'x' to leave as it is\r\n"); UART2PutStr("Chan 1 - 4 = ");UART2PutChar(13);UART2PutChar(10); for (i=0;i<4;i++) { UART2PutDec(SYS_Config.INT1_Width[i]); } UART2PutChar(10);UART2PutChar(13); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if (tchar=='x') { UART2PutStr("\n\rINT1 Delay NOT Set\n\r"); return; } if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if (j<0) j=0; for (i=0;i<4;i++) { SYS_Config.Reset_Delay[i] = SYS_Config.Reset_Delay[i] + SYS_Config.INT1_Width[i] - j; SYS_Config.INT1_Width[i] = j; CPLD_Set_Chan(i); CPLD_Set_Mode(CPLD_INT1); CPLD_Set_Data(j); Latch_CPLD(); } for (i=0;i<4;i++) { CPLD_Set_Chan(i); CPLD_Set_Mode(CPLD_RESET); CPLD_Set_Data(SYS_Config.Reset_Delay[i]); Latch_CPLD(); } UART2PutStr("\n\rINT1 Delay set\n\r"); tchar = 0; sprintf(tstr,"\r\nSYS_Config.Reset_Delay = %d\r\n", SYS_Config.Reset_Delay[0]); UART2PutStr(tstr); } // end 'I' function //JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ // set INT2 delay, expects 'J' followed by three digits, 0-9, representing // digital value to send as delay setting if (tchar=='J') { UART2PutStr("\r\nNow enter three decimal digits, 0-9, with leading zeros as necessary"); UART2PutStr("\r\nor 'x' to leave as it is\r\n"); UART2PutStr("Chan 1 - 4 = ");UART2PutChar(13);UART2PutChar(10); for (i=0;i<4;i++) { UART2PutDec(SYS_Config.INT2_Width[i]+1); } UART2PutChar(10);UART2PutChar(13); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if (tchar=='x') { i=3; j=1000; } if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if ((j>=0) && (j<256)) j = j - 1; if (j<0) j = 0; for (i=0;i<4;i++) { SYS_Config.INT2_Width[i] = j; CPLD_Set_Chan(i); CPLD_Set_Mode(CPLD_INT2); CPLD_Set_Data(j); Latch_CPLD(); } UART2PutStr("\n\rINT2 Delay set\n\r"); tchar = 0; } // end 'J' function //mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm if (tchar=='m') { // toggle through acquistion modes modetog = modetog + 1; if (modetog>3) modetog = 0; CPLD_Set_Chan(0); // doesn't actually matter CPLD_Set_Mode(CPLD_ACQ); CPLD_Set_Data(modetog); Latch_CPLD(); UART2PutStr("Acquisition mode set to "); UART2PutChar(modetog+'0'); UART2PutStr("\n\r"); UART2PutStr("0=Norm, 1=0pC, 2=200pC, 3=1000pC\r\n"); } //uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu if (tchar=='u') // Test Over Threshold Limit { if(OC_THRESHOLD == 1200.) OC_THRESHOLD = 900.; else OC_THRESHOLD = 1200.; Init_MPS_Parameters(); sprintf(tstr,"\n\rOC_THRESHOLD = %4.0f\n\r", (double)OC_THRESHOLD); UART2PutStr(tstr); } // end "Test Over Threshold Limit" //ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp if (tchar=='p') { // toggle printing PRINTON = !PRINTON; if (PRINTON) UART2PutStr("\r\n Printing is Now Enabled\r\n"); else UART2PutStr("\r\n Print is Now Dis-Abled\r\n"); } //ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg if (tchar=='g') { // Execute an acquisition sequence if (modetog==0) modetog = ACQ_MODE_1000pC; // or it needs to wait for CHAN_RDY_ALL Set_ACQ_Mode(modetog, 0); // set for calibration signal, no preset NumNops(Cal_Charge_Delay); i=0; CPLD_Trig_All(); i=0; while (!CAL_DONE && !CHAN_RDY_ALL) {} i=0; Get_Data_ADC(); // put averaged ADC counts into Data_Raw[] i=0; Delay_mS(1); CPLD_Clr_All(); Scale_Data_pC(); // scale Data_Raw into pC_Adj[] i=0; for (Chan=0;Chan<4;Chan++) { if (SYS_Config.Chan_ON[Chan]==1) { UART2PutStr("\r\nChan "); UART2PutDec(Chan); UART2PutStr(": INT1 = "); UART2PutDec(Data_Raw[Chan*2]); UART2PutStr(" INT2 = "); UART2PutDec(Data_Raw[Chan*2+1]); UART2PutStr(" DIFF = "); UART2PutDec((Data_Raw[Chan*2+1] - Data_Raw[Chan*2])); UART2PutStr("\r\nChan "); UART2PutDec(Chan); UART2PutStr(": INT1 = "); ftoa(pC_Adj[Chan*2], tstr, 2, 'f'); UART2PutStr(tstr); UART2PutStr(" INT2 = "); ftoa(pC_Adj[Chan*2+1], tstr, 2, 'f'); UART2PutStr(tstr); UART2PutStr(" DIFF = "); ftoa((pC_Adj[Chan*2+1] - pC_Adj[Chan*2]), tstr, 2, 'f'); UART2PutStr(tstr); } } UART2PutChar(10);UART2PutChar(13); i=0; Write_pC_DAC(); Set_ACQ_Mode(ACQ_MODE_1000pC, 1); // set for large calibration signal, preset NumNops(Cal_Charge_Delay); } // end 'g', get ADC channel //eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee if (tchar=='e') { // toggle Ext Trigger Enable EXT_TRIG = !EXT_TRIG; if (EXT_TRIG) { Trigger_Enable(Trig_Mask); UART2PutStr("\r\n Trigger Mask Now Set To "); UART2PutDec(Trig_Mask); } else { Trigger_Enable(Trig_None); CPLD_Clr_All(); CPLD_Clr_All(); UART2PutStr("\r\n Trigger Mask Now Set To "); UART2PutDec(Trig_None); } } // end 'e' trigger enable function //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx if (tchar=='x') { // set trigger_mask UART2PutStr("\r\n Enter a number between 0 and 32 for the Trig_Mask = "); i=0; j=0; while (i<2) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if ((j>=0) & (j<33)) { Trig_Mask = j; } UART2PutStr("\r\n Trig_Mask set to = "); UART2PutDec(Trig_Mask);UART2PutChar(10);UART2PutChar(13); } // end 'x' set trigger mask value //0000000000000000000000000000000000000000000000000000000000000000000000000000000 if (tchar=='o') { // toggle all channels on or off if (enabletog) { for (Chan=0;Chan<4;Chan++) { SYS_Config.Chan_ON[Chan] = 1; enabletog=0; } UART2PutStr("\r\nAll Channels Now ENABLED \r\n"); } else { for (Chan=0;Chan<4;Chan++) { SYS_Config.Chan_ON[Chan] = 0; enabletog = 1; } UART2PutStr("\r\nAll Channels Now DISABLED \r\n"); } } //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv if (tchar=='v') { // Displays and Sets Version number of this software UART2PutStr("\r\nPresent Version number of this software is = "); ftoa(SYS_Config.Firmware_Version, tstr, 2, 'f'); UART2PutStr(tstr); UART2PutStr("\r\n 'x' leaves unchanged "); UART2PutStr("\r\nEnter two digits for suffix of version # 1."); i=0; j=0; while (i<2) { if (UART2IsPressed()) { tchar = UART2GetChar(); if (tchar=='x') i=3; if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if (i!=3) { f1 = (float) (1. + j/100.); SYS_Config.Firmware_Version = f1; i = Save_Config_EEPROM(); UART2PutDec(i); UART2PutStr("\r\nConfiguration Bytes saved to EEPROM\r\n"); } } // end version control routine //nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn if (tchar=='n') { // Set MPS Overcharge byte UART2PutStr("\r\nEnter two digits from 00 to 15 for MPS OverCharge byte "); i=0; j=0; while (i<2) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; } if (tchar=='x') i=2; } } MPS_OverCharge(j); UART2PutStr("\r\nMPS_OverCharge byte set to "); UART2PutDec(j);UART2PutChar(10);UART2PutChar(13); } // end MPS Overcharge byte setting //wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww if (tchar=='w') { // Set MPS Comparator byte UART2PutStr("\r\nEnter two digits from 00 to 15 for MPS Comparator byte"); i=0; j=0; while (i<2) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; } if (tchar=='x') i=2; } } if ((j>=0) && (j<=255)) { MPS_Comparator(j); UART2PutStr("\r\nMPS_Comparator byte set to "); UART2PutDec(j);UART2PutChar(10);UART2PutChar(13); } } // end MPS Comparator byte setting //bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb if (tchar=='b') { // Display and Set Board ID Number UART2PutStr("\r\nBoard ID is set to "); UART2PutDec(SYS_Config.Board_ID); UART2PutStr("\r\nEnter a 1 digit Board ID Number or 'x' to exit "); i=0; j=0; while (!i) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=(tchar-'0'); i++; } if (tchar=='x') i=3; } } SYS_Config.Board_ID = j; if (i<3) { UART2PutStr("\r\nBoard ID set to "); UART2PutDec(SYS_Config.Board_ID);UART2PutChar(10);UART2PutChar(13); i = Save_Config_EEPROM(); UART2PutDec(i); UART2PutStr("Configuration Bytes saved to EEPROM\r\n"); } // now copy cal data for this board into SYS_Config Update_Cal_Data(SYS_Config.Board_ID); } // end Board ID routine //ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd if (tchar=='d') { // DAC calibration Routine // remember present settings of DAC calibration for this board // and set new values to the "perfect" values for (Chan=0;Chan<8;Chan++) { Temp_Err_Gain[Chan] = SYS_Config.DAC_Err_Gain[Chan]; Temp_Err_Offset[Chan] = SYS_Config.DAC_Err_Offset[Chan]; SYS_Config.DAC_Err_Gain[Chan] = 0.0; SYS_Config.DAC_Err_Offset[Chan] = 1.0; } for (Chan=0;Chan<8;Chan++) { i = Toroid_DAC_Scale(0., Chan); j=0; DAC_Write(i, Chan); UART2PutDec(Chan);UART2PutStr(" ");UART2PutDec(i);UART2PutStr("\r\n"); } UART2PutStr("\r\nOutputs set to 0pC \r\n"); UART2PutStr("Measure actual outputs for all 8 channels and record \r\n"); UART2PutStr("Then hit any key to continue \r\n"); j=0; /* while (!UART2IsPressed()) {} tchar = UART2GetChar(); UART2PutStr("\r\n Now set outputs to 200pC \r\n"); for (Chan=0;Chan<8;Chan++) { i = Toroid_DAC_Scale(200., Chan); DAC_Write(i, Chan); UART2PutDec(Chan);UART2PutStr(" ");UART2PutDec(i);UART2PutStr("\r\n"); } */ j=0; while (!UART2IsPressed()) {} tchar = UART2GetChar(); for (Chan=0;Chan<8;Chan++) { i = Toroid_DAC_Scale(1000., Chan); DAC_Write(i, Chan); UART2PutDec(Chan);UART2PutStr(" ");UART2PutDec(i);UART2PutStr("\r\n"); } j=0; UART2PutStr("\r\n Ouputs to 1000pC \r\n"); UART2PutStr("Measure actual outputs for all 8 channels and record \r\n"); UART2PutStr("Then hit any key to continue \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); // reset present settings of DAC calibration for this board for (Chan=0;Chan<8;Chan++) { SYS_Config.DAC_Err_Gain[Chan] = Temp_Err_Gain[Chan]; SYS_Config.DAC_Err_Offset[Chan] = Temp_Err_Offset[Chan]; } UART2PutStr("\r\n DAC Cal Done, original DAC Cal values have been restored \r\n"); } // end DAC calibration routine //ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff if (tchar=='f') { UART2PutStr("\r\nthe present channel assignment is \r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutStr("Chan # ");UART2PutDec(Chan); UART2PutStr(" is "); if (SYS_Config.Chan_Faradaycup[Chan]) UART2PutStr(" Faraday Cup\r\n"); else UART2PutStr(" Toroid\r\n"); } UART2PutStr("enter the channel # to make Faraday Cup or 'x' for no changes "); i=0; while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<'4')) { Chan = tchar-'0'; UART2PutStr("\r\nIs this chan a Toroid or Faraday cup? [T/F] "); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if (tchar=='T') { SYS_Config.Chan_Faradaycup[Chan] = 0; // SYS_Config.Chan_ON[Chan]=1; } if (tchar=='F') { SYS_Config.Chan_Faradaycup[Chan] = 1; SYS_Config.Chan_ON[Chan]=1; } UART2PutStr("\r\nRemember to save to EEPROM if desired\r\n"); } UART2PutStr("\r\nthe present channel assignment is \r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutStr("Chan # ");UART2PutDec(Chan); UART2PutStr(" is "); if (SYS_Config.Chan_Faradaycup[Chan]) UART2PutStr(" Faraday Cup\r\n"); else UART2PutStr(" Toroid\r\n"); } } // end faraday cup routine //qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq if (tchar=='q') { UART2PutStr("\r\nEnter the channel numbmer to scan"); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if ((tchar>='0') & (tchar<'4')) { Chan=tchar-'0'; Trigger_Enable(Trig_None); CPLD_Clr_All(); Set_ACQ_Mode(ACQ_MODE_1000pC, 0); NumNops(Cal_Charge_Delay); CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_INT1); CPLD_Set_Data(SYS_Config.Cal_Delay[Chan]); Latch_CPLD(); // latch data into CPLD CPLD_Set_Mode(CPLD_INT2); CPLD_Set_Data((unsigned)SYS_Config.INT1_Width); Latch_CPLD(); // CPLD_Set_Mode(CPLD_RESET); // CPLD_Set_Data(1); // Latch_CPLD(); // can't go past end of INT2 window or CPLD will lock up Delay_End = 255; // 95 + 1 + INT2_CAL - 1; Delay_Start = 0; Peak_Start = 4; // zero peaks memory Reset_peak_pos = 0; // holds the channel with the peak value (delay position) Reset_peak_val = 0; // holds the peak value of that channel Reset_min_pos = 0; // holds the channel with the peak value (delay position) Reset_min_val = 65535; // holds the min value of that channel Reset_Avg=0; CPLD_Set_Chan(Chan); //DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD // scan all possible delay values for (Delay=0;DelayPeak_Start) { if (CAL_Reset[Delay] > Reset_peak_val) { Reset_peak_val = CAL_Reset[Delay]; Reset_peak_pos = Delay; } if (CAL_Reset[Delay] < Reset_min_val) { Reset_min_val = CAL_Reset[Delay]; Reset_min_pos = Delay; } } i=0; i=0; //////////////////////////////////////////////////////////////////////// } // end delay scan /* UART2PutStr("\r\n"); for (Delay=0;Delay<256;Delay++) { UART2PutDec(Delay); i=CAL_Reset[Delay]/300; for (j=0;j='0') & (tchar<'4')) { Chan = tchar-'0'; UART2PutStr("\r\nNow enter three digits, as in 1.xxx\r\n"); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if ((tchar>='0') && (tchar<='9')) { j=j*10+(tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if (j==0) j=1000; SYS_Config.Chan_Cal[Chan] = (float) (j/1000.); } else { UART2PutStr("\r\n values not changed \r\n"); } UART2PutStr("\r\nthe present channel calibration factors are \r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutStr("Chan # ");UART2PutDec(Chan); UART2PutStr(" = "); ftoa(SYS_Config.Chan_Cal[Chan], tstr, 3, 'f'); UART2PutStr(tstr); UART2PutStr("\r\n"); } } // end of 'z' calibration setting ////////////////////////////////////////////////////////////////////////////// //kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk // Waits (for ever) for a trigger and reads and displays it on the console if (tchar=='k') { UART2PutStr("\r\n"); for (i=0;i<8;i++) { Data_Raw_Avg[i] = 0; } for (i=0;i<10;i++) { while (!CHAN_RDY_ALL) { } Get_Data_ADC(); CPLD_Clr_All(); k=0; for (j=0;j<8;j++) { Data_Raw_Avg[j] = Data_Raw_Avg[j] + Data_Raw[j]; } k=0; } for (i=0;i<8;i++) { Data_Raw[i] = Data_Raw_Avg[i] / 10.0;; } k=0; // scale data into pC_Adj[] Scale_Data_pC(); k=0; // writes all enabled channels to DAC Write_pC_DAC(); for (i=0;i<8;i=i+2) { UART2PutDec(Data_Raw[i]);UART2PutStr(" ");UART2PutDec(Data_Raw[i+1]);UART2PutStr(" | "); } UART2PutStr("\r\n"); for (i=0;i<4;i++) { ftoa(pC_Adj[i], tstr, 3, 'f'); UART2PutStr(tstr);UART2PutStr(" "); } UART2PutStr("\r\n"); } // end kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk ////////////////////////////////////////////////////////////////////////////// //aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa // manual, benchtop calibration routine if (tchar=='a') { UART2PutStr("\r\nEnter the channel number to calibrate, 0 - 3"); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if ((tchar>='0') & (tchar<'4')) { Chan=tchar-'0'; UART2PutStr("\r\n Attach 50 Ohm termination to that channel \r\n"); UART2PutStr(" Hit any key when ready \r\n"); while (!UART2IsPressed()) {} // wait forever for a key press tchar=UART2GetChar(); Set_ACQ_Mode(ACQ_MODE_1000pC, 0); // no preset NumNops(Cal_Charge_Delay); Baseline1 = 0; Baseline2 = 0; for (i=0;i<10;i++) { // get baseline data while (!CHAN_RDY_ALL) { } Get_Data_ADC(); CPLD_Clr_All(); Baseline1 = Baseline1 + Data_Raw[Chan*2]; Baseline2 = Baseline2 + Data_Raw[Chan*2+1]; } // end averaging loop Baseline1 = Baseline1 / 10; Baseline2 = Baseline2 / 10; UART2PutStr(" Baseline for INT1 = ");UART2PutDec(Baseline1);UART2PutStr("\r\n"); UART2PutStr(" Baseline for INT2 = ");UART2PutDec(Baseline2);UART2PutStr("\r\n"); UART2PutStr(" Now connect a calibrated pulse to that channel \r\n"); UART2PutStr(" Hit any key when ready \r\n"); while (!UART2IsPressed()) {} // wait forever for a key press tchar=UART2GetChar(); Sig1 = 0; Sig2 = 0; for (i=0;i<10;i++) { // get baseline data while (!CHAN_RDY_ALL) {} Get_Data_ADC(); CPLD_Clr_All(); Sig1 = Sig1 + Data_Raw[Chan*2]; Sig2 = Sig2 + Data_Raw[Chan*2+1]; } // end averaging loop Sig1 = Sig1 / 10; Sig2 = Sig2 / 10; UART2PutStr(" Signal for INT1 = ");UART2PutDec(Sig1);UART2PutStr("\r\n"); UART2PutStr(" Signal for INT2 = ");UART2PutDec(Sig2);UART2PutStr("\r\n"); } // end if channel number good } // end "a" manual calibration routine // start location setting routine if (tchar=='9') { UART2PutStr("\r\nEnter the location index for this board, 0 - 4 \r\n"); UART2PutStr("0 = LKG21-1405 IM01,IM02,IM03,IMS1\r\n"); UART2PutStr("1 = LKG21-1407 IMBC1I,IMBC1O,FC01,FCG1\r\n"); UART2PutStr("2 = LKF24-1306 IMBC2I,IMBC2O\r\n"); UART2PutStr("3 = B911-2206 IM31,IM36\r\n"); UART2PutStr("4 = B921-2306 IMUNDI,IMUNDO,IMDUMP\r\n"); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if ((tchar>='0') & (tchar<'5')) { SYS_Config.Location_ID=tchar-'0'; } UART2PutStr("Location set to ");UART2PutDec(SYS_Config.Location_ID); } // end "z" set location ID //888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888 if (tchar=='8') { // Run MPS Init routine Init_MPS_Parameters(); UART2PutStr("MPS Parameters set to defaults, but not saved \r\n"); } // end MPS update routine //777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777 if (tchar=='7') { // manually enter MPS outputs UART2PutStr("Enter second digit for MPS toggle \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<'9')) { i = tchar - '0'; } if (i==1) { // toggle overcharge on chan 0 if (!Man_MPS_T1) { Man_MPS_T1 = 1; MPS_OverCharge(1); UART2PutStr("Chan 1 set to overcharge, FAULT \r\n"); } else { Man_MPS_T1 = 0; MPS_OverCharge(0); UART2PutStr("Chan 1 set to NO overcharge \r\n"); } } if (i==5) { // get another char for comparator level 1 or 2 i=0; UART2PutStr(" Enter 0 = Fault, 1 = Level1, 2 = Level2, 3 = OK \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<='3')) { i = tchar - '0'; i = 3 - i; MPS_Comparator(i); // first comp. chan is first two bits UART2PutStr("Comparator 1 set to ");UART2PutDec(i);UART2PutStr("\r\n"); } } if (i==6) { // get another char for comparator level 1 or 2 i=0; UART2PutStr(" Enter 0 = Fault, 1 = Level-1 >10% loss, 2 = Level-2 >50% loss, 3 = OK \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<='3')) { i = tchar - '0'; i = 3 - i; MPS_Comparator(i*4); // second comp chan is 3rd and 4th bits UART2PutStr("Comparator 2 set to ");UART2PutDec(i);UART2PutStr("\r\n"); } } UART2PutStr(" Hit any key when done, NOT responding to triggers now \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); UART2PutStr(" Back to free running now \r\n"); } // end manually entering MPS outputs //66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 if (tchar=='6') { // manually force MPS outputs if (Force_MPSLevel <=3) { // then it's already being forced Force_MPSLevel = 4; // so disable it Force_MPSChan = 4; } else { //must = 4, disabled already Force_MPSChan = 0; UART2PutStr("Enter Comparator channel to control, 0 - 3 "); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<='3')) { Force_MPSChan = tchar - '0'; } UART2PutStr("Enter 0 = Fault, 1 = Level-1 >10% loss, 2 = Level-2 >50% loss, 3 = OK \r\n"); while (!UART2IsPressed()) {} tchar = UART2GetChar(); if ((tchar>='0') & (tchar<='3')) { i = tchar - '0'; Force_MPSLevel = i; // force pC_Adj values to simulate } UART2PutStr("Hit 6 again to free MPS outputs \r\n"); } UART2PutDec(Force_MPSLevel);UART2PutStr(" = Force_MPSLevel \r\n"); } //5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555 if (tchar=='5') { // set lower limit for signal detection UART2PutStr("Lower Limit is now ");UART2PutDec(SYS_Config.LowerLimit_pC);UART2PutStr("\r\n"); UART2PutStr("Enter three digits in units of (int) pC = "); i=0; j=0; while (i<3) { if (UART2IsPressed()) { tchar = UART2GetChar(); if (tchar=='x') i=4; if ((tchar>='0') && (tchar<='9')) { j= j*10 + (tchar-'0'); i++; UART2PutChar(tchar); } // is good char } // if keypressed } // end while if (i!=4) { if ((j>=0) & (j<1000)) SYS_Config.LowerLimit_pC = j; } UART2PutStr("Lower Limit is now ");UART2PutDec(SYS_Config.LowerLimit_pC);UART2PutStr("\r\n"); UART2PutStr("Remember to Save to EEPROM is desired \r\n"); } // end '5' set lower limit /////////////////////////////////////////////////////////////////////////////////// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // RESETS ALL PARAMETERS STORED IN EEPROM TO NOMINAL VALUES // USE CAUTIOUSLY!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1 if (tchar=='!') { UART2PutStr("\r\n"); UART2PutStr("\r\nARE YOU REALLY SURE YOU REALLY WANT TO RESET ALL EEPROM PARAMETER?"); UART2PutStr("\r\n ALL THE PRESENT VALUES WILL BE FOREVER LOST !!!!"); UART2PutStr("\r\n HIT 'Y' FOR RESETTING ALL DATA, 'N' TO NOT DO ANYTHING"); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if (tchar=='Y') { UART2PutStr("\r\n OK, this will erase all present values !!!"); UART2PutStr("\r\n enter 'Y' again to really do this = "); while (!UART2IsPressed()) {} tchar=UART2GetChar(); if (tchar=='Y') { i=0; Init_EEPROM_Parameters(); UART2PutStr("\r\n OK, all EEPROM data set to default values\r\n\r\n"); } else { UART2PutStr("\r\n No EEPROM data changed, nothing changed\r\n\r\n"); } } else { UART2PutStr("\r\n No EEPROM data changed, nothing changed\r\n\r\n"); } } // end '!' routine for reseting eeprom parameters //GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG // Inputs new Channel Gain Value by David Brown if (tchar=='G') { char Cvalue[10]; int k; for(i=0; i<=4; i++) { sprintf(tstr, "\n\n\rLocation = %d", i); UART2PutStr(tstr); for(j=0; j<=3; j++) { sprintf(tstr, "\n\rGain_Adj[%d][%d] = %f", i, j,(double)Gain_Adj[i][j]); UART2PutStr(tstr); } } sprintf(tstr, "\n\n\rLocation(0->4) = "); UART2PutStr(tstr); tchar = UART2GetChar(); UART2PutChar(tchar); i = tchar - 48; // 48 = ASCII offset sprintf(tstr, "\n\n\rChannel(0->3) = "); UART2PutStr(tstr); tchar = UART2GetChar(); UART2PutChar(tchar); j = tchar - 48; // 48 = ASCII offset sprintf(tstr, "\n\n\rGain_Adj[%d][%d] = %f", i, j,(double)Gain_Adj[i][j]); UART2PutStr(tstr); sprintf(tstr, "\n\n\rEnter New Value = ?"); UART2PutStr(tstr); if((tchar = UART2GetChar()) != 13) { Cvalue[0] = tchar; UART2PutChar(tchar); k = 1; do { tchar = UART2GetChar(); UART2PutChar(tchar); Cvalue[k++] = tchar; } while(tchar != 13); } Gain_Adj[i][j] = atof(Cvalue); sprintf(tstr, "\n\n\rGain[%d][%d] = %f", i, j, (double)Gain_Adj[i][j]); UART2PutStr(tstr); } //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: } // end if char received on serial port } // End ProcessKeys() /***************************************************************************** * EOF *****************************************************************************/