diff FXAnalyse.c @ 111:8bdd7e38715f

Fix N3 measurement
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 02 Jul 2013 12:58:01 +0200
parents 2a9f8a811d87
children 6691728a0c58
line wrap: on
line diff
--- a/FXAnalyse.c	Fri Jun 28 14:46:34 2013 +0200
+++ b/FXAnalyse.c	Tue Jul 02 12:58:01 2013 +0200
@@ -106,6 +106,8 @@
 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0;
 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6;  
 
+double f_beat_Sr_plus, f_beat_Sr_minus;
+
 double Step1=800000.0,Step2=800000.0;
 
 double Ch4Plus=0.0,Ch4Minus=0.0;
@@ -183,7 +185,7 @@
 	s->previous = value;
 }
 
-struct stat stat_math1, stat_ch2, stat_ch4, freq;
+struct stat stat_math1, stat_ch2, stat_ch4, stat_ch3, freq;
 
 #define MIN(x, y) (x) < (y) ? (x) : (y)
 
@@ -1035,6 +1037,9 @@
 						
 						t1_3 = utc;
 						stat_zero(&stat_ch2);
+						stat_zero(&stat_ch3);
+						f_beat_Sr_plus = 0.0;
+						f_beat_Sr_minus = 0.0;
 						
 						// record current DDS3 frequency
 						GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
@@ -1052,6 +1057,7 @@
 						}
 						
 						stat_accumulate(&stat_ch2, Ch2);
+						stat_accumulate(&stat_ch3, Ch3);
 						
 						if (utc - t1_3 > SlopeTime3) {
 							// slope measurement
@@ -1059,6 +1065,7 @@
 							
 							t2_3 = utc;
 							stat_zero(&stat_ch2);
+							stat_zero(&stat_ch3);
 							
 							// frep positive step
 							SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
@@ -1106,11 +1113,13 @@
 						}
 						
 						n_3++;
-						Frepplus_3 += Ch2 - Slope_3 * (utc - t2_3);
+						Frepplus_3 += Math1 + 250000000 - Slope_3 * (utc - t3_2);
+						f_beat_Sr_plus += Ch3;
 						
 						if (utc - t2_3 > DeltaT_3) {
 							// positive step measurement
 							Frepplus_3 = Frepplus_3 / n_3;
+							f_beat_Sr_plus = f_beat_Sr_plus / n_3;
 							
 							n_3 = 0;
 							t3_3 = utc;
@@ -1142,13 +1151,22 @@
 						
 						n_3++;
 						Frepminus_3 += Ch2 - Slope_3 * (utc - t3_3);
+						f_beat_Sr_minus += Ch3;
 						
 						if (utc - t3_3 > DeltaT_3) {
-							// positive step measurement
+							// negative step measurement
 							Frepminus_3 = Frepminus_3 / n_3;
+							f_beat_Sr_minus = f_beat_Sr_plus / n_3;
+							
+							// check delta frep
+							double delta_f_rep = Frepplus_3 - Frepplus_3;
+							double expected = N1 / Ndiv * 2.0 * DeltakHz_3 * 1000.0;
+							logmsg("delta frep=%g expected=%g", delta_f_rep, expected);
 							
 							// compute N3
-							N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000));
+							double delta_f_beat_Sr = f_beat_Sr_plus - f_beat_Sr_minus + 2.0 * N3/N1 * Ndiv * DeltakHz_3 * 1000;
+							logmsg("delta fbeat=%g", delta_f_beat_Sr);
+							N_3 = delta_f_beat_Sr / delta_f_rep;
 							SetCtrlVal(CalcNPanel, CALCN_N, N_3);
 							
 							t1_3=0.0;
@@ -1164,6 +1182,10 @@
 							// back to initial DDS3 frequency
 							SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init);
 							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
+							// adjust DDS frequency to keep 55 MHz tracker oscillator locked
+							double fDDS2 = DDS4xAD9912.Frequency2 + 275000 - Ch4;
+							SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2);
+							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2);
 							
 							// done
 							Measuring_3 = N_MEASUREMENT_NONE;