Mercurial > hg > fxanalyse
comparison 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 |
comparison
equal
deleted
inserted
replaced
55:54add101fdca | 56:6e73fb3d94fa |
---|---|
101 double Signe1=1.0,Signe2=1.0,Signe3=0.0; | 101 double Signe1=1.0,Signe2=1.0,Signe3=0.0; |
102 | 102 |
103 // slope cancelling | 103 // slope cancelling |
104 | 104 |
105 int SlopeMeasuring = FALSE; | 105 int SlopeMeasuring = FALSE; |
106 int AutoStopSlopeCancellingIfDelock = TRUE; | 106 int StopSlopeCancellingOnUnlocked = TRUE; |
107 double SlopeMath2 = 0.0; // currently applied frequency dedrifiting slope | 107 double SlopeMath2 = 0.0; // currently applied frequency dedrifiting slope |
108 double TimetoSlope = 60.0; | 108 double TimetoSlope = 60.0; |
109 double SlopeMeasuringTimeBegin = 0.0; | 109 double SlopeMeasuringTimeBegin = 0.0; |
110 | 110 |
111 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; | 111 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; |
496 time_t utcTime; | 496 time_t utcTime; |
497 char * ReportString = "dd.mm.yy\t00:00:00\t3481610838.000\t0000000000000.00000000"; | 497 char * ReportString = "dd.mm.yy\t00:00:00\t3481610838.000\t0000000000000.00000000"; |
498 | 498 |
499 int BoxChecked = FALSE; | 499 int BoxChecked = FALSE; |
500 | 500 |
501 switch (event) | 501 switch (event) { |
502 { | |
503 case EVENT_TIMER_TICK: | 502 case EVENT_TIMER_TICK: |
504 | |
505 if (! Acquiring) | 503 if (! Acquiring) |
506 break; | 504 break; |
507 | 505 |
508 GetFileInfo(LogFileName, &LogFileSize); | 506 GetFileInfo(LogFileName, &LogFileSize); |
509 | 507 |
1205 Getsign3 = FALSE; | 1203 Getsign3 = FALSE; |
1206 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3); | 1204 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3); |
1207 } | 1205 } |
1208 } | 1206 } |
1209 | 1207 |
1210 // slope cancelling | 1208 // slope measurement |
1211 if (SlopeMeasuring == TRUE) | 1209 if (SlopeMeasuring == TRUE) |
1212 { | 1210 { |
1213 double currentFreq = 0.0; | 1211 double currentFreq = 0.0; |
1214 | 1212 |
1215 // select reference | 1213 // select reference |
1220 case SLOPE_REFERENCE_HG_CAVITY: | 1218 case SLOPE_REFERENCE_HG_CAVITY: |
1221 currentFreq = Ch2 * 1542.2 / 1062.5; | 1219 currentFreq = Ch2 * 1542.2 / 1062.5; |
1222 break; | 1220 break; |
1223 } | 1221 } |
1224 | 1222 |
1223 // stop slope cancelling if the comb is not locked | |
1224 if (StopSlopeCancellingOnUnlocked & (fabs(currentFreq - Math2_slope) < limitotakoff)) { | |
1225 | |
1226 double frequency = DEDRIFT_DDS_FREQUENCY; | |
1227 if (KeepFrequ) | |
1228 frequency = DDSFox_ReadFreq(&DDS1xAD9956); | |
1229 | |
1230 if (! KeepSlope) | |
1231 SlopeMath2 = 0.0; | |
1232 | |
1233 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); | |
1234 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | |
1235 | |
1236 Slope_Math2slope = 0.0; | |
1237 SlopeMeasuring = FALSE; | |
1238 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); | |
1239 } | |
1240 | |
1241 // update slope measurement | |
1242 if (nstabilisationSlopeMeasuring < 5) { | |
1243 nstabilisationSlopeMeasuring += 1; | |
1244 } else { | |
1245 N_Math2slope = N_Math2slope + 1; | |
1246 Math2_slope = currentFreq; | |
1247 Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope; | |
1248 Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1); | |
1249 } | |
1250 | |
1251 // update applied slope | |
1225 if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { | 1252 if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { |
1226 | |
1227 Nratio = Nratio + 1; | |
1228 if (Nratio >= 1) | |
1229 MoyMath2 = MoyMath2 + Moy_Math2slope; | |
1230 | 1253 |
1231 if (invertSlopeSign) | 1254 if (invertSlopeSign) |
1232 SlopeMath2 = SlopeMath2 - Slope_Math2slope; | 1255 SlopeMath2 = SlopeMath2 - Slope_Math2slope; |
1233 else | 1256 else |
1234 SlopeMath2 = SlopeMath2 + Slope_Math2slope; | 1257 SlopeMath2 = SlopeMath2 + Slope_Math2slope; |
1235 | 1258 |
1259 if (FrequCorrec) { | |
1260 // proportional correction | |
1261 | |
1262 Nratio += 1; | |
1263 if (Nratio >= 1) { | |
1264 MoyMath2 = MoyMath2 + Moy_Math2slope; | |
1265 } | |
1266 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { | |
1267 CenterFrequencyCh2 = MoyMath2; | |
1268 CenterFrequencyCh2ToDetermine = FALSE; | |
1269 } | |
1270 if (Nratio == ratio) { | |
1271 double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; | |
1272 SlopeMath2 = SlopeMath2 + correction; | |
1273 Nratio = 0; | |
1274 MoyMath2 = 0.0; | |
1275 } | |
1276 } | |
1277 | |
1278 double frequency = DDSFox_ReadFreq(&DDS1xAD9956); | |
1279 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); | |
1280 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | |
1281 | |
1236 N_Math2slope = 0.0; | 1282 N_Math2slope = 0.0; |
1237 Math2_slope = 0.0; | 1283 Math2_slope = 0.0; |
1238 Moy_Math2slope = 0.0; | 1284 Moy_Math2slope = 0.0; |
1239 Slope_Math2slope = 0.0; | 1285 Slope_Math2slope = 0.0; |
1240 | |
1241 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { | |
1242 CenterFrequencyCh2 = MoyMath2; | |
1243 CenterFrequencyCh2ToDetermine = FALSE; | |
1244 } | |
1245 | |
1246 if (Nratio == ratio) { | |
1247 if (FrequCorrec == TRUE) { | |
1248 double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; | |
1249 SlopeMath2 = SlopeMath2 + correction; | |
1250 } | |
1251 Nratio = 0; | |
1252 MoyMath2 = 0.0; | |
1253 } | |
1254 | |
1255 double frequency = DDSFox_ReadFreq(&DDS1xAD9956); | |
1256 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); | |
1257 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | |
1258 | |
1259 nstabilisationSlopeMeasuring = 0; | 1286 nstabilisationSlopeMeasuring = 0; |
1260 SlopeMeasuringTimeBegin = utc; | 1287 SlopeMeasuringTimeBegin = utc; |
1261 | |
1262 } | |
1263 else | |
1264 { | |
1265 if (nstabilisationSlopeMeasuring < 5) | |
1266 { | |
1267 nstabilisationSlopeMeasuring = nstabilisationSlopeMeasuring + 1; | |
1268 Math2_slope = currentFreq; | |
1269 } | |
1270 else | |
1271 { | |
1272 if ((currentFreq-Math2_slope) < limitotakoff && (currentFreq-Math2_slope) > -limitotakoff) | |
1273 { | |
1274 N_Math2slope = N_Math2slope + 1; | |
1275 Math2_slope = currentFreq; | |
1276 Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope; | |
1277 Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1); | |
1278 } | |
1279 else | |
1280 { | |
1281 if (AutoStopSlopeCancellingIfDelock) { | |
1282 // stop slope cancelling if the comb is not locked | |
1283 | |
1284 double frequency = DEDRIFT_DDS_FREQUENCY; | |
1285 if (KeepFrequ) | |
1286 frequency = DDSFox_ReadFreq(&DDS1xAD9956); | |
1287 | |
1288 if (! KeepSlope) | |
1289 SlopeMath2 = 0.0; | |
1290 | |
1291 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); | |
1292 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2); | |
1293 | |
1294 SlopeMeasuring = FALSE; | |
1295 N_Math2slope = 0.0; | |
1296 Math2_slope = 0.0; | |
1297 MoyMath2 = 0.0; | |
1298 Moy_Math2slope = 0.0; | |
1299 Slope_Math2slope = 0.0; | |
1300 CenterFrequencyCh2 = 0.0; | |
1301 CenterFrequencyCh2ToDetermine = TRUE; | |
1302 Nratio = -1; | |
1303 nstabilisationSlopeMeasuring = 0; | |
1304 | |
1305 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); | |
1306 } | |
1307 } | |
1308 } | |
1309 } | 1288 } |
1310 } | 1289 } |
1311 | 1290 |
1312 // re-centering | 1291 // re-centering |
1313 if (KeepCentering) { | 1292 if (KeepCentering) { |
2364 } | 2343 } |
2365 return 0; | 2344 return 0; |
2366 } | 2345 } |
2367 | 2346 |
2368 | 2347 |
2369 int CVICALLBACK CB_OnAutoStopSlopeCancellingIfDelock (int panel, int control, int event, | 2348 int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, |
2370 void *callbackData, int eventData1, int eventData2) | 2349 void *callbackData, int eventData1, int eventData2) |
2371 { | 2350 { |
2372 switch (event) | 2351 switch (event) |
2373 { | 2352 { |
2374 case EVENT_COMMIT: | 2353 case EVENT_COMMIT: |
2375 GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &AutoStopSlopeCancellingIfDelock); | 2354 GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &StopSlopeCancellingOnUnlocked); |
2376 break; | 2355 break; |
2377 } | 2356 } |
2378 return 0; | 2357 return 0; |
2379 } | 2358 } |
2380 | 2359 |