# HG changeset patch # User Daniele Nicolodi # Date 1351518393 -3600 # Node ID da82b4815c2fa97a1a0c52698297d3caed076103 # Parent d6efe6fe6eb3d7c3f7287b18e56e1836c302dd4e Fix automatic measurement stop on unlock and simplify dedrifting slope setting diff -r d6efe6fe6eb3 -r da82b4815c2f FXAnalyse.c --- a/FXAnalyse.c Mon Oct 29 14:43:57 2012 +0100 +++ b/FXAnalyse.c Mon Oct 29 14:46:33 2012 +0100 @@ -108,7 +108,7 @@ double TimetoSlope = 60.0; double SlopeMeasuringTimeBegin = 0.0; -double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; +double Slope_Math2slope=0.0,Moy_Math2slope=0.0; int N_Math2slope=0.0; double LimitToDelock=5.0; @@ -126,6 +126,7 @@ SLOPE_REFERENCE_HG_CAVITY = 1, }; +double previousFreq = 0.0; int invertSlopeSign = 0; int slopeReference = SLOPE_REFERENCE_MICROWAVE; @@ -136,10 +137,10 @@ double CenteringTimeBegin10K = 0.0; -int DDSFox_Set(DDSParameter *DDS, double Frequency, double Sweeprate) +int DDSFox_Set(DDSParameter *DDS, double Frequency, double SweepRate) { DDS->Frequency = Frequency; - DDS->SweepRate = Sweeprate; + DDS->SweepRate = SweepRate; DDSFox_SetFreq(DDS); DDSFox_SetDf(DDS); @@ -148,6 +149,14 @@ } +int DDSFox_SetSweepRate(DDSParameter *DDS, double SweepRate) +{ + DDS->SweepRate = SweepRate; + DDSFox_SetDf(DDS); + return 0; +} + + muParserHandle_t initMathParser() { muParserHandle_t parser = mupCreate(); @@ -1225,7 +1234,9 @@ } // stop slope cancelling if the comb is not locked - if (StopSlopeCancellingOnUnlocked & (fabs(currentFreq - Math2_slope) < limitotakoff)) { + if (StopSlopeCancellingOnUnlocked + & (previousFreq != 0.0) + & (fabs(currentFreq - previousFreq) > limitotakoff)) { double frequency = DEDRIFT_DDS_FREQUENCY; if (KeepFrequ) @@ -1244,11 +1255,11 @@ // update slope measurement N_Math2slope = N_Math2slope + 1; - Math2_slope = currentFreq; - Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope; - Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1); + previousFreq = currentFreq; + Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + currentFreq)/N_Math2slope; + Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(currentFreq-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1); // update indicator - SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, 0); + SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, Slope_Math2slope); // update applied slope if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { @@ -1277,12 +1288,10 @@ } } - double frequency = DDSFox_ReadFreq(&DDS1xAD9956); SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, SlopeMath2); - DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); + DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2); N_Math2slope = 0.0; - Math2_slope = 0.0; Moy_Math2slope = 0.0; Slope_Math2slope = 0.0; SlopeMeasuringTimeBegin = utc; @@ -2217,10 +2226,7 @@ SlopeMeasuringTimeBegin = utc; SlopeMeasuring = TRUE; - - frequency = DDSFox_ReadFreq(&DDS1xAD9956); - GetCtrlVal(panel, PANEL_SLOPE_APPLIED, &SlopeMath2); - DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); + previousFreq = 0.0; Nratio = -1; CenterFrequencyCh2ToDetermine = TRUE ; @@ -2240,7 +2246,6 @@ SlopeMeasuring = FALSE; N_Math2slope = 0.0; - Math2_slope = 0.0; Moy_Math2slope = 0.0; Slope_Math2slope = 0.0; MoyMath2 = 0.0; @@ -2452,14 +2457,11 @@ int CVICALLBACK CB_SetSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - double frequency; - switch (event) { case EVENT_COMMIT: GetCtrlVal(panel, control, &SlopeMath2); - frequency = DDSFox_ReadFreq(&DDS1xAD9956); - DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); + DDSFox_SetSweepRate(&DDS1xAD9956, SlopeMath2); break; } return 0;