diff FXAnalyse.c @ 25:fde495ba28d2

Correct DDS3 frequency adjustement on N3 measurement. Cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 02 Oct 2012 12:23:31 +0200
parents b838371c7a91
children 4bb197635664
line wrap: on
line diff
--- a/FXAnalyse.c	Fri Jul 20 17:38:15 2012 +0200
+++ b/FXAnalyse.c	Tue Oct 02 12:23:31 2012 +0200
@@ -44,8 +44,8 @@
 //==============================================================================
 // Global variables
 
-char * LogFileName ;
-char ExtraMathFileName[MAX_PATHNAME_LEN] ;
+char LogFileName[MAX_PATHNAME_LEN];
+char ExtraMathFileName[MAX_PATHNAME_LEN];
 
 double utc = 0;
 double mjd = 0;
@@ -151,6 +151,7 @@
 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0;
 
 double LimitToDelock=5.0;
+double SlopeCorrection=0.0;
 double limitotakoff=70.0;
 
 int ratio=10; //Recentre la frequence tous les ratios
@@ -232,7 +233,6 @@
 {
 	//int ThreadId ;   // to be used when I will replace timer by thread for counder readout
 	
-	char FileNamePrototype[MAX_PATHNAME_LEN] ;  
 	double initfreqDDS ;
 	char * MathString1 = "                                                             " ;
 	char * MathString2 = "                                                             " ;
@@ -255,10 +255,6 @@
 	
 	DisplayPanel (MainPanel);
 	
-		// Initialize LogFileName pointer
-	
-	LogFileName = FileNamePrototype ;
-	
 	// Initialyze the DDS Besancon Output
 	
 	DDSBes_Initialize(&DDSBes) ;
@@ -509,18 +505,16 @@
 	return 0;
 }
 
-void FindCurrentFileName(void)
+
+void CurrentFileName(char *fname)
 {
-	char * date, day[3], month[3], year[3];	    // DD ; MM ; 20YY plus one space for NULL termination character
-	
-	date = DateStr();
-	Scan(date, "%s>%s[w2]-%s[w2]-20%s[w2]", month, day, year);	   
-	Fmt(LogFileName, "%s<%s\\%s%s%s_Frequ.txt", LOGFILEPATH, year, month, day);		 
-	return ;
+	char day[3], month[3], year[3];
+	char *date = DateStr();
+	Scan(date, "%s>%s[w2]-%s[w2]-20%s[w2]", month, day, year);
+	Fmt(fname, "%s<%s\\%s%s%s_Frequ.txt", LOGFILEPATH, year, month, day);
 }
 
 
-
 int CVICALLBACK CB_OnStart (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
@@ -550,7 +544,7 @@
 			Acquiring = TRUE;
 			SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_LABEL_TEXT, "__RESET"); 
 			
-			FindCurrentFileName(); // LogFileName is the one corresponding to the date of today...
+			CurrentFileName(LogFileName);
 			GetFileInfo(LogFileName, &OldLogFilePtr);
 			OldLogFilePtr -= OldLogFilePtr%FXLINELENGTH + FXLINELENGTH - 2;
 			break;
@@ -686,8 +680,6 @@
 						SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1) ;
 						SetCtrlVal(CalcN2Panel, CALCN2_N, N_2) ;
 						SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ;
-						SetCtrlVal(CalcN3Panel, CALCN3_N, N_3) ;
-						SetCtrlVal(CalcN3Panel, CALCN3_SLOPE, Slope_3) ;
 						SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
 						SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);  
 						SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring); 	   
@@ -1205,7 +1197,7 @@
 									SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
 									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000);
 									// compensate with DDS3 to keep measured beatnote in counter box range
-									double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3;
+									double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3 * 1000;
 									SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
 									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
 									// allow counter to settle
@@ -1237,7 +1229,7 @@
 									SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000);
 									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000);
 									// compensate with DDS3 to keep measured beatnote in counter box range
-									double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3;
+									double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3 * 1000;
 									SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
 									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
 									// allow counter to settle
@@ -1261,7 +1253,7 @@
 									Frepminus_3 = Frepminus_3 / n_3;
 									
 									// compute N3
-									N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3);
+									N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000));
 									SetCtrlVal(CalcN3Panel, CALCN3_N, N_3);
 									
 									t1_3=0.0;
@@ -1277,6 +1269,9 @@
 									// back to nominal frep
 									SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
 									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
+									// back to initial DDS3 frequency
+									SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init);
+									DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
 								}
 								break;
 						}
@@ -1532,13 +1527,12 @@
 							Acquiring = FALSE ;
 							do {
 								Delay(5.1);
-								FindCurrentFileName() ;
-								}
-							while (!GetFileInfo(LogFileName, &OldLogFilePtr)) ;
+								CurrentFileName(LogFileName) ;
+							} while (!GetFileInfo(LogFileName, &OldLogFilePtr));
 							printf("new file : %s \r\n\r\n",Date, Time, LogFileName);  
 							Acquiring = TRUE ;
 							OldLogFilePtr = 2;
-							}
+						}
 						
 						ResumeTimerCallbacks() ;