/***************************************************************************** * * Toroid Beam Charge Monitor * ***************************************************************************** * FileName: Callibration.c * Dependencies: system.h * Processor: PIC24 * Compiler: MPLAB C30 * Linker: MPLAB LINK30 * * Software for the embedded PIC24H processor in the BCM for LCLS * Stanford Linear Accelerator Center * LCLS Controls * * * * Author Date Comment *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * Michael Cecere 08/28/2006 * * * *****************************************************************************/ #include "system.h" #define Corr_Array_Size 150 #define AMP_THRESHOLD 3000 // discriminates correlation plot in Init_Delay() int Cal_Charge_Delay = 210; // amount of time to wait after setting Charge MUX extern SYS_Config_Struct SYS_Config; extern int PRINTON; extern int EXT_TRIG; unsigned int CAL_Corr[Corr_Array_Size][4]; // holds the correlation plot over pulse delay unsigned long CAL_Corr_peak[4][2]; // remembers the peak value and it's delay time // [Chan][0] = location of peak signal // [Chan][1] = Value of peak delay unsigned long CAL_Corr_min[4][2]; unsigned long CAL_Corr_Avg[4]; unsigned long CAL_Corr_Amp_Delay[4][2]; // [chan][0=Amp]or[1=delay] unsigned int testarray[Corr_Array_Size]; //unsigned int testarray1[Corr_Array_Size]; unsigned long Cal_Raw_1000pC[8]; // holds raw data as read from ADC during cal sequence unsigned long Cal_Raw_200pC[8]; // holds raw data as read from ADC during cal sequence unsigned long Cal_Raw_0pC[8]; // holds raw data as read from ADC during cal sequence unsigned long Data_Raw[8]; // holds raw acquired data float pC_Adj[8]; // holds adjusted acquired data float LINmAvg[8]; float LINoffAvg[8]; float Gain_Adj[8][8]; int RingBufIndex; int prt2 = 1; unsigned int GND = 0; char Trig_Mask; // holds which trig channels are enabled /***************************************************************************** * Function: Acq_Init * * Preconditions: CPLD_Init has been called * * Overview: Sets delays for each analog channel * * Input: none * * Output: none * ******************************************************************************/ void Acq_Init() { int Chan,i; //unsigned uitemp[16]; char tstr[100]; //float Chan_Gain, Baseline; Trigger_Enable(Trig_None); // Inhibit all External Trigger Inputs to CPLD RingBufIndex=0; for (Chan=0;Chan<4;Chan++) { CPLD_LE = 0; // CPLD Latch data latch bit CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_CAL); // set Calibration delay CPLD_Set_Data(118); Latch_CPLD(); i=0; CPLD_Set_Mode(CPLD_INT1); // set Integration #1 delay CPLD_Set_Data(SYS_Config.INT1_Width[Chan]); Latch_CPLD(); i=0; CPLD_Set_Mode(CPLD_INT2); // set Integration #2 delay CPLD_Set_Data(SYS_Config.INT2_Width[Chan]); Latch_CPLD(); i=0; CPLD_Set_Mode(CPLD_RESET); // set Reset delay CPLD_Set_Data(SYS_Config.Reset_Delay[Chan]); Latch_CPLD(); i=0; } // end loop on chan number // clear CPLD ACK just in case CPLD_Clr_All(); sprintf(tstr,"\r\nCPLD_Clr_All();\n"); UART2PutStr(tstr); // Find CAL_DELAY for each channel activated // need some sort of "error" checking here. // then figuring out how to indicate an error is a challenge // maybe the LEDs on the front panel //Init_Delays(); // Commented out DGB 4-13-09 //sprintf(tstr,"\r\nInit_Delays();\n"); // Commented out DGB 4-13-09 //UART2PutStr(tstr); // Commented out DGB 4-13-09 i=0; Set_ACQ_Mode(ACQ_MODE_1000pC, 0); // no preset NumNops(Cal_Charge_Delay); CPLD_Trig_All(); i=0; while (!CAL_DONE && !CHAN_RDY_ALL) {} i=0; Get_Data_ADC(); i=0; CPLD_Clr_All(); i=0; /* // this applies the hardcoded calibration values. for (Chan=0;Chan<8;Chan++) { LINmAvg[Chan] = SYS_Config.Chan_Gain[Chan]; LINoffAvg[Chan] = SYS_Config.Chan_Offset[Chan]; } */ // calibrate each active channel // needs to be run at least 10 times to fill up the ring for (i=0;i<20;i++) { Set_ACQ_Mode(ACQ_MODE_1000pC, 0); // no preset NumNops(Cal_Charge_Delay); CPLD_Trig_All(); while (!CAL_DONE && !CHAN_RDY_ALL) {} Get_Cal_ADC(); CPLD_Clr_All(); } i=0; i=0; CPLD_Clr_All(); // enable Cal_Trig and normal Acq triggers Trig_Mask = 1; i=0; //if (PRINTON) { if (0) { UART2PutStr("\r\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n"); UART2PutStr("\r\n Signal Calibration Finished\r\n"); for (Chan=0;Chan<8;Chan++) { UART2PutStr("\r\nChan #"); UART2PutDec(Chan); UART2PutStr(" Offset = "); ftoa(LINoffAvg[Chan], tstr, 2, 'f'); UART2PutStr(tstr); UART2PutStr(" in pC, Slope = "); ftoa(LINmAvg[Chan], tstr, 6, 'f'); UART2PutStr(tstr); UART2PutStr(" in pC/ADC Count"); } UART2PutStr("\r\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\r\n"); } // end if PRINTON } /***************************************************************************** * Function: Set_ACQ_Mode * * Preconditions: everything has been initialized correctly. * * Overview: Sets the charging potential on all enabled channels * * Input: ACQ_MODE_NORM = Normal, No calibration pulse generated * ACQ_MODE_0pC = no charge, but calibration circuit fires as normal * ACQ_MODE_200pC = 200pC charge setting. charges 100pF cap to 2Volts * ACQ_MODE_1000pC = 1000pC charge setting. charges 100pF cap to 10Volts * Preset = 1, Cal Charge Level is set, but need ext cal trigger to activate * meaningless for ACQ_MODE_NORM setting * * Chan # must be 0 * ******************************************************************************/ void Set_ACQ_Mode(char Mode, char Preset) { int i; CPLD_LE = 0; // CPLD Latch data latch bit if ((Mode<0)|(Mode>3)) Mode = 0; // default to Normal Acquisition mode if (!Preset) Mode = Mode | ACQ_MODE_PRESET; // Turn on Preset Bit CPLD_Set_Chan(0); // must be set to chan 0, but effects all channels i=0; CPLD_Set_Mode(CPLD_ACQ); // CPLD_ACQ works across all channels i=0; CPLD_Set_Data(Mode); // i=0; Latch_CPLD(); // latch it in to the CPLD i=0; } /***************************************************************************** * Function: Init_Delays * * Overview: determines loop delay time and sets cal delays appropriately * * this routine scans each channel through the complete range of delay possible. * at 8.4nS per CPLD click and 8 bit range gives 2.142uS range, or 1.07uS one-way trip. * At 4nS/m, the speed of the LMR-400, that's a max run of 272m or 900feet... * * When Cal_Delay = 0, the INT windows should start on the very next clock after the * trigger is received. (for bench testing) * * Input: Chan_ON[Chan] * * Output: Cal_Delay, INT1_Width, INT2_Width, Reset_Delay * ******************************************************************************/ int Init_Delays() { //char tstr[100]; int i,j, k, Chan, Delay, over_threshold; //unsigned int uint; int INT1_CAL_temp = 8; // temporary length of windows for delay timing int INT2_CAL_temp = 17; // changing this will affect the Amplitude reached also int RESET_CAL_temp = 1; int Delay_End, Delay_Start, Peak_Start; //unsigned long lpeak,lmin, ulong; int DAC_Counts; Trigger_Enable(Trig_None); // Inhibit all External Trigger Inputs to CPLD CPLD_Clr_All(); // zero correlation array for (i=0;iPeak_Start) { if (CAL_Corr[Delay][Chan] > CAL_Corr_peak[Chan][1]) { CAL_Corr_peak[Chan][1] = CAL_Corr[Delay][Chan]; CAL_Corr_peak[Chan][0] = Delay; } if (CAL_Corr[Delay][Chan] < CAL_Corr_min[Chan][1]) { CAL_Corr_min[Chan][1] = CAL_Corr[Delay][Chan]; CAL_Corr_min[Chan][0] = Delay; } } } // end Chan i =0; i=0; //////////////////////////////////////////////////////////////////////// } // end delay scan i=0; i=0; for (Chan=0;Chan<4;Chan++) { // calculate overall average for peak discrimination CAL_Corr_Avg[Chan]=0; for (Delay=0;Delay(CAL_Corr_Avg[Chan]+AMP_THRESHOLD)) { CAL_Corr_Amp_Delay[Chan][0]=CAL_Corr_peak[Chan][1] - CAL_Corr_Avg[Chan]; // positive pulses result from negative calibration pulses into a toroid SYS_Config.Chan_Polarity[Chan] = 1; CAL_Corr_Amp_Delay[Chan][1] = CAL_Corr_peak[Chan][0]; over_threshold = 1; // is over threshold } if (CAL_Corr_Avg[Chan]>(CAL_Corr_min[Chan][1]+AMP_THRESHOLD)) { CAL_Corr_Amp_Delay[Chan][0]=CAL_Corr_Avg[Chan] - CAL_Corr_min[Chan][1]; // negative pulses often are a result of connecting the cal port to the signal port // directly through 22dB attenuators, no toroid to invert signal. SYS_Config.Chan_Polarity[Chan] = 0; CAL_Corr_Amp_Delay[Chan][1] = CAL_Corr_min[Chan][0]; over_threshold = 1; // is over threshold } //??????????????????????????????????????????????????????????????????????????????????? // if there's not enough signal shut off the channels and throw an error? if ((!over_threshold) & (!SYS_Config.Chan_Faradaycup[Chan])) { SYS_Config.Chan_ON[Chan] = 0; } } // end chan scan // flash lights to indicate which channels are enabled for (Chan=0;Chan<4;Chan++) { LED1=0;LED2=0;LED3=0; Delay_mS(500); LED1=1; if (SYS_Config.Chan_ON[Chan]) LED2=1; Delay_mS(500); } // now set all the delays appropriately for (Chan=0;Chan<4;Chan++) { CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_CAL); // set the calibration delay Delay = CAL_Corr_Amp_Delay[Chan][1] + SYS_Config.Cal_Pre_Trig[Chan]; Delay = Delay + SYS_Config.INT1_Width[Chan]; // force delay if faraday channel if (SYS_Config.Chan_Faradaycup[Chan]) Delay = 71; if (Delay<=0) Delay = 50; CPLD_Set_Data(Delay); SYS_Config.Cal_Delay[Chan] = Delay; // remember value Latch_CPLD(); } // end chan loop ///////////////////////////////////////////////////////////////////////////////// // force all channels enabled //for (Chan=0;Chan<4;Chan++) SYS_Config.Chan_ON[Chan]=1; if (1) { UART2PutStr("\r\n*****************************************************\r\n"); for (Chan=0;Chan<4;Chan++) { UART2PutStr("\r\nCal Delay Chan #"); UART2PutDec(Chan); UART2PutStr(" = "); UART2PutDec(SYS_Config.Cal_Delay[Chan]); UART2PutStr(" Clock cycles, Chan is "); SYS_Config.Chan_ON[Chan] = 1; //DB Hard coding all channels to be ENABLED! if (SYS_Config.Chan_ON[Chan] == 1) { UART2PutStr("Enabled, ");} else { UART2PutStr("DISABLED, "); } if (SYS_Config.Chan_Polarity[Chan] == 1) { UART2PutStr("Polarity is 1"); } else { UART2PutStr("Polarity is 0"); } if (SYS_Config.Chan_Faradaycup[Chan] == 1) UART2PutStr(", is FARADAY CUP "); UART2PutStr(", Amp= "); UART2PutDec(CAL_Corr_Amp_Delay[Chan][0]); } // end chan scan UART2PutStr("\r\n*****************************************************\r\n"); UART2PutStr("\r\n Delay Calibration Finished\r\n"); i=0; UART2PutChar(13);UART2PutChar(10); } // end if PRINTON // RESET all channel parameters the same // except for the cal delay // and drive DAC outputs appropriately for (Chan=0;Chan<4;Chan++) { CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_INT1); CPLD_Set_Data(SYS_Config.INT1_Width[Chan]); Latch_CPLD(); // latch data into CPLD CPLD_Set_Mode(CPLD_INT2); CPLD_Set_Data(SYS_Config.INT2_Width[Chan]); Latch_CPLD(); CPLD_Set_Mode(CPLD_RESET); CPLD_Set_Data(SYS_Config.Reset_Delay[Chan]); Latch_CPLD(); // set to 0pC, or 0.200volts as sign channel enabled if (SYS_Config.Chan_ON[Chan]) { DAC_Counts = Toroid_DAC_Scale(0, Chan); DAC_Write(DAC_Counts, Chan); } else { DAC_Write(0, Chan); } } return 0; } // end Init_Delays /***************************************************************************** * Function: Clin(reading, Chan) * * Overview: returns linear fit to data, uses 0pC and 1000pC only * * Input: ADC reading and Chan * * Output: linearly adjusted value * ******************************************************************************/ float Clin(unsigned long counts, unsigned Chan) { //int i; float ftemp, fGND; char tstr[100] = " "; fGND = (float)(SYS_Config.Chan_Gain[Chan] * GND); ftemp = (float)(SYS_Config.Chan_Gain[Chan] * (counts - SYS_Config.Chan_Offset[Chan])); ftemp = ftemp - fGND; // if (SYS_Config.Chan_Polarity[Chan/2]==0) ftemp=-1.*ftemp; // 0 = Faraday Cup // 1 = Faraday Cup if (SYS_Config.Chan_Faradaycup[Chan/2] == 45) ftemp = ftemp * (-0.866802); if (SYS_Config.Chan_Faradaycup[Chan/2] == 67) ftemp = ftemp * (-0.931388); if(prt2) { sprintf(tstr,"\r\nSYS_Config.Chan_Gain[%d] = %9.6f\r\n",Chan, (double)SYS_Config.Chan_Gain[Chan]); UART2PutStr(tstr); sprintf(tstr,"SYS_Config.Chan_Offset[%d] = %4.1f\r\n\n",Chan, (double)SYS_Config.Chan_Offset[Chan]); UART2PutStr(tstr); } return (ftemp); } //**************************************************************************** /***************************************************************************** * Function: Get_Cal_ADC() * * Overview: Performs calibration on each enabled channel * * Input: none * * Output: adjusts Gain and Offset value based on calibration pulses * * Conditions: * ******************************************************************************/ void Get_Cal_ADC() { int Chan, i, j; //unsigned long ulong; float Cal_pC[8]; char tstr[100]=" "; // assumes cal pulse already set to appear in INT2 // get 1nC charge acquisition already acquired from INT2 Get_Data_ADC(); CPLD_Clr_All(); for (Chan=1;Chan<8;Chan=Chan+2) Cal_Raw_1000pC[Chan] = Data_Raw[Chan]; i=0; // set cal pulse to appear in INT1 period for (Chan=0;Chan<4;Chan++) { CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_CAL); CPLD_Set_Data(SYS_Config.Cal_Delay[Chan]-SYS_Config.INT1_Width[Chan]); Latch_CPLD(); } // set for 1000pC calibration signal, no prefetch Set_ACQ_Mode(ACQ_MODE_1000pC, 0); NumNops(Cal_Charge_Delay); i=0; // trigger for 1000pC INT1 CPLD_Trig_All(); while (!CAL_DONE && !CHAN_RDY_ALL) {} // get 1000pC charge acquisition acquired from INT1 Get_Data_ADC(); CPLD_Clr_All(); for (Chan=0;Chan<8;Chan=Chan+2) Cal_Raw_1000pC[Chan] = Data_Raw[Chan]; // 00000000000000000000000000000000000000000000000000000000000000000000000 // now do 0pC charge calibration in INT1 Set_ACQ_Mode(ACQ_MODE_0pC, 0); // set for 0pC calibration signal NumNops(Cal_Charge_Delay); i=0; // trigger for 0pC in INT1 CPLD_Trig_All(); // wait for 0pC charge acquisition to finish while (!CAL_DONE && !CHAN_RDY_ALL) {} Get_Data_ADC(); CPLD_Clr_All(); for (Chan=0;Chan<8;Chan=Chan+2) Cal_Raw_0pC[Chan] = Data_Raw[Chan]; // set cal pulse to appear back in INT2 for (Chan=0;Chan<4;Chan++) { CPLD_Set_Chan(Chan); CPLD_Set_Mode(CPLD_CAL); CPLD_Set_Data(SYS_Config.Cal_Delay[Chan]); Latch_CPLD(); } i=0; // trigger for 0pC in INT2 CPLD_Trig_All(); while (!CAL_DONE && !CHAN_RDY_ALL) {} Get_Data_ADC(); CPLD_Clr_All(); for (Chan=1;Chan<8;Chan=Chan+2) Cal_Raw_0pC[Chan] = Data_Raw[Chan]; i=0; // linear fit between 0pC and 1000pC for INT2 // spli up by int windows so can treat them differently, like scale INT1 from 0 - 200pC // // really need a true running average here but i'm not sure how much time that would // save with a ring only 10 values long // // this routine will give bad values until the ring buffer is filled // so Acq_Init() must run this routine at least more then 10 times // Linear fit between 0pC and 1000pC for INT2 for (Chan=0;Chan<8;Chan++) { j=(int) (Chan/2.); if (SYS_Config.Chan_Polarity[j]==1) { // inverting channel, like real toroid // Calibrated_xxxpC is measured output in pC // Cal_Raw_xxxpC = ADC Counts of signal // LINm = Gain in pC/Count SYS_Config.LINm[Chan][RingBufIndex] = (float)((SYS_Config.Calibrated_1000pC[j] - SYS_Config.Calibrated_0pC[j]) / (Cal_Raw_1000pC[Chan]-Cal_Raw_0pC[Chan])); SYS_Config.LINoff[Chan][RingBufIndex] = (float)(SYS_Config.Calibrated_0pC[j]); // - SYS_Config.LINm[Chan][RingBufIndex] * Cal_Raw_0pC[Chan]); } else { // non-inverting channel, like only using attenutators SYS_Config.LINm[Chan][RingBufIndex] = (float)((SYS_Config.Calibrated_1000pC[j] - SYS_Config.Calibrated_0pC[j]) / (Cal_Raw_0pC[Chan]-Cal_Raw_1000pC[Chan])); SYS_Config.LINoff[Chan][RingBufIndex] = (float)(SYS_Config.Calibrated_0pC[j]); // - SYS_Config.LINm[Chan][RingBufIndex] * Cal_Raw_0pC[Chan]); } // zero the average position LINmAvg[Chan] = 0; LINoffAvg[Chan] = 0; } // average into LINxAvg which is used by the Clin conversion routine for (Chan=0;Chan<8;Chan++) { for (i=0;i(RINGBUFSIZE-1)) RingBufIndex=0; if (PRINTON) { for (Chan=0;Chan<8;Chan++) { Cal_pC[Chan] = Clin((unsigned long)(Cal_Raw_1000pC[Chan]-Cal_Raw_0pC[Chan]),Chan); ftoa(Cal_pC[Chan], tstr, 3, 'f'); UART2PutStr(tstr);UART2PutStr(" "); } UART2PutStr("\r\n\r\n"); for (Chan=0;Chan<8;Chan++) { ftoa(LINmAvg[Chan], tstr, 4, 'f'); UART2PutStr(tstr);UART2PutStr("/"); ftoa(LINoffAvg[Chan], tstr, 4, 'f'); UART2PutStr(tstr);UART2PutStr(" "); } UART2PutStr("\r\n\n"); } i=0; i=0; } /***************************************************************************** * Function: Get_Data_ADC() * * Overview: Normal Data Acquisition Routine * * Input: none * * Output: fills Data_Raw[] with the averaged ADC reads for each channel * ******************************************************************************/ void Get_Data_ADC() { int Chan, i; unsigned long ultemp, ADC_counts; //char tstr[80]=" "; Read_Ground(0); for (Chan=0;Chan<8;Chan++) { MUX_Chan(Chan); ultemp = 0; for (i=0;i 0) ultemp = ultemp + ADC_counts; } Data_Raw[Chan] = ultemp / (SYS_Config.NumDataAvg - 1); // "-1" because we average seven instead of 8. } // end chan scan MUX_Chan(Ground); } // end Get_Data_ADC /***************************************************************************** * Function: Scale_Data_pC() * * Overview: scales raw ADC data into pC * * Input: Data_Raw[] * * Output: fills pC_Adj with data calibrated in nC, * ******************************************************************************/ void Scale_Data_pC() { int Chan; float INT1, INT2; for (Chan=0;Chan<4;Chan++) { INT1 = Clin((unsigned long)(Data_Raw[Chan*2]),Chan*2); prt2 = 0; INT2 = Clin((unsigned long)(Data_Raw[Chan*2+1]),Chan*2+1); pC_Adj[Chan] = (INT2 - 2 * INT1) * Gain_Adj[SYS_Config.Location_ID][Chan]; } } /***************************************************************************** * Function: Trigger_Enable(char data) * * Overview: enables/disables External triggers * * Input: triggers enabled with a '1' in the appropriate bit position * Trig_Chan0 = Bit[0] = enable all normal acquisition triggers for all 4 channels * Trig_Chan1 = Bit[1] = reserved * Trig_Chan2 = Bit[2] = reserved * Trig_Chan3 = Bit[3] = reserved * Trig_Cal = Bit[4] = enables calibration trigger input * Trig_All = 0x11, turns on all enables * Trig_None = 0x00, turns off all enables * * Output: none * ******************************************************************************/ void Trigger_Enable(char data) { CPLD_Set_Chan(0); // CPLD_Set_Mode(CPLD_TRIG); // set External Trig Enable Status CPLD_Set_Data(data); if (data==0) EXT_TRIG = 0; else EXT_TRIG = 1; Latch_CPLD(); } /***************************************************************************** * Function: Read_Ground() * * Overview: Set MUX to read ground pin voltage. * * Input: none * * Output: Averaged Ground Readings * * Author: David G. Brown * * Date: June 5, 2008 * ******************************************************************************/ void Read_Ground(int PON) { int i; char tstr[100] = " "; unsigned long ADC_data, temp_GND; MUX_Chan(Ground); // Write MUX address temp_GND = 0; for(i=0; i<=7; i++) { ADC_data = ADC_Chan(); if(i > 0) temp_GND = temp_GND + ADC_data; } GND = temp_GND / 7; if(PON) { sprintf(tstr,"\r\nAverage GND = %d", (unsigned) GND); UART2PutStr(tstr); UART2PutStr("\r\n"); } // set MUX back to first channel MUX_Chan(Ground); return; } // end Read_Ground /***************************************************************************** * Function: Calibrate() * * Overview: Does Calibration. * * Input: none * * Output: * * Author: David G. Brown * * Date: June 9, 2008 * ******************************************************************************/ void Calibrate(int Cal_PON) { int Chan; char tstr[80] = " "; // 00000000000000000000000000000000000000000000000000000000000000000000000 // 0pC charge calibration Set_ACQ_Mode(ACQ_MODE_0pC, 0); // set for 0pC calibration signal NumNops(Cal_Charge_Delay); CPLD_Clr_All(); // trigger for 0pC CPLD_Trig_All(); if(Cal_PON == 1) { sprintf(tstr,"\r\nWaiting for CAL_DONE"); UART2PutStr(tstr); } // wait for 0pC charge acquisition to finish while (!CAL_DONE && !CHAN_RDY_ALL) { if (CHAN_RDY_ALL) break; } Read_Ground(0); Get_Data_ADC(); CPLD_Clr_All(); for (Chan=0; Chan<=7; Chan++) { SYS_Config.Chan_Offset[Chan] = Data_Raw[Chan]; SYS_Config.Chan_Offset[Chan] = SYS_Config.Chan_Offset[Chan] - GND; if(Cal_PON == 1) { sprintf(tstr,"\r\nSYS_Config.Chan_Offset[%d] = %6.0f", Chan, (double) SYS_Config.Chan_Offset[Chan]); UART2PutStr(tstr); } } if(Cal_PON == 1) UART2PutStr("\r\n\n"); } // End Calibrate Function.