# HG changeset patch # User Daniele Nicolodi # Date 1436534475 -7200 # Node ID a451d4618dbff55710c0ffc5446bddd0ddd9c2a9 # Parent 3f395eab72eb01a762f646fa57809c032015433a Simplify code moving the update of the DDS frequency display to the wrappers diff -r 3f395eab72eb -r a451d4618dbf FXAnalyse.c --- a/FXAnalyse.c Fri Jul 10 13:40:36 2015 +0200 +++ b/FXAnalyse.c Fri Jul 10 15:21:15 2015 +0200 @@ -196,22 +196,33 @@ struct ad9956 ad9956; struct ad9912 ad9912; +static const int PANEL_DDS[4] = { PANEL_DDS1, PANEL_DDS2, PANEL_DDS3, PANEL_DDS4 }; static inline int ad9912_set_frequency_w(struct ad9912 *d, unsigned c, double f) { int r = ad9912_set_frequency(d, c, f); - if (r) + if (r) { logmessage(ERROR, "ad9912 set frequency channel=%d error=%d", c, -r); - return r; + return r; + } + + // update DDS frequency display + SetCtrlVal(MainPanel, PANEL_DDS[c], d->frequency[i]); + return 0; } static inline int ad9912_ramp_frequency_w(struct ad9912 *d, unsigned c, double f, double s) { int r = ad9912_ramp_frequency(d, c, f, s); - if (r) + if (r) { logmessage(ERROR, "ad9912 ramp frequency channel=%d error=%d", c, -r); - return r; + return r; + } + + // update DDS frequency display + SetCtrlVal(MainPanel, PANEL_DDS[c], d->frequency[i]); + return 0; } @@ -547,7 +558,6 @@ } else { freq = freq + adj; ad9912_set_frequency_w(&ad9912, 1, freq); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); } } @@ -561,7 +571,6 @@ } else { freq = freq + adj; ad9912_set_frequency_w(&ad9912, 2, freq); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); } } @@ -575,7 +584,6 @@ } else { freq = freq + adj; ad9912_set_frequency_w(&ad9912, 3, freq); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj); } } @@ -721,7 +729,6 @@ double frequency, clock; char expr[1024]; char host[256]; - int PANEL_DDS[4] = { PANEL_DDS1, PANEL_DDS2, PANEL_DDS3, PANEL_DDS4 }; if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) return -1; @@ -786,12 +793,11 @@ // try to read back current frequency from DDS for (i = 0; i < 4; i++) { rv = ad9912_get_frequency(&ad9912, i, &frequency); - if ((rv) || (frequency == 0.0)) { + if ((rv != 0) || (frequency == 0.0)) { logmessage(WARNING, "reset DDS%d frequency to default value", i + 1); GetCtrlVal(MainPanel, PANEL_DDS[i], &frequency); ad9912_set_frequency_w(&ad9912, i, frequency); } - SetCtrlVal(MainPanel, PANEL_DDS[i], frequency); } // setup ZMQ pub socket @@ -1046,7 +1052,6 @@ // set DDS1 to nominal frequency ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // record current DDS frequencies f0_DDS[1] = ad9912.frequency[1]; @@ -1071,7 +1076,6 @@ // frep positive step ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[LO], FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // allow counter to settle settling = 3; @@ -1090,7 +1094,6 @@ double fDDS2 = ad9912.frequency[1]; ad9912_set_frequency_w(&ad9912, 1, fDDS2 + 275000 - Ch4); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); // allow counter to settle settling = 3; @@ -1117,7 +1120,6 @@ // frep negative step ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[LO], FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // allow counter to settle settling = 3; @@ -1151,8 +1153,6 @@ // back to nominal frep ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); // done n_measurement[LO] = N_MEASUREMENT_NONE; @@ -1171,7 +1171,6 @@ // set DDS1 to nominal frequency ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // record current DDS frequencies f0_DDS[1] = ad9912.frequency[1]; @@ -1202,13 +1201,11 @@ // frep positive step double fDDS1 = f0_DDS[0] + delta_f_lock[HG]; ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // adjust DDS3 to keep beatnote within the bandpass filter. prediction double fDDS3 = f0_DDS[2] + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; df_DDS3 = fDDS3 - ad9912.frequency[2]; ad9912_set_frequency_w(&ad9912, 2, fDDS3); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); // allow counter to settle settling = 3; @@ -1227,12 +1224,10 @@ double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; ad9912_set_frequency_w(&ad9912, 1, fDDS2); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); double fDDS3 = ad9912.frequency[2] + 10000 - Ch2; df_DDS3 = df_DDS3 + 10000 - Ch2; ad9912_set_frequency_w(&ad9912, 2, fDDS3); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); // allow counter to settle settling = 3; @@ -1262,13 +1257,11 @@ // negative frequency step double fDDS1 = f0_DDS[0] - delta_f_lock[HG]; ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // adjust DDS3 to keep beatnote within the bandpass filter. prediction double fDDS3 = f0_DDS[2] - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; df_DDS3 = fDDS3 - ad9912.frequency[2]; ad9912_set_frequency_w(&ad9912, 2, fDDS3); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); // allow counter to settle settling = 3; @@ -1311,9 +1304,6 @@ ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); ad9912_set_frequency_w(&ad9912, 2, f0_DDS[2]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); // done n_measurement[HG] = N_MEASUREMENT_NONE; @@ -1332,7 +1322,6 @@ // set DDS1 to nominal frequency ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // record current DDS frequencies f0_DDS[1] = ad9912.frequency[1]; @@ -1369,12 +1358,10 @@ // frep positive step ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[SR], FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // adjust DDS3 to keep beatnote within the bandpass filter double fDDS4 = f0_DDS[3] + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; ad9912_set_frequency_w(&ad9912, 3, fDDS4); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); // allow counter to settle settling = 3; @@ -1394,7 +1381,6 @@ // adjust DDS frequency to keep 55 MHz tracker oscillator locked double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; ad9912_set_frequency_w(&ad9912, 1, fDDS2); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); // allow counter to settle settling = 3; @@ -1423,12 +1409,10 @@ // frep negative step ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[SR], FREP_STEP_SIZE); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // adjust DDS3 to keep beatnote within the bandpass filter double fDDS4 = f0_DDS[3] - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; ad9912_set_frequency_w(&ad9912, 3, fDDS4); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); // allow counter to settle settling = 3; @@ -1480,9 +1464,6 @@ ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); // done n_measurement[SR] = N_MEASUREMENT_NONE; @@ -1518,7 +1499,6 @@ // back to original repetition rate ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); // measurement done beatsign.measure = NONE; @@ -1622,19 +1602,15 @@ switch (control) { case PANEL_DDS1: ad9912_set_frequency_w(&ad9912, 0, frequency); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); break; case PANEL_DDS2: ad9912_set_frequency_w(&ad9912, 1, frequency); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); break; case PANEL_DDS3: ad9912_set_frequency_w(&ad9912, 2, frequency); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); break; case PANEL_DDS4: ad9912_set_frequency_w(&ad9912, 3, frequency); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); break; } break; @@ -1879,12 +1855,6 @@ break; } - // update DDS frequencies display - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); - break; } return 0; @@ -1921,7 +1891,6 @@ // step the repetition rate beatsign.f0_DDS = ad9912.frequency[0]; ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS + step); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); break; } @@ -1940,17 +1909,14 @@ case PANEL_ADJUST_DDS2: frequency = ad9912.frequency[1] + 275000 - Ch4; ad9912_set_frequency_w(&ad9912, 1, frequency); - SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); break; case PANEL_ADJUST_DDS3: frequency = ad9912.frequency[2] + 10000 - Ch2; ad9912_set_frequency_w(&ad9912, 2, frequency); - SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); break; case PANEL_ADJUST_DDS4: frequency = ad9912.frequency[3] + 10000 - Ch3; ad9912_set_frequency_w(&ad9912, 3, frequency); - SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); break; } break; @@ -1967,7 +1933,6 @@ GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); f0_DDS[0] = 880000000.0 / Ndiv; ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); - SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); break; } return 0;