Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 56:6e73fb3d94fa
Simplyfy slope measurement code
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 17 Oct 2012 15:52:36 +0200 |
parents | 54add101fdca |
children | 0e4e0d7b6a22 |
line wrap: on
line diff
--- 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;