comparison 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
comparison
equal deleted inserted replaced
24:b838371c7a91 25:fde495ba28d2
42 //static int CVICALLBACK ReadCounterThread(void *functionData); // to be used when I will replace timer by thread for counder readout 42 //static int CVICALLBACK ReadCounterThread(void *functionData); // to be used when I will replace timer by thread for counder readout
43 43
44 //============================================================================== 44 //==============================================================================
45 // Global variables 45 // Global variables
46 46
47 char * LogFileName ; 47 char LogFileName[MAX_PATHNAME_LEN];
48 char ExtraMathFileName[MAX_PATHNAME_LEN] ; 48 char ExtraMathFileName[MAX_PATHNAME_LEN];
49 49
50 double utc = 0; 50 double utc = 0;
51 double mjd = 0; 51 double mjd = 0;
52 52
53 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!! 53 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!!
149 149
150 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; 150 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0;
151 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0; 151 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0;
152 152
153 double LimitToDelock=5.0; 153 double LimitToDelock=5.0;
154 double SlopeCorrection=0.0;
154 double limitotakoff=70.0; 155 double limitotakoff=70.0;
155 156
156 int ratio=10; //Recentre la frequence tous les ratios 157 int ratio=10; //Recentre la frequence tous les ratios
157 158
158 volatile bool FrequCorrec=FALSE,KeepFrequ=TRUE, KeepSlope=TRUE ; 159 volatile bool FrequCorrec=FALSE,KeepFrequ=TRUE, KeepSlope=TRUE ;
230 231
231 int main (int argc, char *argv[]) 232 int main (int argc, char *argv[])
232 { 233 {
233 //int ThreadId ; // to be used when I will replace timer by thread for counder readout 234 //int ThreadId ; // to be used when I will replace timer by thread for counder readout
234 235
235 char FileNamePrototype[MAX_PATHNAME_LEN] ;
236 double initfreqDDS ; 236 double initfreqDDS ;
237 char * MathString1 = " " ; 237 char * MathString1 = " " ;
238 char * MathString2 = " " ; 238 char * MathString2 = " " ;
239 char * MathString3 = " " ; 239 char * MathString3 = " " ;
240 char * MathString4 = " " ; 240 char * MathString4 = " " ;
252 return -1; 252 return -1;
253 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0) 253 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0)
254 return -1; 254 return -1;
255 255
256 DisplayPanel (MainPanel); 256 DisplayPanel (MainPanel);
257
258 // Initialize LogFileName pointer
259
260 LogFileName = FileNamePrototype ;
261 257
262 // Initialyze the DDS Besancon Output 258 // Initialyze the DDS Besancon Output
263 259
264 DDSBes_Initialize(&DDSBes) ; 260 DDSBes_Initialize(&DDSBes) ;
265 DDSBes_SetClockFrequency(&DDSBes, DDSBESCLOCK) ; // Peut etre passer tout ca dans DDSBes-Initialize ? 261 DDSBes_SetClockFrequency(&DDSBes, DDSBESCLOCK) ; // Peut etre passer tout ca dans DDSBes-Initialize ?
507 503
508 } 504 }
509 return 0; 505 return 0;
510 } 506 }
511 507
512 void FindCurrentFileName(void) 508
513 { 509 void CurrentFileName(char *fname)
514 char * date, day[3], month[3], year[3]; // DD ; MM ; 20YY plus one space for NULL termination character 510 {
515 511 char day[3], month[3], year[3];
516 date = DateStr(); 512 char *date = DateStr();
517 Scan(date, "%s>%s[w2]-%s[w2]-20%s[w2]", month, day, year); 513 Scan(date, "%s>%s[w2]-%s[w2]-20%s[w2]", month, day, year);
518 Fmt(LogFileName, "%s<%s\\%s%s%s_Frequ.txt", LOGFILEPATH, year, month, day); 514 Fmt(fname, "%s<%s\\%s%s%s_Frequ.txt", LOGFILEPATH, year, month, day);
519 return ; 515 }
520 }
521
522 516
523 517
524 int CVICALLBACK CB_OnStart (int panel, int control, int event, 518 int CVICALLBACK CB_OnStart (int panel, int control, int event,
525 void *callbackData, int eventData1, int eventData2) 519 void *callbackData, int eventData1, int eventData2)
526 { 520 {
548 Allan_Reset(&AllanMath5); 542 Allan_Reset(&AllanMath5);
549 } 543 }
550 Acquiring = TRUE; 544 Acquiring = TRUE;
551 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_LABEL_TEXT, "__RESET"); 545 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_LABEL_TEXT, "__RESET");
552 546
553 FindCurrentFileName(); // LogFileName is the one corresponding to the date of today... 547 CurrentFileName(LogFileName);
554 GetFileInfo(LogFileName, &OldLogFilePtr); 548 GetFileInfo(LogFileName, &OldLogFilePtr);
555 OldLogFilePtr -= OldLogFilePtr%FXLINELENGTH + FXLINELENGTH - 2; 549 OldLogFilePtr -= OldLogFilePtr%FXLINELENGTH + FXLINELENGTH - 2;
556 break; 550 break;
557 } 551 }
558 return 0; 552 return 0;
684 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3); 678 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3);
685 SetCtrlVal(CalcN1Panel, CALCN1_N, N_1) ; 679 SetCtrlVal(CalcN1Panel, CALCN1_N, N_1) ;
686 SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1) ; 680 SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1) ;
687 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2) ; 681 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2) ;
688 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ; 682 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ;
689 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3) ;
690 SetCtrlVal(CalcN3Panel, CALCN3_SLOPE, Slope_3) ;
691 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2); 683 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
692 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2); 684 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
693 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring); 685 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring);
694 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling); 686 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling);
695 // Treat data 687 // Treat data
1203 1195
1204 // frep positive step 1196 // frep positive step
1205 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000); 1197 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
1206 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000); 1198 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000);
1207 // compensate with DDS3 to keep measured beatnote in counter box range 1199 // compensate with DDS3 to keep measured beatnote in counter box range
1208 double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3; 1200 double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3 * 1000;
1209 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); 1201 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1210 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 1202 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1211 // allow counter to settle 1203 // allow counter to settle
1212 settling = 3; 1204 settling = 3;
1213 } 1205 }
1235 1227
1236 // frep negative step 1228 // frep negative step
1237 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000); 1229 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000);
1238 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000); 1230 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000);
1239 // compensate with DDS3 to keep measured beatnote in counter box range 1231 // compensate with DDS3 to keep measured beatnote in counter box range
1240 double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3; 1232 double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3 * 1000;
1241 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); 1233 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1242 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 1234 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1243 // allow counter to settle 1235 // allow counter to settle
1244 settling = 3; 1236 settling = 3;
1245 } 1237 }
1259 if (utc - t3_3 > DeltaT_3) { 1251 if (utc - t3_3 > DeltaT_3) {
1260 // positive step measurement 1252 // positive step measurement
1261 Frepminus_3 = Frepminus_3 / n_3; 1253 Frepminus_3 = Frepminus_3 / n_3;
1262 1254
1263 // compute N3 1255 // compute N3
1264 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3); 1256 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000));
1265 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3); 1257 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3);
1266 1258
1267 t1_3=0.0; 1259 t1_3=0.0;
1268 t2_3=0.0; 1260 t2_3=0.0;
1269 t3_3=0.0; 1261 t3_3=0.0;
1275 Measuring_3 = N_MEASUREMENT_STEP_0; 1267 Measuring_3 = N_MEASUREMENT_STEP_0;
1276 1268
1277 // back to nominal frep 1269 // back to nominal frep
1278 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4); 1270 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1279 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4); 1271 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1272 // back to initial DDS3 frequency
1273 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init);
1274 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
1280 } 1275 }
1281 break; 1276 break;
1282 } 1277 }
1283 1278
1284 // Calcul du signe de fb 1279 // Calcul du signe de fb
1530 printf("Entering change of date substructure\r\n"); 1525 printf("Entering change of date substructure\r\n");
1531 printf("old file : %s %s %s \r\n",Date, Time, LogFileName); 1526 printf("old file : %s %s %s \r\n",Date, Time, LogFileName);
1532 Acquiring = FALSE ; 1527 Acquiring = FALSE ;
1533 do { 1528 do {
1534 Delay(5.1); 1529 Delay(5.1);
1535 FindCurrentFileName() ; 1530 CurrentFileName(LogFileName) ;
1536 } 1531 } while (!GetFileInfo(LogFileName, &OldLogFilePtr));
1537 while (!GetFileInfo(LogFileName, &OldLogFilePtr)) ;
1538 printf("new file : %s \r\n\r\n",Date, Time, LogFileName); 1532 printf("new file : %s \r\n\r\n",Date, Time, LogFileName);
1539 Acquiring = TRUE ; 1533 Acquiring = TRUE ;
1540 OldLogFilePtr = 2; 1534 OldLogFilePtr = 2;
1541 } 1535 }
1542 1536
1543 ResumeTimerCallbacks() ; 1537 ResumeTimerCallbacks() ;
1544 1538
1545 } ; 1539 } ;
1546 1540