comparison FXAnalyse.c @ 196:87dae6d62a61

New AD9912 client code to communicate with improved server code
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 31 Mar 2014 17:03:32 +0200
parents a5c70eae1e0b
children 5cac684eb12e
comparison
equal deleted inserted replaced
195:d841dfb30b0b 196:87dae6d62a61
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "FXAnalyse.h" 11 #include "FXAnalyse.h"
12 #include "Plot.h" 12 #include "Plot.h"
13 #include "Allan.h" 13 #include "Allan.h"
14 #include "DDS4xAD9912.h" 14 #include "ad9912.h"
15 #include "DDS_Fox.h" 15 #include "DDS_Fox.h"
16 #include "muParserDLL.h" 16 #include "muParserDLL.h"
17 #include "utils.h" 17 #include "utils.h"
18 #include "stat.h" 18 #include "stat.h"
19 #include "future.h" 19 #include "future.h"
25 25
26 #define FREP_STEP_SIZE 50000.0 26 #define FREP_STEP_SIZE 50000.0
27 #define SPEED_OF_LIGHT 299792458.0 // m/s 27 #define SPEED_OF_LIGHT 299792458.0 // m/s
28 #define SR_WAVELENGTH 698.4460 // nm 28 #define SR_WAVELENGTH 698.4460 // nm
29 #define HG_WAVELENGTH 1062.4000 // nm 29 #define HG_WAVELENGTH 1062.4000 // nm
30
30 31
31 // select which data provider to use 32 // select which data provider to use
32 #ifdef NDEBUG 33 #ifdef NDEBUG
33 #define DataProvider KKDataProvider 34 #define DataProvider KKDataProvider
34 #else 35 #else
159 PLOT(Math5, 0.0, 0.0), 160 PLOT(Math5, 0.0, 0.0),
160 { NULL } 161 { NULL }
161 }; 162 };
162 163
163 164
164 // dedrift DDS 165 struct ad9956 ad9956;
165 DDSParameter DDS1xAD9956; 166 struct ad9912 ad9912;
166 // 4xAD9912 DDS box 167
167 DDS4xAD9912_Data DDS4xAD9912; 168
169 static inline int ad9912_set_frequency_w(struct ad9912 *d, unsigned c, double f)
170 {
171 int r = ad9912_set_frequency(d, c, f);
172 if (r)
173 logmessage(ERROR, "ad9912 set frequency channel=%d error=%d", c, -r);
174 return r;
175 }
176
177
178 static inline int ad9912_ramp_frequency_w(struct ad9912 *d, unsigned c, double f, double s)
179 {
180 int r = ad9912_ramp_frequency(d, c, f, s);
181 if (r)
182 logmessage(ERROR, "ad9912 ramp frequency channel=%d error=%d", c, -r);
183 return r;
184 }
168 185
169 186
170 enum { 187 enum {
171 LO = 1, 188 LO = 1,
172 HG = 2, 189 HG = 2,
190 int nobs = 0; 207 int nobs = 0;
191 int settling = 0; 208 int settling = 0;
192 209
193 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3, df_DDS3; 210 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3, df_DDS3;
194 211
195 double SlopeTime1=40.0, DeltaT_1=20.0, delta_f_lock_1=500.0; 212 double SlopeTime1 = 40.0, DeltaT_1 = 40.0, delta_f_lock_1 = 500e3;
196 double SlopeTime2=40.0, DeltaT_2=20.0, delta_f_lock_2=500.0; 213 double SlopeTime2 = 40.0, DeltaT_2 = 40.0, delta_f_lock_2 = 500e3;
197 double SlopeTime3=40.0, DeltaT_3=20.0, delta_f_lock_3=500.0; 214 double SlopeTime3 = 40.0, DeltaT_3 = 40.0, delta_f_lock_3 = 500e3;
198 215
199 double t1, t2, t3; 216 double t1, t2, t3;
200 double f_rep_slope, f_beat_slope; 217 double f_rep_slope, f_beat_slope;
201 double f_rep_plus, f_rep_minus; 218 double f_rep_plus, f_rep_minus;
202 double f_beat_plus, f_beat_minus; 219 double f_beat_plus, f_beat_minus;
282 { \ 299 { \
283 .name = __name, \ 300 .name = __name, \
284 .data = __data, \ 301 .data = __data, \
285 .nchan = __nchan, \ 302 .nchan = __nchan, \
286 .control = __control, \ 303 .control = __control, \
287 .write = __write \ 304 .write = __write, \
288 } 305 }
289 306
290 struct datafile datafiles[] = { 307 struct datafile datafiles[] = {
291 DATAFILE("Raw", event.data, 4, PANEL_SAVE_RAW, TRUE), 308 DATAFILE("Raw", event.data, 4, PANEL_SAVE_RAW, TRUE),
292 DATAFILE("DDS", DDS4xAD9912.frequency, 4, PANEL_SAVE_DDS, FALSE), 309 DATAFILE("DDS", ad9912.frequency, 4, PANEL_SAVE_DDS, FALSE),
293 DATAFILE("Lo", &Math2, 1, PANEL_SAVE_LO, FALSE), 310 DATAFILE("Lo", &Math2, 1, PANEL_SAVE_LO, FALSE),
294 DATAFILE("Hg", &Math3, 1, PANEL_SAVE_HG, FALSE), 311 DATAFILE("Hg", &Math3, 1, PANEL_SAVE_HG, FALSE),
295 DATAFILE("Sr", &Math4, 1, PANEL_SAVE_SR, FALSE), 312 DATAFILE("Sr", &Math4, 1, PANEL_SAVE_SR, FALSE),
296 DATAFILE("Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE), 313 DATAFILE("Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE),
297 { NULL, } 314 { NULL, }
352 369
353 mupDefineVar(parser, "Ch1", &Ch1); 370 mupDefineVar(parser, "Ch1", &Ch1);
354 mupDefineVar(parser, "Ch2", &Ch2); 371 mupDefineVar(parser, "Ch2", &Ch2);
355 mupDefineVar(parser, "Ch3", &Ch3); 372 mupDefineVar(parser, "Ch3", &Ch3);
356 mupDefineVar(parser, "Ch4", &Ch4); 373 mupDefineVar(parser, "Ch4", &Ch4);
357 mupDefineVar(parser, "DDS1", &(DDS4xAD9912.frequency[0])); 374 mupDefineVar(parser, "DDS1", &(ad9912.frequency[0]));
358 mupDefineVar(parser, "DDS2", &(DDS4xAD9912.frequency[1])); 375 mupDefineVar(parser, "DDS2", &(ad9912.frequency[1]));
359 mupDefineVar(parser, "DDS3", &(DDS4xAD9912.frequency[2])); 376 mupDefineVar(parser, "DDS3", &(ad9912.frequency[2]));
360 mupDefineVar(parser, "DDS4", &(DDS4xAD9912.frequency[3])); 377 mupDefineVar(parser, "DDS4", &(ad9912.frequency[3]));
361 mupDefineVar(parser, "N1", &N1); 378 mupDefineVar(parser, "N1", &N1);
362 mupDefineVar(parser, "N2", &N2); 379 mupDefineVar(parser, "N2", &N2);
363 mupDefineVar(parser, "N3", &N3); 380 mupDefineVar(parser, "N3", &N3);
364 mupDefineVar(parser, "Sign1", &Sign1); 381 mupDefineVar(parser, "Sign1", &Sign1);
365 mupDefineVar(parser, "Sign2", &Sign2); 382 mupDefineVar(parser, "Sign2", &Sign2);
419 logmessage(ERROR, "data folder not configured in %s", path); 436 logmessage(ERROR, "data folder not configured in %s", path);
420 // do not allow to start the acquisition 437 // do not allow to start the acquisition
421 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); 438 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE);
422 } 439 }
423 440
424 // AD9956 configuration parameters 441 // ad9956 configuration parameters
425 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host)); 442 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host));
426 if (! rv) 443 if (! rv)
427 return -1; 444 return -1;
428 rv = Ini_GetInt(configuration, "AD9956", "port", &port); 445 rv = Ini_GetInt(configuration, "AD9956", "port", &port);
429 if (! rv) 446 if (! rv)
431 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock); 448 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock);
432 if (! rv) 449 if (! rv)
433 return -1; 450 return -1;
434 451
435 // dedrift DDS 452 // dedrift DDS
436 DDSFox_Init(&DDS1xAD9956, host, port); 453 DDSFox_Init(&ad9956, host, port);
437 454
438 // AD9912 configuration parameters 455 // ad9912 configuration parameters
439 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host)); 456 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host));
440 if (! rv) 457 if (! rv)
441 return -1; 458 return -1;
442 rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock); 459 rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock);
443 if (! rv) 460 if (! rv)
444 return -1; 461 return -1;
445 462
446 // initialize 4x AD9912 DDS box 463 // initialize AD9912 DDS box
447 DDS4xAD9912_Init(&DDS4xAD9912, host, clock); 464 ad9912_init(&ad9912, host, clock);
448 DDS4xAD9912_Reset(&DDS4xAD9912);
449 GetCtrlVal(MainPanel, PANEL_DDS1, &frequency); 465 GetCtrlVal(MainPanel, PANEL_DDS1, &frequency);
450 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, frequency); 466 ad9912_set_frequency_w(&ad9912, 0, frequency);
451 GetCtrlVal(MainPanel, PANEL_DDS2, &frequency); 467 GetCtrlVal(MainPanel, PANEL_DDS2, &frequency);
452 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, frequency); 468 ad9912_set_frequency_w(&ad9912, 1, frequency);
453 GetCtrlVal(MainPanel, PANEL_DDS3, &frequency); 469 GetCtrlVal(MainPanel, PANEL_DDS3, &frequency);
454 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); 470 ad9912_set_frequency_w(&ad9912, 2, frequency);
455 GetCtrlVal(MainPanel, PANEL_DDS4, &frequency); 471 GetCtrlVal(MainPanel, PANEL_DDS4, &frequency);
456 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); 472 ad9912_set_frequency_w(&ad9912, 3, frequency);
457 473
458 // dispose configuration 474 // dispose configuration
459 Ini_Dispose(configuration); 475 Ini_Dispose(configuration);
460 476
461 // Sr data logger 477 // Sr data logger
462 sr_datalogger_init(&datalogger); 478 sr_datalogger_init(&datalogger);
463 479
464 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1); 480 GetCtrlVal(MainPanel, PANEL_N1, &N1);
465 GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2); 481 GetCtrlVal(MainPanel, PANEL_N2, &N2);
466 GetCtrlVal(MainPanel, PANEL_N3CHOICE, &N3); 482 GetCtrlVal(MainPanel, PANEL_N3, &N3);
467 483
468 MathParser1 = muParserNew(); 484 MathParser1 = muParserNew();
469 GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr); 485 GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr);
470 mupSetExpr(MathParser1, expr); 486 mupSetExpr(MathParser1, expr);
471 487
694 710
695 case N_MEASUREMENT_INIT: 711 case N_MEASUREMENT_INIT:
696 // initialization step 712 // initialization step
697 713
698 // set DDS1 to nominal frequency 714 // set DDS1 to nominal frequency
699 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 715 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1);
700 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 716 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
701 717
702 // record current DDS frequencies 718 // record current DDS frequencies
703 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 719 f0_DDS2 = ad9912.frequency[1];
704 720
705 t1 = utc; 721 t1 = utc;
706 t2 = t3 = 0.0; 722 t2 = t3 = 0.0;
707 nobs = 0; 723 nobs = 0;
708 stat_zero(&stat_math1); 724 stat_zero(&stat_math1);
719 735
720 if ((utc - t1) > SlopeTime1) { 736 if ((utc - t1) > SlopeTime1) {
721 f_rep_slope = stat_math1.slope; 737 f_rep_slope = stat_math1.slope;
722 738
723 // frep positive step 739 // frep positive step
724 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE); 740 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE);
725 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 741 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
726 742
727 // allow counter to settle 743 // allow counter to settle
728 settling = 3; 744 settling = 3;
729 745
730 // next step 746 // next step
737 // adjust DDS frequency to keep beatnote within the bandpass filter 753 // adjust DDS frequency to keep beatnote within the bandpass filter
738 754
739 if (settling-- > 0) 755 if (settling-- > 0)
740 break; 756 break;
741 757
742 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 758 double fDDS2 = ad9912.frequency[1];
743 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2 + 275000 - Ch4); 759 ad9912_set_frequency_w(&ad9912, 1, fDDS2 + 275000 - Ch4);
744 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 760 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
745 761
746 // allow counter to settle 762 // allow counter to settle
747 settling = 3; 763 settling = 3;
748 764
749 // next step 765 // next step
765 if ((utc - t2) > DeltaT_1) { 781 if ((utc - t2) > DeltaT_1) {
766 f_rep_plus = f_rep_plus / nobs; 782 f_rep_plus = f_rep_plus / nobs;
767 nobs = 0; 783 nobs = 0;
768 784
769 // frep negative step 785 // frep negative step
770 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE); 786 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE);
771 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 787 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
772 788
773 // allow counter to settle 789 // allow counter to settle
774 settling = 3; 790 settling = 3;
775 791
776 // next step 792 // next step
798 double delta_f_rep = f_rep_minus - f_rep_plus; 814 double delta_f_rep = f_rep_minus - f_rep_plus;
799 N_measured = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep; 815 N_measured = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep;
800 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 816 SetCtrlVal(CalcNPanel, CALCN_N, N_measured);
801 817
802 // back to nominal frep 818 // back to nominal frep
803 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 819 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
804 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 820 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
805 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 821 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
806 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 822 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
807 823
808 // done 824 // done
809 Measuring_1 = N_MEASUREMENT_NONE; 825 Measuring_1 = N_MEASUREMENT_NONE;
810 } 826 }
811 break; 827 break;
819 835
820 case N_MEASUREMENT_INIT: 836 case N_MEASUREMENT_INIT:
821 // initialization step 837 // initialization step
822 838
823 // set DDS1 to nominal frequency 839 // set DDS1 to nominal frequency
824 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 840 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1);
825 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 841 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
826 842
827 // record current DDS frequencies 843 // record current DDS frequencies
828 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 844 f0_DDS2 = ad9912.frequency[1];
829 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 845 f0_DDS3 = ad9912.frequency[2];
830 846
831 t1 = utc; 847 t1 = utc;
832 t2 = t3 = 0.0; 848 t2 = t3 = 0.0;
833 nobs = 0; 849 nobs = 0;
834 stat_zero(&stat_math1); 850 stat_zero(&stat_math1);
850 f_rep_slope = stat_math1.slope; 866 f_rep_slope = stat_math1.slope;
851 f_beat_slope = stat_ch2.slope; 867 f_beat_slope = stat_ch2.slope;
852 868
853 // frep positive step 869 // frep positive step
854 double fDDS1 = f0_DDS1 + delta_f_lock_2; 870 double fDDS1 = f0_DDS1 + delta_f_lock_2;
855 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); 871 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
856 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 872 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
857 873
858 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 874 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
859 double fDDS3 = f0_DDS3 + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2; 875 double fDDS3 = f0_DDS3 + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2;
860 df_DDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 876 df_DDS3 = fDDS3 - ad9912.frequency[2];
861 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 877 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
862 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 878 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
863 879
864 // allow counter to settle 880 // allow counter to settle
865 settling = 3; 881 settling = 3;
866 882
867 // next step 883 // next step
874 // adjust DDS frequency to keep beatnote within the bandpass filter 890 // adjust DDS frequency to keep beatnote within the bandpass filter
875 891
876 if (settling-- > 0) 892 if (settling-- > 0)
877 break; 893 break;
878 894
879 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; 895 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4;
880 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); 896 ad9912_set_frequency_w(&ad9912, 1, fDDS2);
881 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 897 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
882 898
883 double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; 899 double fDDS3 = ad9912.frequency[2] + 10000 - Ch2;
884 df_DDS3 = df_DDS3 + 10000 - Ch2; 900 df_DDS3 = df_DDS3 + 10000 - Ch2;
885 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 901 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
886 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 902 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
887 903
888 // allow counter to settle 904 // allow counter to settle
889 settling = 3; 905 settling = 3;
890 906
891 // next step 907 // next step
910 f_beat_plus = f_beat_plus / nobs; 926 f_beat_plus = f_beat_plus / nobs;
911 nobs = 0; 927 nobs = 0;
912 928
913 // negative frequency step 929 // negative frequency step
914 double fDDS1 = f0_DDS1 - delta_f_lock_2; 930 double fDDS1 = f0_DDS1 - delta_f_lock_2;
915 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); 931 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE);
916 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 932 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
917 933
918 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 934 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
919 double fDDS3 = f0_DDS3 - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2; 935 double fDDS3 = f0_DDS3 - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2;
920 df_DDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 936 df_DDS3 = fDDS3 - ad9912.frequency[2];
921 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 937 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
922 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 938 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
923 939
924 // allow counter to settle 940 // allow counter to settle
925 settling = 3; 941 settling = 3;
926 942
927 // next step 943 // next step
947 f_beat_minus = f_beat_minus / nobs; 963 f_beat_minus = f_beat_minus / nobs;
948 nobs = 0; 964 nobs = 0;
949 965
950 // compute N2 966 // compute N2
951 double delta_f_rep_m = f_rep_minus - f_rep_plus; 967 double delta_f_rep_m = f_rep_minus - f_rep_plus;
952 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; 968 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_2 / N1;
953 969 double delta = delta_f_rep_m - delta_f_rep;
954 logmsg("delta frep: measured=%e expected=%e difference=%e", 970
955 delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); 971 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
972 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
956 973
957 N_measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; 974 N_measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep;
958 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 975 SetCtrlVal(CalcNPanel, CALCN_N, N_measured);
959 976
960 // back to nominal frequency 977 // back to nominal frequency
961 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 978 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
962 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 979 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
963 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 980 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
964 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 981 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
965 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 982 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
966 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 983 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
967 984
968 // done 985 // done
969 Measuring_2 = N_MEASUREMENT_NONE; 986 Measuring_2 = N_MEASUREMENT_NONE;
970 } 987 }
971 break; 988 break;
979 996
980 case N_MEASUREMENT_INIT: 997 case N_MEASUREMENT_INIT:
981 // init 998 // init
982 999
983 // set DDS1 to nominal frequency 1000 // set DDS1 to nominal frequency
984 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 1001 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1);
985 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1002 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
986 1003
987 // record current DDS frequencies 1004 // record current DDS frequencies
988 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 1005 f0_DDS2 = ad9912.frequency[1];
989 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 1006 f0_DDS3 = ad9912.frequency[2];
990 1007
991 t1 = utc; 1008 t1 = utc;
992 t2 = t3 = 0.0; 1009 t2 = t3 = 0.0;
993 nobs = 0; 1010 nobs = 0;
994 stat_zero(&stat_math1); 1011 stat_zero(&stat_math1);
1016 1033
1017 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); 1034 logmsg("f_rep_slope=%e Hz/s", f_rep_slope);
1018 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); 1035 logmsg("f_beat_slope=%e Hz/s", f_rep_slope);
1019 1036
1020 // frep positive step 1037 // frep positive step
1021 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE); 1038 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE);
1022 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1039 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1023 1040
1024 // adjust DDS3 to keep beatnote within the bandpass filter 1041 // adjust DDS3 to keep beatnote within the bandpass filter
1025 double fDDS3 = f0_DDS3 + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1042 double fDDS3 = f0_DDS3 + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3;
1026 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 1043 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
1027 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1044 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1028 1045
1029 // allow counter to settle 1046 // allow counter to settle
1030 settling = 3; 1047 settling = 3;
1031 1048
1032 // next step 1049 // next step
1040 1057
1041 if (settling-- > 0) 1058 if (settling-- > 0)
1042 break; 1059 break;
1043 1060
1044 // adjust DDS frequency to keep 55 MHz tracker oscillator locked 1061 // adjust DDS frequency to keep 55 MHz tracker oscillator locked
1045 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; 1062 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4;
1046 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); 1063 ad9912_set_frequency_w(&ad9912, 1, fDDS2);
1047 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1064 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1048 1065
1049 // allow counter to settle 1066 // allow counter to settle
1050 settling = 3; 1067 settling = 3;
1051 1068
1052 // next step 1069 // next step
1070 f_rep_plus = f_rep_plus / nobs; 1087 f_rep_plus = f_rep_plus / nobs;
1071 f_beat_plus = f_beat_plus / nobs; 1088 f_beat_plus = f_beat_plus / nobs;
1072 nobs = 0; 1089 nobs = 0;
1073 1090
1074 // frep negative step 1091 // frep negative step
1075 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE); 1092 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE);
1076 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1093 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1077 1094
1078 // adjust DDS3 to keep beatnote within the bandpass filter 1095 // adjust DDS3 to keep beatnote within the bandpass filter
1079 double fDDS3 = f0_DDS3 - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1096 double fDDS3 = f0_DDS3 - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3;
1080 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 1097 ad9912_set_frequency_w(&ad9912, 2, fDDS3);
1081 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1098 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1082 1099
1083 // allow counter to settle 1100 // allow counter to settle
1084 settling = 3; 1101 settling = 3;
1085 1102
1086 // next step 1103 // next step
1107 nobs = 0; 1124 nobs = 0;
1108 1125
1109 // check delta frep 1126 // check delta frep
1110 double delta_f_rep_m = f_rep_plus - f_rep_minus; 1127 double delta_f_rep_m = f_rep_plus - f_rep_minus;
1111 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; 1128 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1;
1112 1129 double delta = delta_f_rep_m - delta_f_rep;
1113 logmsg("delta frep: measured=%e expected=%e difference=%e", 1130
1114 delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); 1131 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
1115 1132 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
1116 logmsg("f_beat_minus=%e", f_beat_minus);
1117 logmsg("f_beat_plus =%e", f_beat_plus);
1118 1133
1119 // compute N3 1134 // compute N3
1120 double delta_f_beat = f_beat_plus - f_beat_minus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; 1135 double delta_f_beat = f_beat_plus - f_beat_minus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3;
1121 double delta_f_beat_expected = delta_f_rep * N3; 1136 double delta_f_beat_expected = delta_f_rep * N3;
1122 1137
1127 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 1142 SetCtrlVal(CalcNPanel, CALCN_N, N_measured);
1128 1143
1129 logmsg("measured N3=%.3f", N_measured); 1144 logmsg("measured N3=%.3f", N_measured);
1130 1145
1131 // back to nominal frep 1146 // back to nominal frep
1132 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1147 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1133 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1148 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1134 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1149 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
1135 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1150 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1136 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1151 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1137 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1152 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1138 1153
1139 // done 1154 // done
1140 Measuring_3 = N_MEASUREMENT_NONE; 1155 Measuring_3 = N_MEASUREMENT_NONE;
1141 } 1156 }
1142 break; 1157 break;
1148 if (utc > tbegin1+2) { 1163 if (utc > tbegin1+2) {
1149 if (Math1 > Frepbefore1) 1164 if (Math1 > Frepbefore1)
1150 Sign1 = -1.0; 1165 Sign1 = -1.0;
1151 else 1166 else
1152 Sign1 = +1.0; 1167 Sign1 = +1.0;
1153 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1); 1168 ad9912_set_frequency_w(&ad9912, 0, Frequency1);
1154 Getsign1 = FALSE; 1169 Getsign1 = FALSE;
1155 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); 1170 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1);
1156 } 1171 }
1157 } 1172 }
1158 if (Getsign2 == TRUE) { 1173 if (Getsign2 == TRUE) {
1166 if (Ch2 > Ch2before) 1181 if (Ch2 > Ch2before)
1167 Sign2 = -1.0; 1182 Sign2 = -1.0;
1168 else 1183 else
1169 Sign2 = +1.0; 1184 Sign2 = +1.0;
1170 } 1185 }
1171 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2); 1186 ad9912_set_frequency_w(&ad9912, 0, Frequency2);
1172 Getsign2 = FALSE; 1187 Getsign2 = FALSE;
1173 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); 1188 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2);
1174 } 1189 }
1175 } 1190 }
1176 if (Getsign3 == TRUE) { 1191 if (Getsign3 == TRUE) {
1177 if (utc > tbegin3+2){ 1192 if (utc > tbegin3+2){
1178 if (Ch3 > Frepbefore3) 1193 if (Ch3 > Frepbefore3)
1179 Sign3 = -1.0; 1194 Sign3 = -1.0;
1180 else 1195 else
1181 Sign3 = +1.0; 1196 Sign3 = +1.0;
1182 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3); 1197 ad9912_set_frequency_w(&ad9912, 3, Frequency3);
1183 Getsign3 = FALSE; 1198 Getsign3 = FALSE;
1184 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); 1199 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3);
1185 } 1200 }
1186 } 1201 }
1187 1202
1202 & (freq.previous != 0.0) 1217 & (freq.previous != 0.0)
1203 & (fabs(f - freq.previous) > dedrift.threshold)) { 1218 & (fabs(f - freq.previous) > dedrift.threshold)) {
1204 1219
1205 if (! dedrift.keep_slope) { 1220 if (! dedrift.keep_slope) {
1206 dedrift.applied = 0.0; 1221 dedrift.applied = 0.0;
1207 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); 1222 DDSFox_SetSweepRate(&ad9956, dedrift.applied);
1208 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1223 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1209 } 1224 }
1210 if (! dedrift.keep_freq) { 1225 if (! dedrift.keep_freq) {
1211 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); 1226 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied);
1212 } 1227 }
1213 1228
1214 stat_zero(&freq); 1229 stat_zero(&freq);
1215 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); 1230 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope);
1216 dedrift.enabled = FALSE; 1231 dedrift.enabled = FALSE;
1235 dedrift.applied += freq.slope; 1250 dedrift.applied += freq.slope;
1236 1251
1237 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1252 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1238 1253
1239 if (dedrift.doubleslope) 1254 if (dedrift.doubleslope)
1240 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied * 2.0); 1255 DDSFox_SetSweepRate(&ad9956, dedrift.applied * 2.0);
1241 else 1256 else
1242 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); 1257 DDSFox_SetSweepRate(&ad9956, dedrift.applied);
1243 1258
1244 logmsg("dedrift update: adjustment=%+3e slope=%+3e", freq.slope, dedrift.applied); 1259 logmsg("dedrift update: adjustment=%+3e slope=%+3e", freq.slope, dedrift.applied);
1245 1260
1246 stat_zero(&freq); 1261 stat_zero(&freq);
1247 dedrift.t0 = utc; 1262 dedrift.t0 = utc;
1257 1272
1258 if ((utc - recenter.t0) > recenter.interval) { 1273 if ((utc - recenter.t0) > recenter.interval) {
1259 1274
1260 if (recenter.lo) { 1275 if (recenter.lo) {
1261 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz 1276 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz
1262 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 1277 double freq = ad9912.frequency[1];
1263 double adj = 275000.0 - rollmean_ch4.mean; 1278 double adj = 275000.0 - rollmean_ch4.mean;
1264 freq = freq + adj; 1279 freq = freq + adj;
1265 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); 1280 ad9912_set_frequency_w(&ad9912, 1, freq);
1266 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1281 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1267 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); 1282 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj);
1268 } 1283 }
1269 1284
1270 if (recenter.hg) { 1285 if (recenter.hg) {
1271 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz 1286 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz
1272 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 1287 double freq = ad9912.frequency[2];
1273 double adj = 10000 - rollmean_ch2.mean; 1288 double adj = 10000 - rollmean_ch2.mean;
1274 freq = freq + adj; 1289 freq = freq + adj;
1275 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); 1290 ad9912_set_frequency_w(&ad9912, 2, freq);
1276 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1291 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1277 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); 1292 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj);
1278 } 1293 }
1279 1294
1280 if (recenter.sr) { 1295 if (recenter.sr) {
1281 // adjust DDS3 frequency to keep Ch3 reading at 10 kHz 1296 // adjust DDS3 frequency to keep Ch3 reading at 10 kHz
1282 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 1297 double freq = ad9912.frequency[2];
1283 double adj = 10000 - rollmean_ch3.mean; 1298 double adj = 10000 - rollmean_ch3.mean;
1284 freq = freq + adj; 1299 freq = freq + adj;
1285 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); 1300 ad9912_set_frequency_w(&ad9912, 2, freq);
1286 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1301 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1287 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS3 adjustment=%+3e", adj); 1302 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS3 adjustment=%+3e", adj);
1288 } 1303 }
1289 1304
1290 recenter.t0 = utc; 1305 recenter.t0 = utc;
1291 rollmean_zero(&rollmean_ch2); 1306 rollmean_zero(&rollmean_ch2);
1361 case EVENT_COMMIT: 1376 case EVENT_COMMIT:
1362 double frequency; 1377 double frequency;
1363 GetCtrlVal(MainPanel, control, &frequency); 1378 GetCtrlVal(MainPanel, control, &frequency);
1364 switch (control) { 1379 switch (control) {
1365 case PANEL_DDS1: 1380 case PANEL_DDS1:
1366 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, frequency); 1381 ad9912_set_frequency_w(&ad9912, 0, frequency);
1367 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1382 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1368 break; 1383 break;
1369 case PANEL_DDS2: 1384 case PANEL_DDS2:
1370 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, frequency); 1385 ad9912_set_frequency_w(&ad9912, 1, frequency);
1371 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1386 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1372 break; 1387 break;
1373 case PANEL_DDS3: 1388 case PANEL_DDS3:
1374 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); 1389 ad9912_set_frequency_w(&ad9912, 2, frequency);
1375 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1390 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1376 break; 1391 break;
1377 case PANEL_DDS4: 1392 case PANEL_DDS4:
1378 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); 1393 ad9912_set_frequency_w(&ad9912, 3, frequency);
1379 SetCtrlVal(MainPanel, PANEL_DDS4, DDS4xAD9912.frequency[3]); 1394 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1380 break; 1395 break;
1381 } 1396 }
1382 break; 1397 break;
1383 } 1398 }
1384 return 0; 1399 return 0;
1453 switch (event) 1468 switch (event)
1454 { 1469 {
1455 case EVENT_COMMIT: 1470 case EVENT_COMMIT:
1456 switch (control) 1471 switch (control)
1457 { 1472 {
1458 case PANEL_N1CHOICE: 1473 case PANEL_N1:
1459 GetCtrlVal(panel, control, &N1); 1474 GetCtrlVal(panel, control, &N1);
1460 break; 1475 break;
1461 case PANEL_N2CHOICE: 1476 case PANEL_N2:
1462 GetCtrlVal(panel, control, &N2); 1477 GetCtrlVal(panel, control, &N2);
1463 break; 1478 break;
1464 case PANEL_N3CHOICE: 1479 case PANEL_N3:
1465 GetCtrlVal(panel, control, &N3); 1480 GetCtrlVal(panel, control, &N3);
1466 break; 1481 break;
1467 } 1482 }
1468 break; 1483 break;
1469 } 1484 }
1479 case EVENT_COMMIT: 1494 case EVENT_COMMIT:
1480 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure); 1495 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure);
1481 switch (measure) { 1496 switch (measure) {
1482 case LO: 1497 case LO:
1483 N1 = round(N_measured); 1498 N1 = round(N_measured);
1484 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1); 1499 SetCtrlVal(MainPanel, PANEL_N1, N1);
1485 break; 1500 break;
1486 case HG: 1501 case HG:
1487 N2 = round(N_measured); 1502 N2 = round(N_measured);
1488 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2); 1503 SetCtrlVal(MainPanel, PANEL_N2, N2);
1489 break; 1504 break;
1490 case SR: 1505 case SR:
1491 N3 = round(N_measured); 1506 N3 = round(N_measured);
1492 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); 1507 SetCtrlVal(MainPanel, PANEL_N3, N3);
1493 break; 1508 break;
1494 } 1509 }
1495 break; 1510 break;
1496 } 1511 }
1497 return 0; 1512 return 0;
1506 case EVENT_COMMIT: 1521 case EVENT_COMMIT:
1507 switch (control) { 1522 switch (control) {
1508 case PANEL_N1CALCULUS: 1523 case PANEL_N1CALCULUS:
1509 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1524 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1510 if (! visible) { 1525 if (! visible) {
1511 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, LO); 1526 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, LO);
1512 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); 1527 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo");
1513 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); 1528 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1);
1514 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); 1529 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1);
1515 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); 1530 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0);
1516 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1531 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1518 } 1533 }
1519 break; 1534 break;
1520 case PANEL_N2CALCULUS: 1535 case PANEL_N2CALCULUS:
1521 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1536 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1522 if (! visible) { 1537 if (! visible) {
1523 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, HG); 1538 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, HG);
1524 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); 1539 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg");
1525 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); 1540 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2);
1526 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); 1541 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2);
1527 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); 1542 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0);
1528 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1543 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1530 } 1545 }
1531 break; 1546 break;
1532 case PANEL_N3CALCULUS: 1547 case PANEL_N3CALCULUS:
1533 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1548 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1534 if (! visible) { 1549 if (! visible) {
1535 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, SR); 1550 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, SR);
1536 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); 1551 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr");
1537 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); 1552 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3);
1538 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); 1553 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3);
1539 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); 1554 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0);
1540 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1555 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1596 HidePanel(CalcNPanel); 1611 HidePanel(CalcNPanel);
1597 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); 1612 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring);
1598 switch (measuring) { 1613 switch (measuring) {
1599 case LO: 1614 case LO:
1600 Measuring_1 = FALSE; 1615 Measuring_1 = FALSE;
1601 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1616 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1602 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1617 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1603 break; 1618 break;
1604 case HG: 1619 case HG:
1605 Measuring_2 = FALSE; 1620 Measuring_2 = FALSE;
1606 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1621 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1607 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1622 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1608 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1623 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
1609 break; 1624 break;
1610 case SR: 1625 case SR:
1611 Measuring_3 = FALSE; 1626 Measuring_3 = FALSE;
1612 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1627 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1613 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1628 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1614 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1629 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
1615 break; 1630 break;
1616 } 1631 }
1617 1632
1618 // update DDS frequencies display 1633 // update DDS frequencies display
1619 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1634 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1620 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1635 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1621 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1636 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1622 SetCtrlVal(MainPanel, PANEL_DDS4, DDS4xAD9912.frequency[3]); 1637 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1623 1638
1624 break; 1639 break;
1625 } 1640 }
1626 return 0; 1641 return 0;
1627 } 1642 }
1637 case PANEL_FINDSIGN1: 1652 case PANEL_FINDSIGN1:
1638 tbegin1 = utc; 1653 tbegin1 = utc;
1639 Frepbefore1 = Math1; 1654 Frepbefore1 = Math1;
1640 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ; 1655 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ;
1641 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ; 1656 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ;
1642 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1+Frequencystep1); 1657 ad9912_set_frequency_w(&ad9912, 0, Frequency1+Frequencystep1);
1643 Getsign1 = TRUE; 1658 Getsign1 = TRUE;
1644 break; 1659 break;
1645 case PANEL_FINDSIGN2: 1660 case PANEL_FINDSIGN2:
1646 tbegin2 = utc; 1661 tbegin2 = utc;
1647 Frepbefore2 = Math1; 1662 Frepbefore2 = Math1;
1648 Ch2before = Ch2; 1663 Ch2before = Ch2;
1649 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ; 1664 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ;
1650 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ; 1665 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ;
1651 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2+Frequencystep2); 1666 ad9912_set_frequency_w(&ad9912, 0, Frequency2+Frequencystep2);
1652 Getsign2 = TRUE; 1667 Getsign2 = TRUE;
1653 break; 1668 break;
1654 case PANEL_FINDSIGN3: 1669 case PANEL_FINDSIGN3:
1655 tbegin3 = utc; 1670 tbegin3 = utc;
1656 Frepbefore3 = Math1; 1671 Frepbefore3 = Math1;
1657 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency3) ; 1672 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency3) ;
1658 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency3+Frequencystep3) ; 1673 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency3+Frequencystep3) ;
1659 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3+Frequencystep3); 1674 ad9912_set_frequency_w(&ad9912, 3, Frequency3+Frequencystep3);
1660 Getsign3 = TRUE; 1675 Getsign3 = TRUE;
1661 break; 1676 break;
1662 } 1677 }
1663 break; 1678 break;
1664 } 1679 }
1667 1682
1668 int CVICALLBACK CB_OnFind275K (int panel, int control, int event, 1683 int CVICALLBACK CB_OnFind275K (int panel, int control, int event,
1669 void *callbackData, int eventData1, int eventData2) 1684 void *callbackData, int eventData1, int eventData2)
1670 { 1685 {
1671 double frequency; 1686 double frequency;
1672
1673 switch (event) 1687 switch (event)
1674 { 1688 {
1675 case EVENT_COMMIT: 1689 case EVENT_COMMIT:
1676 switch (control) 1690 switch (control)
1677 { 1691 {
1678 case PANEL_FIND275K2: 1692 case PANEL_FIND275K2:
1679 frequency = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; 1693 frequency = ad9912.frequency[1] + 275000 - Ch4;
1680 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, frequency); 1694 ad9912_set_frequency_w(&ad9912, 1, frequency);
1681 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); 1695 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1682 break; 1696 break;
1683 case PANEL_FIND10K3: 1697 case PANEL_FIND10K3:
1684 frequency = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; 1698 frequency = ad9912.frequency[2] + 10000 - Ch2;
1685 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); 1699 ad9912_set_frequency_w(&ad9912, 2, frequency);
1686 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); 1700 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1687 break; 1701 break;
1688 } 1702 }
1689 break; 1703 break;
1690 } 1704 }
1691 return 0; 1705 return 0;
1697 switch (event) 1711 switch (event)
1698 { 1712 {
1699 case EVENT_COMMIT: 1713 case EVENT_COMMIT:
1700 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); 1714 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv);
1701 f0_DDS1 = 880000000.0 / Ndiv; 1715 f0_DDS1 = 880000000.0 / Ndiv;
1702 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 1716 ad9912_set_frequency_w(&ad9912, 0, f0_DDS1);
1703 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); 1717 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1704 break; 1718 break;
1705 } 1719 }
1706 return 0; 1720 return 0;
1707 } 1721 }
1708 1722
1718 stat_zero(&freq); 1732 stat_zero(&freq);
1719 logmsg("dedrift start"); 1733 logmsg("dedrift start");
1720 } else { 1734 } else {
1721 if (! dedrift.keep_slope) { 1735 if (! dedrift.keep_slope) {
1722 dedrift.applied = 0.0; 1736 dedrift.applied = 0.0;
1723 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); 1737 DDSFox_SetSweepRate(&ad9956, dedrift.applied);
1724 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); 1738 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied);
1725 } 1739 }
1726 if (! dedrift.keep_freq) { 1740 if (! dedrift.keep_freq) {
1727 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); 1741 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied);
1728 } 1742 }
1729 stat_zero(&freq); 1743 stat_zero(&freq);
1730 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope); 1744 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope);
1731 logmsg("dedrift stop"); 1745 logmsg("dedrift stop");
1732 } 1746 }
1741 switch (event) 1755 switch (event)
1742 { 1756 {
1743 case EVENT_COMMIT: 1757 case EVENT_COMMIT:
1744 dedrift.applied = 0.0; 1758 dedrift.applied = 0.0;
1745 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); 1759 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied);
1746 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); 1760 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied);
1747 logmsg("dedrift reset"); 1761 logmsg("dedrift reset");
1748 break; 1762 break;
1749 } 1763 }
1750 return 0; 1764 return 0;
1751 } 1765 }
1883 case EVENT_COMMIT: 1897 case EVENT_COMMIT:
1884 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate); 1898 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate);
1885 switch (estimate) { 1899 switch (estimate) {
1886 case HG: 1900 case HG:
1887 GetCtrlVal(panel, ESTIMATEN_N, &N2); 1901 GetCtrlVal(panel, ESTIMATEN_N, &N2);
1888 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N2); 1902 SetCtrlVal(MainPanel, PANEL_N2, N2);
1889 break; 1903 break;
1890 case SR: 1904 case SR:
1891 GetCtrlVal(panel, ESTIMATEN_N, &N3); 1905 GetCtrlVal(panel, ESTIMATEN_N, &N3);
1892 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); 1906 SetCtrlVal(MainPanel, PANEL_N3, N3);
1893 break; 1907 break;
1894 } 1908 }
1895 HidePanel(panel); 1909 HidePanel(panel);
1896 break; 1910 break;
1897 } 1911 }
1920 { 1934 {
1921 switch (event) 1935 switch (event)
1922 { 1936 {
1923 case EVENT_COMMIT: 1937 case EVENT_COMMIT:
1924 GetCtrlVal(panel, control, &dedrift.applied); 1938 GetCtrlVal(panel, control, &dedrift.applied);
1925 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); 1939 DDSFox_SetSweepRate(&ad9956, dedrift.applied);
1926 break; 1940 break;
1927 } 1941 }
1928 return 0; 1942 return 0;
1929 } 1943 }
1930 1944
1950 dedrift.enabled = FALSE; 1964 dedrift.enabled = FALSE;
1951 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); 1965 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0);
1952 dedrift.applied = 0.0; 1966 dedrift.applied = 0.0;
1953 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); 1967 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied);
1954 // reset DDS 1968 // reset DDS
1955 DDSFox_Reset(&DDS1xAD9956, dedrift.freq0); 1969 DDSFox_Reset(&ad9956, dedrift.freq0);
1956 break; 1970 break;
1957 } 1971 }
1958 return 0; 1972 return 0;
1959 } 1973 }
1960 1974
2076 { 2090 {
2077 switch (event) 2091 switch (event)
2078 { 2092 {
2079 case EVENT_COMMIT: 2093 case EVENT_COMMIT:
2080 GetCtrlVal(panel, control, &dedrift.freq0); 2094 GetCtrlVal(panel, control, &dedrift.freq0);
2081 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); 2095 DDSFox_Set(&ad9956, dedrift.freq0, dedrift.applied);
2082 break; 2096 break;
2083 } 2097 }
2084 return 0; 2098 return 0;
2085 } 2099 }