comparison FXAnalyse.c @ 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 1dfaf5ef0352
comparison
equal deleted inserted replaced
69:94cb4b29bb47 70:a945f2b7bef6
1190 Getsign3 = FALSE; 1190 Getsign3 = FALSE;
1191 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3); 1191 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3);
1192 } 1192 }
1193 } 1193 }
1194 1194
1195 // slope measurement 1195 // select reference
1196 if (SlopeMeasuring == TRUE) 1196 double currentFreq = 0.0;
1197 { 1197 switch (slopeReference) {
1198 double currentFreq = 0.0;
1199
1200 // select reference
1201 switch (slopeReference) {
1202 case SLOPE_REFERENCE_MICROWAVE: 1198 case SLOPE_REFERENCE_MICROWAVE:
1203 currentFreq = Math2; 1199 currentFreq = Math2;
1204 break; 1200 break;
1205 case SLOPE_REFERENCE_HG_CAVITY: 1201 case SLOPE_REFERENCE_HG_CAVITY:
1206 currentFreq = Ch2 * 1062.5 / 1542.2; 1202 currentFreq = Ch2 * 1062.5 / 1542.2;
1207 break; 1203 break;
1204 }
1205
1206 // stop slope cancelling if the comb is not locked
1207 if (SlopeMeasuring & StopSlopeCancellingOnUnlocked
1208 & (previousFreq != 0.0)
1209 & (fabs(currentFreq - previousFreq) > limitotakoff)) {
1210
1211 if (! KeepSlope) {
1212 appliedSlope = 0.0;
1213 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
1214 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
1208 } 1215 }
1209 1216 if (! KeepFrequ) {
1210 // stop slope cancelling if the comb is not locked 1217 DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope);
1211 if (StopSlopeCancellingOnUnlocked
1212 & (previousFreq != 0.0)
1213 & (fabs(currentFreq - previousFreq) > limitotakoff)) {
1214
1215 double frequency = DEDRIFT_DDS_FREQUENCY;
1216 if (KeepFrequ)
1217 frequency = DDSFox_ReadFreq(&DDS1xAD9956);
1218
1219 if (! KeepSlope)
1220 appliedSlope = 0.0;
1221
1222 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
1223 DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope);
1224
1225 measuredSlope = 0.0;
1226 SlopeMeasuring = FALSE;
1227 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0);
1228 } 1218 }
1229 1219 measuredSlope = 0.0;
1220 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope);
1221 SlopeMeasuring = FALSE;
1222 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0);
1223 }
1224
1225 // slope measurement
1226 if (SlopeMeasuring)
1227 {
1230 // update slope measurement 1228 // update slope measurement
1231 Nsamples = Nsamples + 1; 1229 Nsamples = Nsamples + 1;
1232 measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1); 1230 if (Nsamples > 1)
1231 measuredSlope = (measuredSlope * (Nsamples - 2) + 6 * (currentFreq - meanFreq) / Nsamples) / (Nsamples + 1);
1232 else
1233 measuredSlope = 0.0;
1233 meanFreq = ((Nsamples - 1) * meanFreq + currentFreq) / Nsamples; 1234 meanFreq = ((Nsamples - 1) * meanFreq + currentFreq) / Nsamples;
1234 previousFreq = currentFreq; 1235 previousFreq = currentFreq;
1235 // update indicator 1236 // update indicator
1236 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope); 1237 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, measuredSlope);
1237 1238
1263 } 1264 }
1264 1265
1265 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); 1266 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
1266 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); 1267 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
1267 1268
1268 Nsamples = 0.0; 1269 Nsamples = 0;
1269 meanFreq = 0.0; 1270 meanFreq = 0.0;
1270 measuredSlope = 0.0; 1271 measuredSlope = 0.0;
1271 SlopeMeasuringTimeBegin = utc; 1272 SlopeMeasuringTimeBegin = utc;
1272 } 1273 }
1273 } 1274 }
2185 2186
2186 2187
2187 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, 2188 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event,
2188 void *callbackData, int eventData1, int eventData2) 2189 void *callbackData, int eventData1, int eventData2)
2189 { 2190 {
2190 double frequency; 2191 switch (event) {
2191 int active;
2192
2193 switch (event)
2194 {
2195 case EVENT_COMMIT: 2192 case EVENT_COMMIT:
2196 2193
2197 GetCtrlVal(panel, control, &active); 2194 GetCtrlVal(panel, control, &SlopeMeasuring);
2198 2195 if (SlopeMeasuring) {
2199 if (active) {
2200 2196
2201 SlopeMeasuringTimeBegin = utc; 2197 SlopeMeasuringTimeBegin = utc;
2202 SlopeMeasuring = TRUE; 2198
2199 Nsamples = 0;
2203 previousFreq = 0.0; 2200 previousFreq = 0.0;
2201 meanFreq = 0.0;
2202 measuredSlope = 0.0;
2204 2203
2205 Nratio = -1; 2204 Nratio = -1;
2205 MoyMath2 = 0.0;
2206 CenterFrequencyCh2ToDetermine = TRUE ; 2206 CenterFrequencyCh2ToDetermine = TRUE ;
2207 CenterFrequencyCh2 = 0.0; 2207 CenterFrequencyCh2 = 0.0;
2208 2208
2209 } else { 2209 } else {
2210 2210 if (! KeepSlope) {
2211 frequency = DEDRIFT_DDS_FREQUENCY;
2212 if (KeepFrequ)
2213 frequency = DDSFox_ReadFreq(&DDS1xAD9956);
2214
2215 if (! KeepSlope)
2216 appliedSlope = 0.0; 2211 appliedSlope = 0.0;
2217 2212 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
2218 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); 2213 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
2219 DDSFox_Set(&DDS1xAD9956, frequency, appliedSlope); 2214 }
2220 2215 if (! KeepFrequ) {
2221 SlopeMeasuring = FALSE; 2216 DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope);
2222 Nsamples = 0.0; 2217 }
2223 meanFreq = 0.0;
2224 measuredSlope = 0.0; 2218 measuredSlope = 0.0;
2225 MoyMath2 = 0.0; 2219 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, measuredSlope);
2226 CenterFrequencyCh2 = 0.0;
2227 Nratio = -1;
2228 } 2220 }
2229 break; 2221 break;
2230 } 2222 }
2231 return 0; 2223 return 0;
2232 } 2224 }