# HG changeset patch # User Daniele Nicolodi # Date 1350481956 -7200 # Node ID 6e73fb3d94fad730d99ebfa6a06fcff32c99ddd6 # Parent 54add101fdca53307e549180f22cc6c285c52ebe Simplyfy slope measurement code diff -r 54add101fdca -r 6e73fb3d94fa FXAnalyse.c --- a/FXAnalyse.c Thu Oct 11 11:59:32 2012 +0200 +++ b/FXAnalyse.c Wed Oct 17 15:52:36 2012 +0200 @@ -103,7 +103,7 @@ // slope cancelling int SlopeMeasuring = FALSE; -int AutoStopSlopeCancellingIfDelock = TRUE; +int StopSlopeCancellingOnUnlocked = TRUE; double SlopeMath2 = 0.0; // currently applied frequency dedrifiting slope double TimetoSlope = 60.0; double SlopeMeasuringTimeBegin = 0.0; @@ -498,10 +498,8 @@ int BoxChecked = FALSE; - switch (event) - { + switch (event) { case EVENT_TIMER_TICK: - if (! Acquiring) break; @@ -1207,7 +1205,7 @@ } } - // slope cancelling + // slope measurement if (SlopeMeasuring == TRUE) { double currentFreq = 0.0; @@ -1222,90 +1220,71 @@ break; } - if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { + // stop slope cancelling if the comb is not locked + if (StopSlopeCancellingOnUnlocked & (fabs(currentFreq - Math2_slope) < limitotakoff)) { + + double frequency = DEDRIFT_DDS_FREQUENCY; + if (KeepFrequ) + frequency = DDSFox_ReadFreq(&DDS1xAD9956); + + if (! KeepSlope) + SlopeMath2 = 0.0; + + SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); + DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); - Nratio = Nratio + 1; - if (Nratio >= 1) - MoyMath2 = MoyMath2 + Moy_Math2slope; + Slope_Math2slope = 0.0; + SlopeMeasuring = FALSE; + SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); + } + + // update slope measurement + if (nstabilisationSlopeMeasuring < 5) { + nstabilisationSlopeMeasuring += 1; + } else { + 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); + } + + // update applied slope + if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { if (invertSlopeSign) SlopeMath2 = SlopeMath2 - Slope_Math2slope; else SlopeMath2 = SlopeMath2 + Slope_Math2slope; - N_Math2slope = 0.0; - Math2_slope = 0.0; - Moy_Math2slope = 0.0; - Slope_Math2slope = 0.0; - - if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { - CenterFrequencyCh2 = MoyMath2; - CenterFrequencyCh2ToDetermine = FALSE; - } - - if (Nratio == ratio) { - if (FrequCorrec == TRUE) { + if (FrequCorrec) { + // proportional correction + + Nratio += 1; + if (Nratio >= 1) { + MoyMath2 = MoyMath2 + Moy_Math2slope; + } + if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { + CenterFrequencyCh2 = MoyMath2; + CenterFrequencyCh2ToDetermine = FALSE; + } + if (Nratio == ratio) { double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; SlopeMath2 = SlopeMath2 + correction; + Nratio = 0; + MoyMath2 = 0.0; } - Nratio = 0; - MoyMath2 = 0.0; } double frequency = DDSFox_ReadFreq(&DDS1xAD9956); SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); + N_Math2slope = 0.0; + Math2_slope = 0.0; + Moy_Math2slope = 0.0; + Slope_Math2slope = 0.0; nstabilisationSlopeMeasuring = 0; SlopeMeasuringTimeBegin = utc; - - } - else - { - if (nstabilisationSlopeMeasuring < 5) - { - nstabilisationSlopeMeasuring = nstabilisationSlopeMeasuring + 1; - Math2_slope = currentFreq; - } - else - { - if ((currentFreq-Math2_slope) < limitotakoff && (currentFreq-Math2_slope) > -limitotakoff) - { - 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); - } - else - { - if (AutoStopSlopeCancellingIfDelock) { - // stop slope cancelling if the comb is not locked - - double frequency = DEDRIFT_DDS_FREQUENCY; - if (KeepFrequ) - frequency = DDSFox_ReadFreq(&DDS1xAD9956); - - if (! KeepSlope) - SlopeMath2 = 0.0; - - SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); - DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); - - SlopeMeasuring = FALSE; - N_Math2slope = 0.0; - Math2_slope = 0.0; - MoyMath2 = 0.0; - Moy_Math2slope = 0.0; - Slope_Math2slope = 0.0; - CenterFrequencyCh2 = 0.0; - CenterFrequencyCh2ToDetermine = TRUE; - Nratio = -1; - nstabilisationSlopeMeasuring = 0; - - SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); - } - } - } } } @@ -2366,13 +2345,13 @@ } -int CVICALLBACK CB_OnAutoStopSlopeCancellingIfDelock (int panel, int control, int event, +int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: - GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &AutoStopSlopeCancellingIfDelock); + GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &StopSlopeCancellingOnUnlocked); break; } return 0; diff -r 54add101fdca -r 6e73fb3d94fa FXAnalyse.h --- a/FXAnalyse.h Thu Oct 11 11:59:32 2012 +0200 +++ b/FXAnalyse.h Wed Oct 17 15:52:36 2012 +0200 @@ -165,7 +165,7 @@ #define PANEL_FIND10K3 111 /* control type: command, callback function: CB_OnFind275K */ #define PANEL_FIND275K2 112 /* control type: command, callback function: CB_OnFind275K */ #define PANEL_RESETSLOPE 113 /* control type: command, callback function: CB_OnResetSlope */ -#define PANEL_CHECKBOX_STOPIFAUTODE 114 /* control type: radioButton, callback function: CB_OnAutoStopSlopeCancellingIfDelock */ +#define PANEL_CHECKBOX_STOPIFAUTODE 114 /* control type: radioButton, callback function: CB_OnStopSlopeCancellingOnUnlocked */ #define PANEL_CHECKBOX_RECENTER 115 /* control type: radioButton, callback function: CB_OnReCentering */ #define PANEL_CHECKBOX_KEEPSLOPE 116 /* control type: radioButton, callback function: CB_OnCROX */ #define PANEL_CHECKBOX_KEEP 117 /* control type: radioButton, callback function: CB_OnCROX */ @@ -193,7 +193,6 @@ int CVICALLBACK CB_OnAllanPlot(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnAutoSaveHg(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnAutoSaveSr(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); -int CVICALLBACK CB_OnAutoStopSlopeCancellingIfDelock(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnChangeNdiv(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnCROX(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnDeltaFreq(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); @@ -220,6 +219,7 @@ int CVICALLBACK CB_OnStart(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStartNCalculus(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnStop(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); +int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_OnTimer(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK CB_SetSlope(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); int CVICALLBACK OnChooseSaveFile(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); diff -r 54add101fdca -r 6e73fb3d94fa FXAnalyse.uir Binary file FXAnalyse.uir has changed