comparison FXAnalyse.c @ 268:ec4462c7f8b7

Extensive cleanup of beatnote specific variables Reorganize the beatnote specific variables in arrays indexed by the beatnote enum constants LO, HG, SR. Also reorganize DDS frequency related variables in arrays indexed by the DDS channel number.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 09 Jul 2015 23:11:00 +0200
parents 1de805d2d37a
children 3f395eab72eb
comparison
equal deleted inserted replaced
267:1de805d2d37a 268:ec4462c7f8b7
260 NONE = -1, 260 NONE = -1,
261 LO = 0, 261 LO = 0,
262 MICROWAVE = LO, 262 MICROWAVE = LO,
263 HG, 263 HG,
264 SR, 264 SR,
265 _N_BEATS, 265 NBEATNOTES,
266 }; 266 };
267
267 268
268 enum { 269 enum {
269 N_MEASUREMENT_NONE, 270 N_MEASUREMENT_NONE,
270 N_MEASUREMENT_INIT, 271 N_MEASUREMENT_INIT,
271 N_MEASUREMENT_SLOPE, 272 N_MEASUREMENT_SLOPE,
273 N_MEASUREMENT_FREP_PLUS, 274 N_MEASUREMENT_FREP_PLUS,
274 N_MEASUREMENT_ADJUST_FREQ_MINUS, 275 N_MEASUREMENT_ADJUST_FREQ_MINUS,
275 N_MEASUREMENT_FREP_MINUS, 276 N_MEASUREMENT_FREP_MINUS,
276 }; 277 };
277 278
278 int n_measurement_1 = N_MEASUREMENT_NONE; 279 int n_measurement[NBEATNOTES] = { N_MEASUREMENT_NONE, };
279 int n_measurement_2 = N_MEASUREMENT_NONE; 280 double slop_time[NBEATNOTES] = { 40.0, };
280 int n_measurement_3 = N_MEASUREMENT_NONE; 281 double integration_time[NBEATNOTES] = { 40.0, };
281 282 double delta_f_lock[NBEATNOTES] = { 500e3, };
282 int nobs = 0;
283 int settling = 0;
284
285 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3, f0_DDS4, df_DDS3;
286
287 double slope_time_1 = 40.0, integration_time_1 = 40.0, delta_f_lock_1 = 500e3;
288 double slope_time_2 = 40.0, integration_time_2 = 40.0, delta_f_lock_2 = 500e3;
289 double slope_time_3 = 40.0, integration_time_3 = 40.0, delta_f_lock_3 = 500e3;
290 283
291 double t1, t2, t3; 284 double t1, t2, t3;
292 double f_rep_slope, f_beat_slope; 285 double f_rep_slope, f_beat_slope;
293 double f_rep_plus, f_rep_minus; 286 double f_rep_plus, f_rep_minus;
294 double f_beat_plus, f_beat_minus; 287 double f_beat_plus, f_beat_minus;
288
289 double f0_DDS[4] = { 110000000.0, 0.0, 0.0, 0.0 };
290 double df_DDS3 = 0.0;
291
292 int nobs = 0;
293 int settling = 0;
295 294
296 295
297 // Beatnote sign determination is done stepping the repetition rate by 296 // Beatnote sign determination is done stepping the repetition rate by
298 // stepping the comb phase-lock offset frequency f_lock generated by 297 // stepping the comb phase-lock offset frequency f_lock generated by
299 // DDS1. A lock frequency step delta_f_lock determines a change in the 298 // DDS1. A lock frequency step delta_f_lock determines a change in the
322 // abs(delta_f_beat) ~= delta_f_lock * 10 321 // abs(delta_f_beat) ~= delta_f_lock * 10
323 // 322 //
324 // this need to do not exceed the beatnote filters bandwidth. Given 323 // this need to do not exceed the beatnote filters bandwidth. Given
325 // those contraints the following f_lock steps are chosen: 324 // those contraints the following f_lock steps are chosen:
326 325
327 double f_lock_step_1 = 10000.0; 326 double f_lock_step[NBEATNOTES] = {
328 double f_lock_step_2 = 10.0; 327 [LO] = 10000.0,
329 double f_lock_step_3 = 10.0; 328 [HG] = 10.0,
329 [SR] = 10.0
330 };
330 331
331 struct beatsign { 332 struct beatsign {
332 int measure; // which beatnote sign is being measured 333 int measure; // which beatnote sign is being measured
333 double f0_DDS1; // DDS1 frequency before stepping 334 double f0_DDS; // DDS frequency before stepping
334 double t0; // measurement start time 335 double t0; // measurement start time
335 double f_rep_zero; // repetition rate before stepping 336 double f_rep_zero; // repetition rate before stepping
336 double f_beat_zero; // beatnote frequwncy before stepping 337 double f_beat_zero; // beatnote frequwncy before stepping
337 }; 338 };
338 339
495 } 496 }
496 497
497 498
498 // recenter 499 // recenter
499 struct recenter { 500 struct recenter {
500 int active; // recenter enabled 501 int active; // recenter enabled
501 int enabled[_N_BEATS]; // which beatnotes to recenter 502 int enabled[NBEATNOTES]; // which beatnotes to recenter
502 double threshold[_N_BEATS]; // maximum frequency correction 503 double threshold[NBEATNOTES]; // maximum frequency correction
503 double interval; // interval 504 double interval; // interval
504 double t0; // beginning of current interval 505 double t0; // beginning of current interval
505 }; 506 };
506 507
507 struct recenter recenter = { 508 struct recenter recenter = {
508 .active = FALSE, 509 .active = FALSE,
509 .enabled = { FALSE, FALSE, FALSE }, 510 .enabled = { FALSE, FALSE, FALSE },
516 int recenter_enabled() 517 int recenter_enabled()
517 { 518 {
518 if (! recenter.active) 519 if (! recenter.active)
519 return FALSE; 520 return FALSE;
520 521
521 for (int i = 0; i < _N_BEATS; i++) 522 for (int i = 0; i < NBEATNOTES; i++)
522 if (recenter.enabled[i]) 523 if (recenter.enabled[i])
523 return TRUE; 524 return TRUE;
524 525
525 return FALSE; 526 return FALSE;
526 } 527 }
1032 for (struct adev *adev = adevs; adev->data; adev++) 1033 for (struct adev *adev = adevs; adev->data; adev++)
1033 adev_update(adev); 1034 adev_update(adev);
1034 1035
1035 // N measurement 1036 // N measurement
1036 1037
1037 switch (n_measurement_1) { 1038 switch (n_measurement[LO]) {
1038 1039
1039 case N_MEASUREMENT_NONE: 1040 case N_MEASUREMENT_NONE:
1040 // not measuring 1041 // not measuring
1041 break; 1042 break;
1042 1043
1043 case N_MEASUREMENT_INIT: 1044 case N_MEASUREMENT_INIT:
1044 // initialization step 1045 // initialization step
1045 1046
1046 // set DDS1 to nominal frequency 1047 // set DDS1 to nominal frequency
1047 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1); 1048 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
1048 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1049 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1049 1050
1050 // record current DDS frequencies 1051 // record current DDS frequencies
1051 f0_DDS2 = ad9912.frequency[1]; 1052 f0_DDS[1] = ad9912.frequency[1];
1052 1053
1053 t1 = utc; 1054 t1 = utc;
1054 t2 = t3 = 0.0; 1055 t2 = t3 = 0.0;
1055 nobs = 0; 1056 nobs = 0;
1056 stat_zero(&stat_math1); 1057 stat_zero(&stat_math1);
1057 f_rep_plus = f_rep_minus = 0.0; 1058 f_rep_plus = f_rep_minus = 0.0;
1058 1059
1059 // next step 1060 // next step
1060 n_measurement_1 += 1; 1061 n_measurement[LO] += 1;
1061 break; 1062 break;
1062 1063
1063 case N_MEASUREMENT_SLOPE: 1064 case N_MEASUREMENT_SLOPE:
1064 // slope measurement 1065 // slope measurement
1065 1066
1066 stat_accumulate(&stat_math1, Math1); 1067 stat_accumulate(&stat_math1, Math1);
1067 1068
1068 if ((utc - t1) > slope_time_1) { 1069 if ((utc - t1) > slope_time[LO]) {
1069 f_rep_slope = stat_math1.slope; 1070 f_rep_slope = stat_math1.slope;
1070 1071
1071 // frep positive step 1072 // frep positive step
1072 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE); 1073 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[LO], FREP_STEP_SIZE);
1073 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1074 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1074 1075
1075 // allow counter to settle 1076 // allow counter to settle
1076 settling = 3; 1077 settling = 3;
1077 1078
1078 // next step 1079 // next step
1079 n_measurement_1 += 1; 1080 n_measurement[LO] += 1;
1080 } 1081 }
1081 break; 1082 break;
1082 1083
1083 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 1084 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
1084 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 1085 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
1093 1094
1094 // allow counter to settle 1095 // allow counter to settle
1095 settling = 3; 1096 settling = 3;
1096 1097
1097 // next step 1098 // next step
1098 n_measurement_1 += 1; 1099 n_measurement[LO] += 1;
1099 break; 1100 break;
1100 1101
1101 case N_MEASUREMENT_FREP_PLUS: 1102 case N_MEASUREMENT_FREP_PLUS:
1102 // frep positive step 1103 // frep positive step
1103 1104
1108 t2 = utc; 1109 t2 = utc;
1109 1110
1110 f_rep_plus += Math1 - f_rep_slope * (utc - t2); 1111 f_rep_plus += Math1 - f_rep_slope * (utc - t2);
1111 nobs += 1; 1112 nobs += 1;
1112 1113
1113 if ((utc - t2) > integration_time_1) { 1114 if ((utc - t2) > integration_time[LO]) {
1114 f_rep_plus = f_rep_plus / nobs; 1115 f_rep_plus = f_rep_plus / nobs;
1115 nobs = 0; 1116 nobs = 0;
1116 1117
1117 // frep negative step 1118 // frep negative step
1118 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE); 1119 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[LO], FREP_STEP_SIZE);
1119 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1120 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1120 1121
1121 // allow counter to settle 1122 // allow counter to settle
1122 settling = 3; 1123 settling = 3;
1123 1124
1124 // next step 1125 // next step
1125 n_measurement_1 += 1; 1126 n_measurement[LO] += 1;
1126 } 1127 }
1127 break; 1128 break;
1128 1129
1129 case N_MEASUREMENT_FREP_MINUS: 1130 case N_MEASUREMENT_FREP_MINUS:
1130 // frep negative step 1131 // frep negative step
1136 t3 = utc; 1137 t3 = utc;
1137 1138
1138 f_rep_minus += Math1 - f_rep_slope * (utc - t2); 1139 f_rep_minus += Math1 - f_rep_slope * (utc - t2);
1139 nobs += 1; 1140 nobs += 1;
1140 1141
1141 if ((utc - t3) > integration_time_1) { 1142 if ((utc - t3) > integration_time[LO]) {
1142 f_rep_minus = f_rep_minus / nobs; 1143 f_rep_minus = f_rep_minus / nobs;
1143 nobs = 0; 1144 nobs = 0;
1144 1145
1145 // compute N1 1146 // compute N1
1146 double delta_f_rep = f_rep_minus - f_rep_plus; 1147 double delta_f_rep = f_rep_minus - f_rep_plus;
1147 double measured = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep; 1148 double measured = Sign1 * 2 * Ndiv * delta_f_lock[LO] / delta_f_rep;
1148 SetCtrlVal(CalcNPanel, CALCN_N, measured); 1149 SetCtrlVal(CalcNPanel, CALCN_N, measured);
1149 1150
1150 // back to nominal frep 1151 // back to nominal frep
1151 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1152 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1152 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1153 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1153 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1154 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1154 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 1155 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1155 1156
1156 // done 1157 // done
1157 n_measurement_1 = N_MEASUREMENT_NONE; 1158 n_measurement[LO] = N_MEASUREMENT_NONE;
1158 } 1159 }
1159 break; 1160 break;
1160 } 1161 }
1161 1162
1162 switch (n_measurement_2) { 1163 switch (n_measurement[HG]) {
1163 1164
1164 case N_MEASUREMENT_NONE: 1165 case N_MEASUREMENT_NONE:
1165 // not measuring 1166 // not measuring
1166 break; 1167 break;
1167 1168
1168 case N_MEASUREMENT_INIT: 1169 case N_MEASUREMENT_INIT:
1169 // initialization step 1170 // initialization step
1170 1171
1171 // set DDS1 to nominal frequency 1172 // set DDS1 to nominal frequency
1172 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1); 1173 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
1173 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1174 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1174 1175
1175 // record current DDS frequencies 1176 // record current DDS frequencies
1176 f0_DDS2 = ad9912.frequency[1]; 1177 f0_DDS[1] = ad9912.frequency[1];
1177 f0_DDS3 = ad9912.frequency[2]; 1178 f0_DDS[2] = ad9912.frequency[2];
1178 1179
1179 t1 = utc; 1180 t1 = utc;
1180 t2 = t3 = 0.0; 1181 t2 = t3 = 0.0;
1181 nobs = 0; 1182 nobs = 0;
1182 stat_zero(&stat_math1); 1183 stat_zero(&stat_math1);
1183 stat_zero(&stat_ch2); 1184 stat_zero(&stat_ch2);
1184 f_rep_plus = f_rep_minus = 0.0; 1185 f_rep_plus = f_rep_minus = 0.0;
1185 f_beat_plus = f_beat_minus = 0.0; 1186 f_beat_plus = f_beat_minus = 0.0;
1186 1187
1187 // next step 1188 // next step
1188 n_measurement_2 += 1; 1189 n_measurement[HG] += 1;
1189 break; 1190 break;
1190 1191
1191 case N_MEASUREMENT_SLOPE: 1192 case N_MEASUREMENT_SLOPE:
1192 // slope measurement 1193 // slope measurement
1193 1194
1194 stat_accumulate(&stat_math1, Math1); 1195 stat_accumulate(&stat_math1, Math1);
1195 stat_accumulate(&stat_ch2, Ch2); 1196 stat_accumulate(&stat_ch2, Ch2);
1196 1197
1197 if ((utc - t1) > slope_time_2) { 1198 if ((utc - t1) > slope_time[HG]) {
1198 f_rep_slope = stat_math1.slope; 1199 f_rep_slope = stat_math1.slope;
1199 f_beat_slope = stat_ch2.slope; 1200 f_beat_slope = stat_ch2.slope;
1200 1201
1201 // frep positive step 1202 // frep positive step
1202 double fDDS1 = f0_DDS1 + delta_f_lock_2; 1203 double fDDS1 = f0_DDS[0] + delta_f_lock[HG];
1203 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); 1204 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
1204 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1205 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1205 1206
1206 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 1207 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
1207 double fDDS3 = f0_DDS3 + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2; 1208 double fDDS3 = f0_DDS[2] + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG];
1208 df_DDS3 = fDDS3 - ad9912.frequency[2]; 1209 df_DDS3 = fDDS3 - ad9912.frequency[2];
1209 ad9912_set_frequency_w(&ad9912, 2, fDDS3); 1210 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
1210 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); 1211 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1211 1212
1212 // allow counter to settle 1213 // allow counter to settle
1213 settling = 3; 1214 settling = 3;
1214 1215
1215 // next step 1216 // next step
1216 n_measurement_2 += 1; 1217 n_measurement[HG] += 1;
1217 } 1218 }
1218 break; 1219 break;
1219 1220
1220 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 1221 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
1221 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 1222 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
1235 1236
1236 // allow counter to settle 1237 // allow counter to settle
1237 settling = 3; 1238 settling = 3;
1238 1239
1239 // next step 1240 // next step
1240 n_measurement_2 += 1; 1241 n_measurement[HG] += 1;
1241 break; 1242 break;
1242 1243
1243 case N_MEASUREMENT_FREP_PLUS: 1244 case N_MEASUREMENT_FREP_PLUS:
1244 // frep positive step 1245 // frep positive step
1245 1246
1251 1252
1252 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1253 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1253 f_beat_plus += Ch2 - f_beat_slope * (utc - t2); 1254 f_beat_plus += Ch2 - f_beat_slope * (utc - t2);
1254 nobs += 1; 1255 nobs += 1;
1255 1256
1256 if ((utc - t2) > integration_time_2) { 1257 if ((utc - t2) > integration_time[HG]) {
1257 f_rep_plus = f_rep_plus / nobs; 1258 f_rep_plus = f_rep_plus / nobs;
1258 f_beat_plus = f_beat_plus / nobs; 1259 f_beat_plus = f_beat_plus / nobs;
1259 nobs = 0; 1260 nobs = 0;
1260 1261
1261 // negative frequency step 1262 // negative frequency step
1262 double fDDS1 = f0_DDS1 - delta_f_lock_2; 1263 double fDDS1 = f0_DDS[0] - delta_f_lock[HG];
1263 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); 1264 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
1264 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1265 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1265 1266
1266 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 1267 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
1267 double fDDS3 = f0_DDS3 - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2; 1268 double fDDS3 = f0_DDS[2] - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG];
1268 df_DDS3 = fDDS3 - ad9912.frequency[2]; 1269 df_DDS3 = fDDS3 - ad9912.frequency[2];
1269 ad9912_set_frequency_w(&ad9912, 2, fDDS3); 1270 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
1270 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); 1271 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1271 1272
1272 // allow counter to settle 1273 // allow counter to settle
1273 settling = 3; 1274 settling = 3;
1274 1275
1275 // next step 1276 // next step
1276 n_measurement_2 += 1; 1277 n_measurement[HG] += 1;
1277 } 1278 }
1278 break; 1279 break;
1279 1280
1280 case N_MEASUREMENT_FREP_MINUS: 1281 case N_MEASUREMENT_FREP_MINUS:
1281 // frep negative step 1282 // frep negative step
1288 1289
1289 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1290 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1290 f_beat_minus += Ch2 + f_beat_slope * (utc - t2); 1291 f_beat_minus += Ch2 + f_beat_slope * (utc - t2);
1291 nobs += 1; 1292 nobs += 1;
1292 1293
1293 if ((utc -t3) > integration_time_2) { 1294 if ((utc -t3) > integration_time[HG]) {
1294 f_rep_minus = f_rep_minus / nobs; 1295 f_rep_minus = f_rep_minus / nobs;
1295 f_beat_minus = f_beat_minus / nobs; 1296 f_beat_minus = f_beat_minus / nobs;
1296 nobs = 0; 1297 nobs = 0;
1297 1298
1298 // compute N2 1299 // compute N2
1299 double delta_f_rep_m = f_rep_minus - f_rep_plus; 1300 double delta_f_rep_m = f_rep_minus - f_rep_plus;
1300 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_2 / N1; 1301 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[HG] / N1;
1301 double delta = delta_f_rep_m - delta_f_rep; 1302 double delta = delta_f_rep_m - delta_f_rep;
1302 1303
1303 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", 1304 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
1304 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); 1305 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
1305 1306
1306 double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; 1307 double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep;
1307 SetCtrlVal(CalcNPanel, CALCN_N, measured); 1308 SetCtrlVal(CalcNPanel, CALCN_N, measured);
1308 1309
1309 // back to nominal frequency 1310 // back to nominal frequency
1310 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1311 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1311 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1312 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1312 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3); 1313 ad9912_set_frequency_w(&ad9912, 2, f0_DDS[2]);
1313 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1314 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1314 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 1315 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1315 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); 1316 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1316 1317
1317 // done 1318 // done
1318 n_measurement_2 = N_MEASUREMENT_NONE; 1319 n_measurement[HG] = N_MEASUREMENT_NONE;
1319 } 1320 }
1320 break; 1321 break;
1321 } 1322 }
1322 1323
1323 switch (n_measurement_3) { 1324 switch (n_measurement[SR]) {
1324 1325
1325 case N_MEASUREMENT_NONE: 1326 case N_MEASUREMENT_NONE:
1326 // not measuring N3 1327 // not measuring N3
1327 break; 1328 break;
1328 1329
1329 case N_MEASUREMENT_INIT: 1330 case N_MEASUREMENT_INIT:
1330 // init 1331 // init
1331 1332
1332 // set DDS1 to nominal frequency 1333 // set DDS1 to nominal frequency
1333 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1); 1334 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
1334 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1335 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1335 1336
1336 // record current DDS frequencies 1337 // record current DDS frequencies
1337 f0_DDS2 = ad9912.frequency[1]; 1338 f0_DDS[1] = ad9912.frequency[1];
1338 f0_DDS4 = ad9912.frequency[3]; 1339 f0_DDS[3] = ad9912.frequency[3];
1339 1340
1340 t1 = utc; 1341 t1 = utc;
1341 t2 = t3 = 0.0; 1342 t2 = t3 = 0.0;
1342 nobs = 0; 1343 nobs = 0;
1343 stat_zero(&stat_math1); 1344 stat_zero(&stat_math1);
1344 stat_zero(&stat_ch3); 1345 stat_zero(&stat_ch3);
1345 f_rep_plus = f_rep_minus = 0.0; 1346 f_rep_plus = f_rep_minus = 0.0;
1346 f_beat_plus = f_beat_minus = 0.0; 1347 f_beat_plus = f_beat_minus = 0.0;
1347 1348
1348 // next step 1349 // next step
1349 n_measurement_3 += 1; 1350 n_measurement[SR] += 1;
1350 break; 1351 break;
1351 1352
1352 case N_MEASUREMENT_SLOPE: 1353 case N_MEASUREMENT_SLOPE:
1353 // slope measurement 1354 // slope measurement
1354 1355
1356 break; 1357 break;
1357 1358
1358 stat_accumulate(&stat_math1, Math1); 1359 stat_accumulate(&stat_math1, Math1);
1359 stat_accumulate(&stat_ch3, Ch3); 1360 stat_accumulate(&stat_ch3, Ch3);
1360 1361
1361 if (utc - t1 > slope_time_3) { 1362 if (utc - t1 > slope_time[SR]) {
1362 // slope measurement 1363 // slope measurement
1363 f_rep_slope = stat_math1.slope; 1364 f_rep_slope = stat_math1.slope;
1364 f_beat_slope = stat_ch3.slope; 1365 f_beat_slope = stat_ch3.slope;
1365 1366
1366 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); 1367 logmsg("f_rep_slope=%e Hz/s", f_rep_slope);
1367 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); 1368 logmsg("f_beat_slope=%e Hz/s", f_rep_slope);
1368 1369
1369 // frep positive step 1370 // frep positive step
1370 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE); 1371 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[SR], FREP_STEP_SIZE);
1371 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1372 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1372 1373
1373 // adjust DDS3 to keep beatnote within the bandpass filter 1374 // adjust DDS3 to keep beatnote within the bandpass filter
1374 double fDDS4 = f0_DDS4 + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1375 double fDDS4 = f0_DDS[3] + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
1375 ad9912_set_frequency_w(&ad9912, 3, fDDS4); 1376 ad9912_set_frequency_w(&ad9912, 3, fDDS4);
1376 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); 1377 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1377 1378
1378 // allow counter to settle 1379 // allow counter to settle
1379 settling = 3; 1380 settling = 3;
1380 1381
1381 // next step 1382 // next step
1382 n_measurement_3 += 1; 1383 n_measurement[SR] += 1;
1383 } 1384 }
1384 break; 1385 break;
1385 1386
1386 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 1387 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
1387 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 1388 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
1397 1398
1398 // allow counter to settle 1399 // allow counter to settle
1399 settling = 3; 1400 settling = 3;
1400 1401
1401 // next step 1402 // next step
1402 n_measurement_3 += 1; 1403 n_measurement[SR] += 1;
1403 break; 1404 break;
1404 1405
1405 case N_MEASUREMENT_FREP_PLUS: 1406 case N_MEASUREMENT_FREP_PLUS:
1406 // frep positive step 1407 // frep positive step
1407 1408
1413 1414
1414 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1415 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1415 f_beat_plus += Ch3 - f_beat_slope * (utc - t2); 1416 f_beat_plus += Ch3 - f_beat_slope * (utc - t2);
1416 nobs += 1; 1417 nobs += 1;
1417 1418
1418 if (utc - t2 > integration_time_3) { 1419 if (utc - t2 > integration_time[SR]) {
1419 f_rep_plus = f_rep_plus / nobs; 1420 f_rep_plus = f_rep_plus / nobs;
1420 f_beat_plus = f_beat_plus / nobs; 1421 f_beat_plus = f_beat_plus / nobs;
1421 nobs = 0; 1422 nobs = 0;
1422 1423
1423 // frep negative step 1424 // frep negative step
1424 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE); 1425 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[SR], FREP_STEP_SIZE);
1425 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1426 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1426 1427
1427 // adjust DDS3 to keep beatnote within the bandpass filter 1428 // adjust DDS3 to keep beatnote within the bandpass filter
1428 double fDDS4 = f0_DDS4 - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1429 double fDDS4 = f0_DDS[3] - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
1429 ad9912_set_frequency_w(&ad9912, 3, fDDS4); 1430 ad9912_set_frequency_w(&ad9912, 3, fDDS4);
1430 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); 1431 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1431 1432
1432 // allow counter to settle 1433 // allow counter to settle
1433 settling = 3; 1434 settling = 3;
1434 1435
1435 // next step 1436 // next step
1436 n_measurement_3 += 1; 1437 n_measurement[SR] += 1;
1437 } 1438 }
1438 break; 1439 break;
1439 1440
1440 case N_MEASUREMENT_FREP_MINUS: 1441 case N_MEASUREMENT_FREP_MINUS:
1441 // frep negative step 1442 // frep negative step
1448 1449
1449 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1450 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1450 f_beat_minus += Ch3 - f_beat_slope * (utc - t2); 1451 f_beat_minus += Ch3 - f_beat_slope * (utc - t2);
1451 nobs += 1; 1452 nobs += 1;
1452 1453
1453 if (utc - t3 > integration_time_3) { 1454 if (utc - t3 > integration_time[SR]) {
1454 f_rep_minus = f_rep_minus / nobs; 1455 f_rep_minus = f_rep_minus / nobs;
1455 f_beat_minus = f_beat_minus / nobs; 1456 f_beat_minus = f_beat_minus / nobs;
1456 nobs = 0; 1457 nobs = 0;
1457 1458
1458 // check delta frep 1459 // check delta frep
1459 double delta_f_rep_m = f_rep_minus - f_rep_plus; 1460 double delta_f_rep_m = f_rep_minus - f_rep_plus;
1460 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; 1461 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[SR] / N1;
1461 double delta = delta_f_rep_m - delta_f_rep; 1462 double delta = delta_f_rep_m - delta_f_rep;
1462 1463
1463 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", 1464 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
1464 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); 1465 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
1465 1466
1466 // compute N3 1467 // compute N3
1467 double delta_f_beat = f_beat_minus - f_beat_plus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1468 double delta_f_beat = f_beat_minus - f_beat_plus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR];
1468 double delta_f_beat_expected = delta_f_rep * N3; 1469 double delta_f_beat_expected = delta_f_rep * N3;
1469 1470
1470 logmsg("delta fbeat: measured=%e expected=%e difference=%e", 1471 logmsg("delta fbeat: measured=%e expected=%e difference=%e",
1471 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); 1472 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected);
1472 1473
1474 SetCtrlVal(CalcNPanel, CALCN_N, measured); 1475 SetCtrlVal(CalcNPanel, CALCN_N, measured);
1475 1476
1476 logmsg("measured N3=%.3f", measured); 1477 logmsg("measured N3=%.3f", measured);
1477 1478
1478 // back to nominal frep 1479 // back to nominal frep
1479 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1480 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1480 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1481 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1481 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4); 1482 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]);
1482 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1483 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1483 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 1484 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1484 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); 1485 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1485 1486
1486 // done 1487 // done
1487 n_measurement_3 = N_MEASUREMENT_NONE; 1488 n_measurement[SR] = N_MEASUREMENT_NONE;
1488 } 1489 }
1489 break; 1490 break;
1490 } 1491 }
1491 1492
1492 // beatnote sign determination 1493 // beatnote sign determination
1514 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); 1515 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3);
1515 break; 1516 break;
1516 } 1517 }
1517 1518
1518 // back to original repetition rate 1519 // back to original repetition rate
1519 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1); 1520 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS);
1520 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1521 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1521 1522
1522 // measurement done 1523 // measurement done
1523 beatsign.measure = NONE; 1524 beatsign.measure = NONE;
1524 1525
1767 case PANEL_N1CALCULUS: 1768 case PANEL_N1CALCULUS:
1768 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1769 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1769 if (! visible) { 1770 if (! visible) {
1770 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(LO)); 1771 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(LO));
1771 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); 1772 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo");
1772 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_1); 1773 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time[LO]);
1773 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_1); 1774 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time[LO]);
1774 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); 1775 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[LO] / 1000.0);
1775 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1776 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1776 DisplayPanel(CalcNPanel); 1777 DisplayPanel(CalcNPanel);
1777 } 1778 }
1778 break; 1779 break;
1779 case PANEL_N2CALCULUS: 1780 case PANEL_N2CALCULUS:
1780 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1781 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1781 if (! visible) { 1782 if (! visible) {
1782 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG)); 1783 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG));
1783 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); 1784 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg");
1784 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_2); 1785 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time[HG]);
1785 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_2); 1786 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time[HG]);
1786 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); 1787 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[HG] / 1000.0);
1787 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1788 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1788 DisplayPanel(CalcNPanel); 1789 DisplayPanel(CalcNPanel);
1789 } 1790 }
1790 break; 1791 break;
1791 case PANEL_N3CALCULUS: 1792 case PANEL_N3CALCULUS:
1792 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1793 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1793 if (! visible) { 1794 if (! visible) {
1794 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); 1795 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR));
1795 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); 1796 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr");
1796 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_3); 1797 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time[SR]);
1797 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_3); 1798 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time[SR]);
1798 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); 1799 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[SR] / 1000.0);
1799 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1800 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1800 DisplayPanel(CalcNPanel); 1801 DisplayPanel(CalcNPanel);
1801 } 1802 }
1802 break; 1803 break;
1803 } 1804 }
1816 case EVENT_COMMIT: 1817 case EVENT_COMMIT:
1817 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); 1818 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
1818 measuring = PTR_TO_INT(v); 1819 measuring = PTR_TO_INT(v);
1819 switch (measuring) { 1820 switch (measuring) {
1820 case LO: 1821 case LO:
1821 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_1); 1822 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time[LO]);
1822 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_1); 1823 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time[LO]);
1823 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); 1824 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock[LO]);
1824 // convert from kHz to Hz 1825 // convert from kHz to Hz
1825 delta_f_lock_1 = delta_f_lock_1 * 1000.0; 1826 delta_f_lock[LO] = delta_f_lock[LO] * 1000.0;
1826 n_measurement_1 = TRUE; 1827 n_measurement[LO] = TRUE;
1827 break; 1828 break;
1828 case HG: 1829 case HG:
1829 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_2); 1830 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time[HG]);
1830 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_2); 1831 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time[HG]);
1831 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2); 1832 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock[HG]);
1832 // convert from kHz to Hz 1833 // convert from kHz to Hz
1833 delta_f_lock_2 = delta_f_lock_2 * 1000.0; 1834 delta_f_lock[HG] = delta_f_lock[HG] * 1000.0;
1834 n_measurement_2 = TRUE; 1835 n_measurement[HG] = TRUE;
1835 break; 1836 break;
1836 case SR: 1837 case SR:
1837 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_3); 1838 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time[SR]);
1838 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_3); 1839 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time[SR]);
1839 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3); 1840 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock[SR]);
1840 // convert from kHz to Hz 1841 // convert from kHz to Hz
1841 delta_f_lock_3 = delta_f_lock_3 * 1000.0; 1842 delta_f_lock[SR] = delta_f_lock[SR] * 1000.0;
1842 n_measurement_3 = TRUE; 1843 n_measurement[SR] = TRUE;
1843 break; 1844 break;
1844 } 1845 }
1845 break; 1846 break;
1846 } 1847 }
1847 return 0; 1848 return 0;
1858 HidePanel(CalcNPanel); 1859 HidePanel(CalcNPanel);
1859 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); 1860 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
1860 measuring = PTR_TO_INT(v); 1861 measuring = PTR_TO_INT(v);
1861 switch (measuring) { 1862 switch (measuring) {
1862 case LO: 1863 case LO:
1863 n_measurement_1 = FALSE; 1864 n_measurement[LO] = FALSE;
1864 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1865 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1865 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1866 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1866 break; 1867 break;
1867 case HG: 1868 case HG:
1868 n_measurement_2 = FALSE; 1869 n_measurement[HG] = FALSE;
1869 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1870 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1870 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1871 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1871 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3); 1872 ad9912_set_frequency_w(&ad9912, 2, f0_DDS[2]);
1872 break; 1873 break;
1873 case SR: 1874 case SR:
1874 n_measurement_3 = FALSE; 1875 n_measurement[SR] = FALSE;
1875 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1876 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE);
1876 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1877 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]);
1877 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4); 1878 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]);
1878 break; 1879 break;
1879 } 1880 }
1880 1881
1881 // update DDS frequencies display 1882 // update DDS frequencies display
1882 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1883 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1895 double step = 0.0; 1896 double step = 0.0;
1896 switch (event) 1897 switch (event)
1897 { 1898 {
1898 case EVENT_COMMIT: 1899 case EVENT_COMMIT:
1899 switch (control) { 1900 switch (control) {
1900 case PANEL_FINDSIGN1: 1901 case PANEL_FINDSIGN1:
1901 beatsign.measure = LO; 1902 beatsign.measure = LO;
1902 beatsign.f_beat_zero = 0.0; 1903 beatsign.f_beat_zero = 0.0;
1903 step = f_lock_step_1; 1904 step = f_lock_step[LO];
1904 break; 1905 break;
1905 case PANEL_FINDSIGN2: 1906 case PANEL_FINDSIGN2:
1906 beatsign.measure = HG; 1907 beatsign.measure = HG;
1907 beatsign.f_beat_zero = Ch2; 1908 beatsign.f_beat_zero = Ch2;
1908 step = f_lock_step_2; 1909 step = f_lock_step[HG];
1909 break; 1910 break;
1910 case PANEL_FINDSIGN3: 1911 case PANEL_FINDSIGN3:
1911 beatsign.measure = SR; 1912 beatsign.measure = SR;
1912 beatsign.f_beat_zero = Ch3; 1913 beatsign.f_beat_zero = Ch3;
1913 step = f_lock_step_3; 1914 step = f_lock_step[SR];
1914 break; 1915 break;
1915 } 1916 }
1916 1917
1917 beatsign.t0 = utc; 1918 beatsign.t0 = utc;
1918 beatsign.f_rep_zero = Math1; 1919 beatsign.f_rep_zero = Math1;
1919 1920
1920 // step the repetition rate 1921 // step the repetition rate
1921 beatsign.f0_DDS1 = ad9912.frequency[0]; 1922 beatsign.f0_DDS = ad9912.frequency[0];
1922 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1 + step); 1923 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS + step);
1923 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1924 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1924 1925
1925 break; 1926 break;
1926 } 1927 }
1927 return 0; 1928 return 0;
1962 { 1963 {
1963 switch (event) 1964 switch (event)
1964 { 1965 {
1965 case EVENT_COMMIT: 1966 case EVENT_COMMIT:
1966 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); 1967 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv);
1967 f0_DDS1 = 880000000.0 / Ndiv; 1968 f0_DDS[0] = 880000000.0 / Ndiv;
1968 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1); 1969 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]);
1969 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1970 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1970 break; 1971 break;
1971 } 1972 }
1972 return 0; 1973 return 0;
1973 } 1974 }