Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 29:585c60175bd5
Cleanup AD9956 DDS parameters setting code
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 02 Oct 2012 18:55:48 +0200 |
parents | 1e4ecf64b485 |
children | 56095062acd4 |
comparison
equal
deleted
inserted
replaced
28:1e4ecf64b485 | 29:585c60175bd5 |
---|---|
13 #include "DDSBes.h" | 13 #include "DDSBes.h" |
14 #include "DDS4xAD9912.h" | 14 #include "DDS4xAD9912.h" |
15 #include "DDS_Fox.h" | 15 #include "DDS_Fox.h" |
16 #include "muParserDLL.h" | 16 #include "muParserDLL.h" |
17 | 17 |
18 | |
19 #define FXLINELENGTH 123 | 18 #define FXLINELENGTH 123 |
20 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" | 19 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" |
21 | 20 |
22 #define DDSBESCLOCK (200.e6) // 200MHz de clock pour la DDS de Besancon... | 21 #define DEDRIFT_DDS_FREQUENCY 70000000 |
23 #define FACTORDDSBES 36*(8/770000) | |
24 | 22 |
25 //============================================================================== | 23 //============================================================================== |
26 // Static global variables | 24 // Static global variables |
27 | 25 |
28 /* multi threading stuff */ // to be used when I will replace timer by thread for counder readout | 26 /* multi threading stuff */ // to be used when I will replace timer by thread for counder readout |
55 double N1, N2, N3, N4 ; | 53 double N1, N2, N3, N4 ; |
56 | 54 |
57 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ; | 55 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ; |
58 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ; | 56 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ; |
59 | 57 |
60 DDS4xAD9912_Data DDS4xAD9912 ; | 58 // 1xAD9956 DDS box |
59 DDSParameter DDS1xAD9956; | |
60 // 4xAD9912 DDS box | |
61 DDS4xAD9912_Data DDS4xAD9912; | |
61 | 62 |
62 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5 ; | 63 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5 ; |
63 | 64 |
64 volatile bool Acquiring = FALSE ; | 65 volatile bool Acquiring = FALSE ; |
65 | 66 |
143 volatile bool OnSlopeCancelling =FALSE; | 144 volatile bool OnSlopeCancelling =FALSE; |
144 double SlopeMath2=0.0; | 145 double SlopeMath2=0.0; |
145 double TimetoSlope=60.0; | 146 double TimetoSlope=60.0; |
146 double SlopeMeasuringTimeBegin=0.0; | 147 double SlopeMeasuringTimeBegin=0.0; |
147 | 148 |
148 char DDSFoxName[255] = "DDS Fox Control" ; | |
149 double DDSFoxClock=200000000; | |
150 int DDSFoxSweepSign=0; | |
151 double DDSFoxFrequency=70000000.0; | |
152 char DDSFoxip[255]="145.238.205.58"; | |
153 int DDSFoxPort=6665 ; | |
154 unsigned int DDSFoxProfil=7; | |
155 double DDSFoxSweeprate=0.0;// numéro de profil de la DDS : single freq=0, sweep=7 ; | |
156 double DDSFoxDeltaT=0.01; | |
157 | |
158 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; | 149 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0; |
159 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0; | 150 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0; |
160 | 151 |
161 double LimitToDelock=5.0; | 152 double LimitToDelock=5.0; |
162 double SlopeCorrection=0.0; | 153 double SlopeCorrection=0.0; |
186 double Timetorecenter10K=3600.0*3; | 177 double Timetorecenter10K=3600.0*3; |
187 double CenteringTimeBegin275K=0.0; | 178 double CenteringTimeBegin275K=0.0; |
188 double CenteringTimeBegin10K=0.0; | 179 double CenteringTimeBegin10K=0.0; |
189 | 180 |
190 | 181 |
191 | 182 int DDSFox_Set(DDSParameter *DDS, double Frequency, double Sweeprate) |
192 //============================================================================== | 183 { |
193 // Functions | 184 DDS->Frequency = Frequency; |
194 int LaunchDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate,int mode) ; | 185 DDS->SweepRate = Sweeprate; |
195 double ReadDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate) ; | 186 |
196 | 187 DDSFox_SetFreq(DDS); |
197 | 188 DDSFox_SetDf(DDS); |
198 | 189 |
199 | 190 return 0; |
191 } | |
192 | |
200 | 193 |
201 void initMathParser(muParserHandle_t * pMathParser) | 194 void initMathParser(muParserHandle_t * pMathParser) |
202 { | 195 { |
203 (* pMathParser) = mupCreate() ; // Math parser number 1, normally used for frep | 196 (* pMathParser) = mupCreate() ; // Math parser number 1, normally used for frep |
204 mupDefineOprtChars( * pMathParser, "abcdefghijklmnopqrstuvwxyzµ" | 197 mupDefineOprtChars( * pMathParser, "abcdefghijklmnopqrstuvwxyzµ" |
260 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0) | 253 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0) |
261 return -1; | 254 return -1; |
262 | 255 |
263 DisplayPanel (MainPanel); | 256 DisplayPanel (MainPanel); |
264 | 257 |
265 // Initialize the quadruple AD9959 DDS (Fox board interface) | 258 // initialize 4x AD9959 DDS box |
266 | |
267 DDS4xAD9912_Reset(&DDS4xAD9912) ; | 259 DDS4xAD9912_Reset(&DDS4xAD9912) ; |
268 GetCtrlVal(MainPanel, PANEL_DDS1, &initfreqDDS) ; | 260 GetCtrlVal(MainPanel, PANEL_DDS1, &initfreqDDS) ; |
269 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, initfreqDDS) ; | 261 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, initfreqDDS) ; |
270 GetCtrlVal(MainPanel, PANEL_DDS2, &initfreqDDS) ; | 262 GetCtrlVal(MainPanel, PANEL_DDS2, &initfreqDDS) ; |
271 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, initfreqDDS) ; | 263 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, initfreqDDS) ; |
273 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, initfreqDDS) ; | 265 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, initfreqDDS) ; |
274 GetCtrlVal(MainPanel, PANEL_DDS4, &initfreqDDS) ; | 266 GetCtrlVal(MainPanel, PANEL_DDS4, &initfreqDDS) ; |
275 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, initfreqDDS) ; | 267 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, initfreqDDS) ; |
276 | 268 |
277 | 269 |
278 // Initialyze the DDSFOX Output | 270 // initialyze 1x AD9956 DDS box |
279 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate,1); | 271 strcpy(DDS1xAD9956.ip, "145.238.205.58"); |
272 DDS1xAD9956.Port = 6665; | |
273 DDS1xAD9956.Profil = 7; // configuration profile: single freq=0, sweep=7 | |
274 DDS1xAD9956.Clock = 200000000; | |
275 DDS1xAD9956.Frequency = DEDRIFT_DDS_FREQUENCY; | |
276 DDS1xAD9956.Delta_T = 0.01; | |
277 DDS1xAD9956.SweepRate = 0.0; | |
278 DDS_Initialize(&DDS1xAD9956); | |
280 | 279 |
281 // Initialize the 5 (separate) math parsers for frep, Nu_Hg, Nu_Sr, N3 and ExtraMath | 280 // Initialize the 5 (separate) math parsers for frep, Nu_Hg, Nu_Sr, N3 and ExtraMath |
282 | 281 |
283 Ch1=0.0 ; Ch2=0.0 ; Ch3=0.0 ; Ch4=0.0 ; | 282 Ch1=0.0 ; Ch2=0.0 ; Ch3=0.0 ; Ch4=0.0 ; |
284 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1) ; | 283 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1) ; |
1324 CenterFrequencyCh2 = MoyMath2; | 1323 CenterFrequencyCh2 = MoyMath2; |
1325 CenterFrequencyCh2ToDetermine = FALSE; | 1324 CenterFrequencyCh2ToDetermine = FALSE; |
1326 } | 1325 } |
1327 | 1326 |
1328 OnSlopeCancelling = TRUE; | 1327 OnSlopeCancelling = TRUE; |
1329 | 1328 |
1330 FoxFrequ = ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); | 1329 FoxFrequ = DDSFox_ReadFreq(&DDS1xAD9956); |
1331 | 1330 |
1332 if (Nratio == ratio) | 1331 if (Nratio == ratio) |
1333 { | 1332 { |
1334 if (FrequCorrec == TRUE) | 1333 if (FrequCorrec == TRUE) |
1335 { | 1334 { |
1338 } | 1337 } |
1339 Nratio = 0; | 1338 Nratio = 0; |
1340 MoyMath2 = 0.0; | 1339 MoyMath2 = 0.0; |
1341 } | 1340 } |
1342 | 1341 |
1343 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,FoxFrequ,SlopeMath2,0); | 1342 DDSFox_Set(&DDS1xAD9956, FoxFrequ, SlopeMath2); |
1344 | 1343 |
1345 nstabilisationSlopeMeasuring = 0; | 1344 nstabilisationSlopeMeasuring = 0; |
1346 SlopeMeasuringTimeBegin = utc; | 1345 SlopeMeasuringTimeBegin = utc; |
1347 | 1346 |
1348 } | 1347 } |
1371 * stop slope cancelling if the comb is not locked | 1370 * stop slope cancelling if the comb is not locked |
1372 */ | 1371 */ |
1373 | 1372 |
1374 if (KeepFrequ == TRUE) | 1373 if (KeepFrequ == TRUE) |
1375 { | 1374 { |
1376 ActualFrequ = ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); | 1375 ActualFrequ = DDSFox_ReadFreq(&DDS1xAD9956); |
1377 } | 1376 } |
1378 else | 1377 else |
1379 { | 1378 { |
1380 ActualFrequ = DDSFoxFrequency; | 1379 ActualFrequ = DEDRIFT_DDS_FREQUENCY; |
1381 } | 1380 } |
1382 | 1381 |
1383 if (KeepSlope == TRUE) | 1382 if (KeepSlope == TRUE) |
1384 { | 1383 { |
1385 ActualSlope = SlopeMath2; | 1384 ActualSlope = SlopeMath2; |
1386 } | 1385 } |
1387 else | 1386 else |
1388 { | 1387 { |
1389 ActualSlope = DDSFoxSweeprate; | 1388 ActualSlope = 0.0; |
1390 OnSlopeCancelling = FALSE; | 1389 OnSlopeCancelling = FALSE; |
1391 } | 1390 } |
1392 | 1391 |
1393 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0); | 1392 DDSFox_Set(&DDS1xAD9956, ActualFrequ, ActualSlope); |
1394 | 1393 |
1395 SlopeMeasuring = FALSE; | 1394 SlopeMeasuring = FALSE; |
1396 N_Math2slope = 0.0; | 1395 N_Math2slope = 0.0; |
1397 Math2_slope = 0.0; | 1396 Math2_slope = 0.0; |
1398 MoyMath2 = 0.0; | 1397 MoyMath2 = 0.0; |
2384 | 2383 |
2385 if (buttonstatu==1) | 2384 if (buttonstatu==1) |
2386 { | 2385 { |
2387 SlopeMeasuringTimeBegin=utc; | 2386 SlopeMeasuringTimeBegin=utc; |
2388 SlopeMeasuring=TRUE; | 2387 SlopeMeasuring=TRUE; |
2389 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); | 2388 ActualFrequ=DDSFox_ReadFreq(&DDS1xAD9956); |
2390 ActualSlope= SlopeMath2; | 2389 ActualSlope= SlopeMath2; |
2391 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0); | 2390 DDSFox_Set(&DDS1xAD9956, ActualFrequ, ActualSlope); |
2392 Nratio=-1; | 2391 Nratio=-1; |
2393 CenterFrequencyCh2ToDetermine=TRUE ; | 2392 CenterFrequencyCh2ToDetermine=TRUE ; |
2394 CenterFrequencyCh2=0.0; | 2393 CenterFrequencyCh2=0.0; |
2395 | 2394 |
2396 } | 2395 } |
2397 else | 2396 else |
2398 { | 2397 { |
2399 if (KeepFrequ==TRUE) {ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);} | 2398 if (KeepFrequ==TRUE) {ActualFrequ=DDSFox_ReadFreq(&DDS1xAD9956);} |
2400 else { ActualFrequ= DDSFoxFrequency;} | 2399 else { ActualFrequ= DEDRIFT_DDS_FREQUENCY;} |
2401 if (KeepSlope==TRUE) {ActualSlope= SlopeMath2; | 2400 if (KeepSlope==TRUE) {ActualSlope= SlopeMath2; |
2402 OnSlopeCancelling =TRUE; } | 2401 OnSlopeCancelling =TRUE; } |
2403 else { ActualSlope= DDSFoxSweeprate; | 2402 else { ActualSlope= 0.0; |
2404 OnSlopeCancelling =FALSE; } | 2403 OnSlopeCancelling =FALSE; } |
2405 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0); | 2404 DDSFox_Set(&DDS1xAD9956, ActualFrequ, ActualSlope); |
2406 SlopeMeasuring=FALSE; | 2405 SlopeMeasuring=FALSE; |
2407 N_Math2slope=0.0; | 2406 N_Math2slope=0.0; |
2408 Math2_slope=0.0; | 2407 Math2_slope=0.0; |
2409 Moy_Math2slope=0.0; | 2408 Moy_Math2slope=0.0; |
2410 Slope_Math2slope=0.0; | 2409 Slope_Math2slope=0.0; |
2433 CenterFrequencyCh2 = 0.0; | 2432 CenterFrequencyCh2 = 0.0; |
2434 MoyMath2 = 0.0; | 2433 MoyMath2 = 0.0; |
2435 Nratio = -1; | 2434 Nratio = -1; |
2436 CenterFrequencyCh2ToDetermine = TRUE ; | 2435 CenterFrequencyCh2ToDetermine = TRUE ; |
2437 OnSlopeCancelling = FALSE; | 2436 OnSlopeCancelling = FALSE; |
2438 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate,0); | 2437 DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, 0.0); |
2439 break; | 2438 break; |
2440 } | 2439 } |
2441 return 0; | 2440 return 0; |
2442 } | 2441 } |
2443 | 2442 |
2450 case EVENT_COMMIT: | 2449 case EVENT_COMMIT: |
2451 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &TimetoSlope); | 2450 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &TimetoSlope); |
2452 break; | 2451 break; |
2453 } | 2452 } |
2454 return 0; | 2453 return 0; |
2455 } | |
2456 | |
2457 | |
2458 int LaunchDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate,int mode) | |
2459 { | |
2460 //mode =0 pour normal | |
2461 //mode =1 pour reset | |
2462 | |
2463 DDSParameter DDSState; | |
2464 | |
2465 strcpy(DDSState.Name, Name); | |
2466 DDSState.Profil = Profil; | |
2467 strcpy(DDSState.ip, ip); | |
2468 DDSState.Port = Port; | |
2469 DDSState.Clock = Clock; | |
2470 DDSState.Delta_T = DeltaT; | |
2471 DDSState.Frequency = Frequency; | |
2472 DDSState.SweepRate = Sweeprate; | |
2473 | |
2474 if (mode == 1) { | |
2475 DDS_Initialize (&DDSState); | |
2476 } else { | |
2477 DDS_ReInitialize (&DDSState); | |
2478 } | |
2479 | |
2480 return 0; | |
2481 } | |
2482 | |
2483 double ReadDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate) | |
2484 { | |
2485 | |
2486 DDSParameter DDSState; | |
2487 | |
2488 strcpy(DDSState.Name, Name); | |
2489 DDSState.Profil = Profil; | |
2490 strcpy(DDSState.ip, ip); | |
2491 DDSState.Port = Port; | |
2492 DDSState.Clock = Clock; | |
2493 DDSState.Delta_T = DeltaT; | |
2494 DDSState.Frequency = Frequency; | |
2495 DDSState.SweepRate = Sweeprate; | |
2496 | |
2497 return DDSFox_ReadFreq(&DDSState); | |
2498 } | 2454 } |
2499 | 2455 |
2500 | 2456 |
2501 int CVICALLBACK CB_OnCROX (int panel, int control, int event, | 2457 int CVICALLBACK CB_OnCROX (int panel, int control, int event, |
2502 void *callbackData, int eventData1, int eventData2) | 2458 void *callbackData, int eventData1, int eventData2) |
2534 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &BoxChecked) ; | 2490 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &BoxChecked) ; |
2535 if (BoxChecked) { | 2491 if (BoxChecked) { |
2536 KeepSlope=TRUE ; | 2492 KeepSlope=TRUE ; |
2537 if (SlopeMeasuring==FALSE && OnSlopeCancelling==FALSE) | 2493 if (SlopeMeasuring==FALSE && OnSlopeCancelling==FALSE) |
2538 { | 2494 { |
2539 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); | 2495 ActualFrequ = DDSFox_ReadFreq(&DDS1xAD9956); |
2540 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,SlopeMath2,0); | 2496 DDSFox_Set(&DDS1xAD9956, ActualFrequ, SlopeMath2); |
2541 OnSlopeCancelling=TRUE; | 2497 OnSlopeCancelling=TRUE; |
2542 | 2498 |
2543 | 2499 |
2544 } | 2500 } |
2545 } | 2501 } |
2546 else {KeepSlope=FALSE ; | 2502 else {KeepSlope=FALSE ; |
2547 if (SlopeMeasuring==FALSE && OnSlopeCancelling==TRUE) | 2503 if (SlopeMeasuring==FALSE && OnSlopeCancelling==TRUE) |
2548 { | 2504 { |
2549 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate); | 2505 ActualFrequ=DDSFox_ReadFreq(&DDS1xAD9956); |
2550 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,DDSFoxSweeprate,0); | 2506 DDSFox_Set(&DDS1xAD9956, ActualFrequ, 0.0); |
2551 OnSlopeCancelling=FALSE; | 2507 OnSlopeCancelling=FALSE; |
2552 } | 2508 } |
2553 | 2509 |
2554 } | 2510 } |
2555 | 2511 |