# HG changeset patch # User Daniele Nicolodi # Date 1411056098 -7200 # Node ID 28a4ff70fe4844f6f670eee217a252fabbe36f85 # Parent ddc8c47db3df38eb62a79e881cf16669b86a2b13 Rework beatnote sign determination. Fix Sign3 measurement diff -r ddc8c47db3df -r 28a4ff70fe48 FXAnalyse.c --- a/FXAnalyse.c Fri May 02 16:33:24 2014 +0200 +++ b/FXAnalyse.c Thu Sep 18 18:01:38 2014 +0200 @@ -260,11 +260,52 @@ double f_beat_plus, f_beat_minus; double N_measured; -double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; -double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0; -double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; +// Beatnote sign determination is done stepping the repetition rate by +// stepping the comb phase-lock offset frequency f_lock generated by +// DDS1. A lock frequency step delta_f_lock determines a change in the +// repetition rate given by: +// +// abs(delta_f_rep) = Ndiv * delta_f_lock / N1 +// +// where Ndiv = 8 and N1 ~= 8 x 10^5 obtaining that +// +// abs(delta_f_rep) ~= delta_f_lock / 10^5 +// +// For the determination of the comb locking beatnote sign we detect +// the sign of delta_f_rep caused by a positive delta_f_lock. f_rep is +// measured should be small enough to do not exceed the 200x PLL +// bandwidth but still be clearly identified. +// +// For the optical beatnotes we detect the sign of delta_f_beat caused +// by a positive delta_f_lock thus we need to take into account the +// sign of the comb locking beatnote. The optical beatnote frequency +// change is given by +// +// abs(delta_f_beat) = abs(delta_f_rep) * Nx +// +// where Nx ~= 10^6 obtaining that +// +// abs(delta_f_beat) ~= delta_f_lock * 10 +// +// this need to do not exceed the beatnote filters bandwidth. Given +// those contraints the following f_lock steps are chosen: -int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; +double f_lock_step_1 = 10000.0; +double f_lock_step_2 = 10.0; +double f_lock_step_3 = 10.0; + +struct beatsign { + int measure; // which beatnote sign is being measured + double f0_DDS1; // DDS1 frequency before stepping + double t0; // measurement start time + double f_rep_zero; // repetition rate before stepping + double f_beat_zero; // beatnote frequwncy before stepping +}; + +struct beatsign beatsign = { + .measure = 0, +}; + struct stat stat_math1, stat_ch2, stat_ch3, freq; struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; @@ -1206,47 +1247,45 @@ break; } - // beatnote sign determination - - if (Getsign1 == TRUE) { - if (utc > tbegin1+2) { - if (Math1 > Frepbefore1) - Sign1 = -1.0; - else - Sign1 = +1.0; - ad9912_set_frequency_w(&ad9912, 0, Frequency1); - Getsign1 = FALSE; + // beatnote sign determination + if ((beatsign.measure) && + (utc > beatsign.t0 + 2.0)) { + + int f_beat_sign, f_rep_sign = 0; + + switch (beatsign.measure) { + case LO: + f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; + Sign1 = f_rep_sign; SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); + break; + case HG: + f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; + f_beat_sign = (Ch2 > beatsign.f_beat_zero) ? -1 : 1; + Sign2 = f_rep_sign * f_beat_sign; + SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); + break; + case SR: + f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; + f_beat_sign = (Ch3 > beatsign.f_beat_zero) ? -1 : 1; + Sign3 = f_rep_sign * f_beat_sign; + SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); + break; } - } - if (Getsign2 == TRUE) { - if (utc > tbegin2+2){ - if (Math1 > Frepbefore2) { - if (Ch2 > Ch2before) - Sign2 = +1.0; - else - Sign2 = -1.0; - } else { - if (Ch2 > Ch2before) - Sign2 = -1.0; - else - Sign2 = +1.0; - } - ad9912_set_frequency_w(&ad9912, 0, Frequency2); - Getsign2 = FALSE; - SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); - } - } - if (Getsign3 == TRUE) { - if (utc > tbegin3+2){ - if (Ch3 > Frepbefore3) - Sign3 = -1.0; - else - Sign3 = +1.0; - ad9912_set_frequency_w(&ad9912, 0, Frequency3); - Getsign3 = FALSE; - SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); - } + + // back to original repetition rate + ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1); + SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); + + // measurement done + beatsign.measure = 0; + + // in the case of the optical beatnotes sign measurement + // we induce fairly small steps in f_rep therefore it is + // good to check that we get the sign of the comb locking + // beatnote right in those cases + if (f_rep_sign != Sign1) + logmessage(ERROR, "merasured f_rep_sign does not agree with previous determination!"); } // select reference @@ -1693,37 +1732,36 @@ int CVICALLBACK CB_OnFindSign (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { + double step = 0.0; switch (event) { case EVENT_COMMIT: - switch (control) - { - case PANEL_FINDSIGN1: - tbegin1 = utc; - Frepbefore1 = Math1; - GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ; - SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ; - ad9912_set_frequency_w(&ad9912, 0, Frequency1+Frequencystep1); - Getsign1 = TRUE; + switch (control) { + case PANEL_FINDSIGN1: + beatsign.measure = LO; + beatsign.f_beat_zero = 0.0; + step = f_lock_step_1; break; case PANEL_FINDSIGN2: - tbegin2 = utc; - Frepbefore2 = Math1; - Ch2before = Ch2; - GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ; - SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ; - ad9912_set_frequency_w(&ad9912, 0, Frequency2+Frequencystep2); - Getsign2 = TRUE; + beatsign.measure = HG; + beatsign.f_beat_zero = Ch2; + step = f_lock_step_2; break; case PANEL_FINDSIGN3: - tbegin3 = utc; - Frepbefore3 = Math1; - GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency3) ; - SetCtrlVal(MainPanel, PANEL_DDS1, Frequency3+Frequencystep3) ; - ad9912_set_frequency_w(&ad9912, 0, Frequency3+Frequencystep3); - Getsign3 = TRUE; + beatsign.measure = SR; + beatsign.f_beat_zero = Ch3; + step = f_lock_step_3; break; } + + beatsign.t0 = utc; + beatsign.f_rep_zero = Math1; + + // step the repetition rate + beatsign.f0_DDS1 = ad9912.frequency[0]; + ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS1 + step); + SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); + break; } return 0;