changeset 118:43b35f4aae78

Fix N3 measurement. Simply frequnecy ramping functions.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 12 Sep 2013 15:49:27 +0200
parents 96ab53ab9496
children f9fb17fb64cc
files DDS4xAD9912.c DDS4xAD9912.h FXAnalyse.c
diffstat 3 files changed, 71 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/DDS4xAD9912.c	Fri Jul 05 16:23:43 2013 +0200
+++ b/DDS4xAD9912.c	Thu Sep 12 15:49:27 2013 +0200
@@ -178,7 +178,7 @@
  * ramp DDS frequency from `f1` to `f2` in steps of `fstep` 
  * with a delay of 0.01 seoconds after each step
  */
-int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep)
+int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep)
 {
 	const double delay = 0.01;
 	
@@ -200,3 +200,32 @@
 	DDS4xAD9912_SetFrequency(dds, channel, f2);
 	return 0;
 }
+
+
+/* 
+ * ramp DDS frequency from the current frequency to `f2` in steps
+ * of `fstep` with a delay of 0.01 seoconds after each step
+ */
+int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep)
+{
+	double f1 = DDS4xAD9912_GetFrequency(dds, channel);
+	return DDS4xAD9912_RampFrequency2(dds, channel, f1, f2, fstep);
+}
+
+
+double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel)
+{
+	switch (channel) {
+		case 1:
+			return dds->Frequency1;
+		case 2:
+			return dds->Frequency2;
+		case 3:
+			return dds->Frequency3;
+		case 4:
+			return dds->Frequency4;
+		default:
+			return 0.0;
+	}
+}
+
--- a/DDS4xAD9912.h	Fri Jul 05 16:23:43 2013 +0200
+++ b/DDS4xAD9912.h	Thu Sep 12 15:49:27 2013 +0200
@@ -61,11 +61,11 @@
 //==============================================================================		
 // Functions
 
-
-static int DDS4xAD9912_SendCmd(int DDSNum,char *Buffer) ; // essentially a private function, hence the static scope... 
+double DDS4xAD9912_GetFrequency(DDS4xAD9912_Data *dds, int channel);
 int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq);
 int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance);
-int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep);
+int DDS4xAD9912_RampFrequency(DDS4xAD9912_Data *dds, int channel, double f2, double fstep);
+int DDS4xAD9912_RampFrequency2(DDS4xAD9912_Data *dds, int channel, double f1, double f2, double fstep);
 
 
 #ifdef __cplusplus
--- a/FXAnalyse.c	Fri Jul 05 16:23:43 2013 +0200
+++ b/FXAnalyse.c	Thu Sep 12 15:49:27 2013 +0200
@@ -104,11 +104,10 @@
 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0;
 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6;  
 
+double f_rep_slope;
 double f_rep_plus, f_rep_minus;
 double f_beat_Sr_plus, f_beat_Sr_minus;
 
-double Step1=800000.0,Step2=800000.0;
-
 double Ch4Plus=0.0,Ch4Minus=0.0;
 
 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0;
@@ -743,7 +742,7 @@
 							SetCtrlVal(CalcNPanel, CALCN_SLOPE, Slope_1);
 							
 							// frep positive step
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FrequDDS1 + DeltakHz_1 * 1000.0, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_1 * 1000.0, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 + DeltakHz_1 * 1000.0);
 							
 							// allow counter to settle
@@ -763,8 +762,7 @@
 							break;
 						}
 						
-						double fDDS2;
-						GetCtrlVal(MainPanel, PANEL_DDS2, &fDDS2);
+						double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2);
 						fDDS2 += 275000 - Ch4;
 						SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2);
 						DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2);
@@ -797,7 +795,7 @@
 							n_1 = 0;
 							
 							// frep negative step
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_1 * 1000.0, FrequDDS1 - DeltakHz_1 * 1000.0, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_1 * 1000.0, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 - DeltakHz_1 * 1000.0);  
 							
 							// allow counter to settle
@@ -839,7 +837,7 @@
 							Frepplus_1 = 0.0;
 							
 							// back to nominal frep
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_1 * 1000.0, FrequDDS1, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
 							SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);
 							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
@@ -890,7 +888,7 @@
 							// frep positive step
 							double fDDS1 = FrequDDS1 + DeltakHz_2 * 1000;
 							printf("fDDS1 = %g\n", fDDS1);
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, FrequDDS1, fDDS1, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, fDDS1);
 							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, fDDS1);
 							
@@ -956,7 +954,7 @@
 
 							// negative frequency step
 							double fDDS1 = FrequDDS1 - DeltakHz_2 * 1000;
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, DDS4xAD9912.Frequency1, fDDS1, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, fDDS1);
 							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, fDDS1);
 							
@@ -986,7 +984,7 @@
 							t3_1 = utc;
 
 						Frepminus_2 = Frepminus_2 + Math1 + 250000000 - Slope_2 * (utc - t3_2);
-						Delta10K_Minus=  Delta10K_Minus + 10000 - (Ch2 - Beatslope_2 * (utc - t3_2));
+						Delta10K_Minus =  Delta10K_Minus + 10000 - (Ch2 - Beatslope_2 * (utc - t3_2));
 						n_2 += 1;
 
 						if ((utc -t3_2) > DeltaT_2) {
@@ -999,11 +997,11 @@
 							SetCtrlVal(CalcNPanel, CALCN_N, N_2);
 							
 							// back to nominal frequency
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1-DeltakHz_2*1000,FrequDDS1, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE);
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
 							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
 							SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);  
