Mercurial > hg > fxanalyse
changeset 70:a945f2b7bef6
Fix slope measurement again
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 29 Oct 2012 14:48:44 +0100 |
parents | 94cb4b29bb47 |
children | 07caeaeb5b88 |
files | FXAnalyse.c FXAnalyse.uir |
diffstat | 2 files changed, 45 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/FXAnalyse.c Mon Oct 29 14:48:24 2012 +0100 +++ b/FXAnalyse.c Mon Oct 29 14:48:44 2012 +0100 @@ -1192,44 +1192,45 @@ } } - // slope measurement - if (SlopeMeasuring == TRUE) - { - double currentFreq = 0.0; - - // select reference - switch (slopeReference) { + // select reference + double currentFreq = 0.0; + switch (slopeReference) { case SLOPE_REFERENCE_MICROWAVE: currentFreq = Math2; break; case SLOPE_REFERENCE_HG_CAVITY: currentFreq = Ch2 * 1062.5 / 1542.2; break; - } - - // stop slope cancelling if the comb is not locked - if (StopSlopeCancellingOnUnlocked - & (previousFreq != 0.0) - & (fabs(currentFreq - previousFreq) > limitotakoff)) { - - double frequency = DEDRIFT_DDS_FREQUENCY; - if (KeepFrequ) - frequency = DDSFox_ReadFreq(&DDS1xAD9956); + } + + // stop slope cancelling if the comb is not locked + if (SlopeMeasuring & StopSlopeCancellingOnUnlocked + & (previousFreq != 0.0) + & (fabs(currentFreq - previousFreq) > limitotakoff)) { - if (! KeepSlope) - appliedSlope = 0.0; - + if (! KeepSlope) { + appliedSlope = 0.0; + DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); - DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope); - - measuredSlope = 0.0; - SlopeMeasuring = FALSE; - SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); + } + if (! KeepFrequ) { + DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope); } - + measuredSlope = 0.0; + SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope); + SlopeMeasuring = FALSE; + SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); + } + + // slope measurement + if (SlopeMeasuring) + { // update slope measurement Nsamples = Nsamples + 1; - measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1); + if (Nsamples > 1) + measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1); + else + measuredSlope = 0.0; meanFreq = ((Nsamples - 1) * meanFreq + currentFreq) / Nsamples; previousFreq = currentFreq; // update indicator @@ -1265,7 +1266,7 @@ SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); - Nsamples = 0.0; + Nsamples = 0; meanFreq = 0.0; measuredSlope = 0.0; SlopeMeasuringTimeBegin = utc; @@ -2187,44 +2188,35 @@ int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - double frequency; - int active; - - switch (event) - { + switch (event) { case EVENT_COMMIT: - GetCtrlVal(panel, control, &active); - - if (active) { + GetCtrlVal(panel, control, &SlopeMeasuring); + if (SlopeMeasuring) { SlopeMeasuringTimeBegin = utc; - SlopeMeasuring = TRUE; + + Nsamples = 0; previousFreq = 0.0; + meanFreq = 0.0; + measuredSlope = 0.0; Nratio = -1; + MoyMath2 = 0.0; CenterFrequencyCh2ToDetermine = TRUE ; CenterFrequencyCh2 = 0.0; } else { - - frequency = DEDRIFT_DDS_FREQUENCY; - if (KeepFrequ) - frequency = DDSFox_ReadFreq(&DDS1xAD9956); - - if (! KeepSlope) + if (! KeepSlope) { appliedSlope = 0.0; - - SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); - DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope); - - SlopeMeasuring = FALSE; - Nsamples = 0.0; - meanFreq = 0.0; + DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); + SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); + } + if (! KeepFrequ) { + DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope); + } measuredSlope = 0.0; - MoyMath2 = 0.0; - CenterFrequencyCh2 = 0.0; - Nratio = -1; + SetCtrlVal(panel, PANEL_SLOPE_MEASURED, measuredSlope); } break; }