-							DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit );
+							DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit);
 							SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2));
 							DDS4xAD9912_SetFrequency (&DDS4xAD9912, 3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2) );
 							
@@ -1035,13 +1033,13 @@
 						settling = 3;
 						
 						t1_3 = utc;
-						stat_zero(&stat_ch2);
-						stat_zero(&stat_ch3);
+						stat_zero(&stat_math1);
 						f_rep_plus = f_rep_minus = 0.0;
 						f_beat_Sr_plus = f_beat_Sr_minus = 0.0;
 						
-						// record current DDS3 frequency
-						GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
+						// record current DDS frequencies
+						FrequencyDDSBesInit = DDS4xAD9912.Frequency2;
+						FrequencyDDS3Init = DDS4xAD9912.Frequency3;
 						
 						// next step
 						Measuring_3 += 1;
@@ -1055,20 +1053,17 @@
 							break;
 						}
 						
-						stat_accumulate(&stat_ch2, Ch2);
-						stat_accumulate(&stat_ch3, Ch3);
+						stat_accumulate(&stat_math1, Math1);
 						
 						if (utc - t1_3 > SlopeTime3) {
 							// slope measurement
-							Slope_3 = stat_ch2.slope;
+							f_rep_slope = stat_math1.slope;
 							
 							t2_3 = utc;
-							stat_zero(&stat_ch2);
-							stat_zero(&stat_ch3);
 							
 							// frep positive step
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 + DeltakHz_3 * 1000);
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FrequDDS1 + DeltakHz_3 * 1000, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_3 * 1000, FREP_STEP_SIZE);
 							// compensate with DDS3 to keep measured beatnote in counter box range
 							double fDDS3 = FrequencyDDS3Init + Signe1 * Signe3 * N3/N1 * Ndiv * DeltakHz_3 * 1000;
 							SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
@@ -1112,7 +1107,7 @@
 						}
 						
 						n_3++;
-						f_rep_plus += Math1 + 250000000 - Slope_3 * (utc - t3_2);
+						f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t3_2);
 						f_beat_Sr_plus += Ch3;
 						
 						if (utc - t2_3 > DeltaT_3) {
@@ -1125,7 +1120,7 @@
 							
 							// frep negative step
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 - DeltakHz_3 * 1000);
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_3 * 1000, FrequDDS1 - DeltakHz_3 * 1000, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_3 * 1000, FREP_STEP_SIZE);
 							// compensate with DDS3 to keep measured beatnote in counter box range
 							double fDDS3 = FrequencyDDS3Init - Signe1 * Signe3 * N3/N1 * Ndiv * DeltakHz_3 * 1000;
 							SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
@@ -1138,8 +1133,7 @@
 							Measuring_3 += 1;
 						}
 						break;
-						
-						
+					
 					case N_MEASUREMENT_FREP_MINUS:
 						// frep negative step
 						
@@ -1149,23 +1143,29 @@
 						}
 						
 						n_3++;
-						f_rep_minus += Math1 + 250000000 - Slope_3 * (utc - t3_2);
+						f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t3_2);
 						f_beat_Sr_minus += Ch3;
 						
 						if (utc - t3_3 > DeltaT_3) {
 							// negative step measurement
 							f_rep_minus = f_rep_minus / n_3;
-							f_beat_Sr_minus = f_beat_Sr_plus / n_3;
+							f_beat_Sr_minus = f_beat_Sr_minus / n_3;
 							
 							// check delta frep
-							double delta_f_rep = f_rep_plus - f_rep_minus;
-							double expected = Ndiv * 2.0 * DeltakHz_3 * 1000.0 / N1;
-							logmsg("delta frep=%g Hz expected=%g Hz", delta_f_rep, expected);
+							double delta_f_rep_m = f_rep_plus - f_rep_minus;
+							double delta_f_rep = Ndiv * 2.0 * DeltakHz_3 * 1000.0 / N1;
+							logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e", 
+								delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep);
+							
+							logmsg("f_beat_Sr_minus=%.12e", f_beat_Sr_minus);
+							logmsg("f_beat_Sr_plus =%.12e", f_beat_Sr_plus);
 							
 							// compute N3
-							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);
+							double delta_f_beat_Sr = f_beat_Sr_plus - f_beat_Sr_minus + 2.0 * Signe1 * Signe3 * N3/N1 * Ndiv * DeltakHz_3 * 1000;
+							double delta_f_beat_Sr_expected = delta_f_rep * N3;
+							logmsg("delta fbeat: measured=%.12e expected=%.12e", delta_f_beat_Sr, delta_f_beat_Sr_expected);
 							N_3 = delta_f_beat_Sr / delta_f_rep;
+							logmsg("measured N3=%.3f", N_3);
 							SetCtrlVal(CalcNPanel, CALCN_N, N_3);
 							
 							t1_3=0.0;
@@ -1175,14 +1175,13 @@
 							
 							// back to nominal frep
 							SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
-							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_3 * 1000, FrequDDS1, FREP_STEP_SIZE);
+							DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE);
 							// 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);
+							// back to initial DDS2 frequency
+							SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);  
+							DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
 							
 							// done
 							Measuring_3 = N_MEASUREMENT_NONE;
@@ -2126,7 +2125,7 @@
 					// default wavelenght for Sr cavity
 					GetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, &wl);
 					if (wl == 0.0)
-						SetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, 698.50);
+						SetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, 698.446);
 					// reset N3 estimate
 					SetCtrlVal(EstimateN3Panel, ESTIMATEN3_N, 0.0);
 					break;