comparison FXAnalyse.c @ 160:f609fb29536b

Simplification and code cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 04 Feb 2014 12:48:37 +0100
parents 07153c41ba16
children 6ee23cb3d6bb
comparison
equal deleted inserted replaced
159:07153c41ba16 160:f609fb29536b
20 #define SR_LOGGER_IP "145.238.204.91" 20 #define SR_LOGGER_IP "145.238.204.91"
21 #define DATAFOLDER "Z:\\Measures-2014" 21 #define DATAFOLDER "Z:\\Measures-2014"
22 22
23 #define FREP_STEP_SIZE 50000.0 23 #define FREP_STEP_SIZE 50000.0
24 24
25 #define SPEED_OF_LIGHT 299792458.0 // m/s
26 #define SR_WAVELENGTH 698.4460 // nm
27 #define HG_WAVELENGTH 1062.4000 // nm
28
25 // data acquisition status 29 // data acquisition status
26 int acquiring; 30 int acquiring;
27 // data queue 31 // data queue
28 CmtTSQHandle dataQueue; 32 CmtTSQHandle dataQueue;
29 // data provider thread 33 // data provider thread
43 double N1, N2, N3; 47 double N1, N2, N3;
44 48
45 // panels 49 // panels
46 static int MainPanel; 50 static int MainPanel;
47 static int CalcNPanel; 51 static int CalcNPanel;
48 static int EstimateN3Panel; 52 static int EstimateNPanel;
49 static int LoggingPanel; 53 static int LoggingPanel;
50 54
51 55
52 struct adev { 56 struct adev {
53 Allan_Data allan; 57 Allan_Data allan;
155 // 4xAD9912 DDS box 159 // 4xAD9912 DDS box
156 DDS4xAD9912_Data DDS4xAD9912; 160 DDS4xAD9912_Data DDS4xAD9912;
157 161
158 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5; 162 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5;
159 163
160 double Ndiv = 8.0;
161
162 int settling = 0;
163
164 enum { 164 enum {
165 MEASURING_N_NONE, 165 N_NONE,
166 MEASURING_N_Lo, 166 N_LO,
167 MEASURING_N_Hg, 167 N_HG,
168 MEASURING_N_Sr, 168 N_SR,
169 }; 169 };
170
171 int measuring = MEASURING_N_NONE;
172 170
173 enum { 171 enum {
174 N_MEASUREMENT_NONE, 172 N_MEASUREMENT_NONE,
175 N_MEASUREMENT_INIT, 173 N_MEASUREMENT_INIT,
176 N_MEASUREMENT_SLOPE, 174 N_MEASUREMENT_SLOPE,
182 180
183 int Measuring_1 = N_MEASUREMENT_NONE; 181 int Measuring_1 = N_MEASUREMENT_NONE;
184 int Measuring_2 = N_MEASUREMENT_NONE; 182 int Measuring_2 = N_MEASUREMENT_NONE;
185 int Measuring_3 = N_MEASUREMENT_NONE; 183 int Measuring_3 = N_MEASUREMENT_NONE;
186 184
185 double Ndiv = 8.0;
186
187 int nobs = 0;
188 int settling = 0;
189
187 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3; 190 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3;
188 191
189 double N_1=0.0, N_2=0.0, N_3=0.0; 192 double N_1=0.0, N_2=0.0, N_3=0.0;
190 double SlopeTime1=40.0, DeltaT_1=20.0, delta_f_lock_1=500.0, t1_1=0.0, t2_1=0.0, t3_1=0.0; 193 double SlopeTime1=40.0, DeltaT_1=20.0, delta_f_lock_1=500.0;
191 double SlopeTime2=40.0, DeltaT_2=20.0, delta_f_lock_2=500.0, t1_2=0.0, t2_2=0.0, t3_2=0.0; 194 double SlopeTime2=40.0, DeltaT_2=20.0, delta_f_lock_2=500.0;
192 double SlopeTime3=40.0, DeltaT_3=20.0, delta_f_lock_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0; 195 double SlopeTime3=40.0, DeltaT_3=20.0, delta_f_lock_3=500.0;
193
194 int n_1=0, n_2=0, n_3=0;
195 196
196 double DeltaDDS3=0.0; 197 double DeltaDDS3=0.0;
197 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; 198 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6;
198 199
200 double t1, t2, t3;
199 double f_rep_slope, f_beat_slope; 201 double f_rep_slope, f_beat_slope;
200 double f_rep_plus, f_rep_minus; 202 double f_rep_plus, f_rep_minus;
201 double f_beat_plus, f_beat_minus; 203 double f_beat_plus, f_beat_minus;
202 204
203 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; 205 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0;
430 432
431 if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) 433 if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
432 return -1; 434 return -1;
433 if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0) 435 if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0)
434 return -1; 436 return -1;
435 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0) 437 if ((EstimateNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN)) < 0)
436 return -1; 438 return -1;
437 if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0) 439 if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0)
438 return -1; 440 return -1;
439 441
440 // initialize 4x AD9959 DDS box 442 // initialize 4x AD9959 DDS box
728 // initialization step 730 // initialization step
729 731
730 // set DDS1 to nominal frequency 732 // set DDS1 to nominal frequency
731 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 733 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1);
732 734
735 // record current DDS frequencies
733 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 736 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2);
734 t1_1 = utc; 737
735 t2_1 = 0.0; 738 t1 = utc;
736 t3_1 = 0.0; 739 t2 = t3 = 0.0;
740 nobs = 0;
737 stat_zero(&stat_math1); 741 stat_zero(&stat_math1);
742 f_rep_plus = f_rep_minus = 0.0;
738 743
739 // next step 744 // next step
740 Measuring_1 += 1; 745 Measuring_1 += 1;
741 break; 746 break;
742 747
743 case N_MEASUREMENT_SLOPE: 748 case N_MEASUREMENT_SLOPE:
744 // slope measurement 749 // slope measurement
745 750
746 stat_accumulate(&stat_math1, Math1); 751 stat_accumulate(&stat_math1, Math1);
747 752
748 if ((utc - t1_1) > SlopeTime1) { 753 if ((utc - t1) > SlopeTime1) {
749 f_rep_slope = stat_math1.slope; 754 f_rep_slope = stat_math1.slope;
750 755
751 // frep positive step 756 // frep positive step
752 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE); 757 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE);
753 758
780 // frep positive step 785 // frep positive step
781 786
782 if (settling-- > 0) 787 if (settling-- > 0)
783 break; 788 break;
784 789
785 if (t2_1 == 0.0) 790 if (t2 == 0.0)
786 t2_1 = utc; 791 t2 = utc;
787 792
788 f_rep_plus += Math1 - f_rep_slope * (utc - t2_1); 793 f_rep_plus += Math1 - f_rep_slope * (utc - t2);
789 n_1 += 1; 794 nobs += 1;
790 795
791 if ((utc - t2_1) > DeltaT_1) { 796 if ((utc - t2) > DeltaT_1) {
792 f_rep_plus = f_rep_plus / n_1; 797 f_rep_plus = f_rep_plus / nobs;
793 n_1 = 0; 798 nobs = 0;
794 799
795 // frep negative step 800 // frep negative step
796 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE); 801 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE);
797 802
798 // allow counter to settle 803 // allow counter to settle
807 // frep negative step 812 // frep negative step
808 813
809 if (settling-- > 0) 814 if (settling-- > 0)
810 break; 815 break;
811 816
812 if (t3_1 == 0.0) 817 if (t3 == 0.0)
813 t3_1 = utc; 818 t3 = utc;
814 819
815 f_rep_minus += Math1 - f_rep_slope * (utc - t2_1); 820 f_rep_minus += Math1 - f_rep_slope * (utc - t2);
816 n_1 += 1; 821 nobs += 1;
817 822
818 if ((utc - t3_1) > DeltaT_1) { 823 if ((utc - t3) > DeltaT_1) {
819 f_rep_minus = f_rep_minus / n_1; 824 f_rep_minus = f_rep_minus / nobs;
820 n_1 = 0; 825 nobs = 0;
821 826
822 // compute N1 827 // compute N1
823 double delta_f_rep = f_rep_minus - f_rep_plus; 828 double delta_f_rep = f_rep_minus - f_rep_plus;
824 N_1 = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep; 829 N_1 = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep;
825 SetCtrlVal(CalcNPanel, CALCN_N, N_1); 830 SetCtrlVal(CalcNPanel, CALCN_N, N_1);
826
827 t1_1 = t2_1 = t3_1 = 0.0;
828 f_rep_minus = f_rep_plus = 0.0;
829 831
830 // back to nominal frep 832 // back to nominal frep
831 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 833 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
832 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 834 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
833 835
847 // initialization step 849 // initialization step
848 850
849 // set DDS1 to nominal frequency 851 // set DDS1 to nominal frequency
850 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 852 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1);
851 853
854 // record current DDS frequencies
852 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); 855 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2);
853 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 856 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3);
854 t1_2 = utc; 857
858 t1 = utc;
859 t2 = t3 = 0.0;
860 nobs = 0;
855 stat_zero(&stat_math1); 861 stat_zero(&stat_math1);
856 stat_zero(&stat_ch2); 862 stat_zero(&stat_ch2);
857 863 f_rep_plus = f_rep_minus = 0.0;
858 Nu1 = N1 * (250000000 + Math1); 864 f_beat_plus = f_beat_minus = 0.0;
859 865
860 // next step 866 // next step
861 Measuring_2 += 1; 867 Measuring_2 += 1;
862 break; 868 break;
863 869
865 // slope measurement 871 // slope measurement
866 872
867 stat_accumulate(&stat_math1, Math1); 873 stat_accumulate(&stat_math1, Math1);
868 stat_accumulate(&stat_ch2, Ch2); 874 stat_accumulate(&stat_ch2, Ch2);
869 875
870 if ((utc - t1_2) > SlopeTime2) { 876 if ((utc - t1) > SlopeTime2) {
871 f_rep_slope = stat_math1.slope; 877 f_rep_slope = stat_math1.slope;
872 f_beat_slope = stat_ch2.slope; 878 f_beat_slope = stat_ch2.slope;
873 879
874 // frep positive step 880 // frep positive step
875 double fDDS1 = f0_DDS1 + delta_f_lock_2; 881 double fDDS1 = f0_DDS1 + delta_f_lock_2;
876 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE); 882 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE);
877 883
878 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 884 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
879 double fDDS3 = f0_DDS3 - delta_f_lock_2 *(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - f_beat_slope * (utc-t1_2); 885 double fDDS3 = f0_DDS3 + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2;
880 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 886 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3);
881 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 887 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
882 888
883 // allow counter to settle 889 // allow counter to settle
884 settling = 3; 890 settling = 3;
913 // frep positive step 919 // frep positive step
914 920
915 if (settling-- > 0) 921 if (settling-- > 0)
916 break; 922 break;
917 923
918 if (t2_1 == 0.0) 924 if (t2 == 0.0)
919 t2_1 = utc; 925 t2 = utc;
920 926
921 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2_2); 927 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
922 f_beat_plus += Ch2 - f_beat_slope * (utc - t2_2); 928 f_beat_plus += Ch2 - f_beat_slope * (utc - t2);
923 n_2 += 1; 929 nobs += 1;
924 930
925 if ((utc - t2_2) > DeltaT_2) { 931 if ((utc - t2) > DeltaT_2) {
926 f_rep_plus = f_rep_plus / n_2; 932 f_rep_plus = f_rep_plus / nobs;
927 f_beat_plus = f_beat_plus / n_2; 933 f_beat_plus = f_beat_plus / nobs;
928 n_2 = 0; 934 nobs = 0;
929 935
930 // negative frequency step 936 // negative frequency step
931 double fDDS1 = f0_DDS1 - delta_f_lock_2; 937 double fDDS1 = f0_DDS1 - delta_f_lock_2;
932 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); 938 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE);
933 939
934 // adjust DDS3 to keep beatnote within the bandpass filter. prediction 940 // adjust DDS3 to keep beatnote within the bandpass filter. prediction
935 double fDDS3 = f0_DDS3 + delta_f_lock_2 *(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); 941 double fDDS3 = f0_DDS3 - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock_2;
936 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); 942 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3);
937 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); 943 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
938 944
939 // allow counter to settle 945 // allow counter to settle
940 settling = 3; 946 settling = 3;
948 // frep negative step 954 // frep negative step
949 955
950 if (settling-- > 0) 956 if (settling-- > 0)
951 break; 957 break;
952 958
953 if (t3_1 == 0.0) 959 if (t3 == 0.0)
954 t3_1 = utc; 960 t3 = utc;
955 961
956 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2_2); 962 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
957 f_beat_minus += Ch2 + f_beat_slope * (utc - t2_2); 963 f_beat_minus += Ch2 + f_beat_slope * (utc - t2);
958 n_2 += 1; 964 nobs += 1;
959 965
960 if ((utc -t3_2) > DeltaT_2) { 966 if ((utc -t3) > DeltaT_2) {
961 f_rep_minus = f_rep_minus / n_2; 967 f_rep_minus = f_rep_minus / nobs;
962 f_beat_minus = f_beat_minus / n_2; 968 f_beat_minus = f_beat_minus / nobs;
963 n_2 = 0; 969 nobs = 0;
964 970
965 // compute N2 971 // compute N2
966 double delta_f_rep = f_rep_minus - f_rep_plus; 972 double delta_f_rep = f_rep_minus - f_rep_plus;
967 N_2 = -Sign2 * (DeltaDDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; 973 N_2 = -Sign2 * (DeltaDDS3 + f_beat_minus - f_beat_plus) / delta_f_rep;
968 SetCtrlVal(CalcNPanel, CALCN_N, N_2); 974 SetCtrlVal(CalcNPanel, CALCN_N, N_2);
970 // back to nominal frequency 976 // back to nominal frequency
971 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 977 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
972 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 978 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
973 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 979 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3);
974 980
975 t1_2 = t2_2 = t3_2 = 0.0;
976 f_rep_minus = f_rep_plus = 0.0;
977 f_beat_minus = f_beat_plus = 0.0;
978
979 // done 981 // done
980 Measuring_2 = N_MEASUREMENT_NONE; 982 Measuring_2 = N_MEASUREMENT_NONE;
981 } 983 }
982 break; 984 break;
983 } 985 }
989 break; 991 break;
990 992
991 case N_MEASUREMENT_INIT: 993 case N_MEASUREMENT_INIT:
992 // init 994 // init
993 995
996 // set DDS1 to nominal frequency
994 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); 997 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1);
995 settling = 3; 998
996 999 // record current DDS frequencies
997 t1_3 = utc; 1000 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2);
1001 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3);
1002
1003 t1 = utc;
1004 t2 = t3 = 0.0;
1005 nobs = 0;
998 stat_zero(&stat_math1); 1006 stat_zero(&stat_math1);
999 stat_zero(&stat_ch3); 1007 stat_zero(&stat_ch3);
1000 f_rep_plus = f_rep_minus = 0.0; 1008 f_rep_plus = f_rep_minus = 0.0;
1001 f_beat_plus = f_beat_minus = 0.0; 1009 f_beat_plus = f_beat_minus = 0.0;
1002 1010
1003 // record current DDS frequencies
1004 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2);
1005 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3);
1006
1007 // next step 1011 // next step
1008 Measuring_3 += 1; 1012 Measuring_3 += 1;
1009 break; 1013 break;
1010 1014
1011 case N_MEASUREMENT_SLOPE: 1015 case N_MEASUREMENT_SLOPE:
1015 break; 1019 break;
1016 1020
1017 stat_accumulate(&stat_math1, Math1); 1021 stat_accumulate(&stat_math1, Math1);
1018 stat_accumulate(&stat_ch3, Ch3); 1022 stat_accumulate(&stat_ch3, Ch3);
1019 1023
1020 if (utc - t1_3 > SlopeTime3) { 1024 if (utc - t1 > SlopeTime3) {
1021 // slope measurement 1025 // slope measurement
1022 f_rep_slope = stat_math1.slope; 1026 f_rep_slope = stat_math1.slope;
1027 f_beat_slope = stat_ch3.slope;
1028
1023 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); 1029 logmsg("f_rep_slope=%e Hz/s", f_rep_slope);
1024 f_beat_slope = stat_ch3.slope;
1025 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); 1030 logmsg("f_beat_slope=%e Hz/s", f_rep_slope);
1026
1027 t2_3 = utc;
1028 1031
1029 // frep positive step 1032 // frep positive step
1030 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE); 1033 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE);
1031 1034
1032 // adjust DDS3 to keep beatnote within the bandpass filter 1035 // adjust DDS3 to keep beatnote within the bandpass filter
1062 case N_MEASUREMENT_FREP_PLUS: 1065 case N_MEASUREMENT_FREP_PLUS:
1063 // frep positive step 1066 // frep positive step
1064 1067
1065 if (settling-- > 0) 1068 if (settling-- > 0)
1066 break; 1069 break;
1067 1070
1068 n_3++; 1071 if (t2 == 0.0)
1069 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); 1072 t2 = utc;
1070 f_beat_plus += Ch3 - f_beat_slope * (utc - t3_2); 1073
1071 1074 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1072 if (utc - t2_3 > DeltaT_3) { 1075 f_beat_plus += Ch3 - f_beat_slope * (utc - t2);
1073 // positive step measurement 1076 nobs += 1;
1074 f_rep_plus = f_rep_plus / n_3; 1077
1075 f_beat_plus = f_beat_plus / n_3; 1078 if (utc - t2 > DeltaT_3) {
1076 1079 f_rep_plus = f_rep_plus / nobs;
1077 n_3 = 0; 1080 f_beat_plus = f_beat_plus / nobs;
1078 t3_3 = utc; 1081 nobs = 0;
1079 1082
1080 // frep negative step 1083 // frep negative step
1081 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE); 1084 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE);
1082 1085
1083 // adjust DDS3 to keep beatnote within the bandpass filter 1086 // adjust DDS3 to keep beatnote within the bandpass filter
1096 // frep negative step 1099 // frep negative step
1097 1100
1098 if (settling-- > 0) 1101 if (settling-- > 0)
1099 break; 1102 break;
1100 1103
1101 n_3++; 1104 if (t3 == 0.0)
1102 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); 1105 t3 = utc;
1103 f_beat_minus += Ch3 - f_beat_slope * (utc - t3_2); 1106
1104 1107 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1105 if (utc - t3_3 > DeltaT_3) { 1108 f_beat_minus += Ch3 - f_beat_slope * (utc - t2);
1106 // negative step measurement 1109 nobs += 1;
1107 f_rep_minus = f_rep_minus / n_3; 1110
1108 f_beat_minus = f_beat_minus / n_3; 1111 if (utc - t3 > DeltaT_3) {
1112 f_rep_minus = f_rep_minus / nobs;
1113 f_beat_minus = f_beat_minus / nobs;
1114 nobs = 0;
1109 1115
1110 // check delta frep 1116 // check delta frep
1111 double delta_f_rep_m = f_rep_plus - f_rep_minus; 1117 double delta_f_rep_m = f_rep_plus - f_rep_minus;
1112 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; 1118 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1;
1113 logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e", 1119 logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e",
1122 logmsg("delta fbeat: measured=%.12e expected=%.12e difference=%.12e", 1128 logmsg("delta fbeat: measured=%.12e expected=%.12e difference=%.12e",
1123 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); 1129 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected);
1124 N_3 = delta_f_beat / delta_f_rep; 1130 N_3 = delta_f_beat / delta_f_rep;
1125 logmsg("measured N3=%.3f", N_3); 1131 logmsg("measured N3=%.3f", N_3);
1126 SetCtrlVal(CalcNPanel, CALCN_N, N_3); 1132 SetCtrlVal(CalcNPanel, CALCN_N, N_3);
1127
1128 t1_3=0.0;
1129 t2_3=0.0;
1130 t3_3=0.0;
1131 n_3 = 0;
1132 1133
1133 // back to nominal frep 1134 // back to nominal frep
1134 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1135 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
1135 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1136 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
1136 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1137 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3);
1552 } 1553 }
1553 1554
1554 int CVICALLBACK CB_OnAcceptN (int panel, int control, int event, 1555 int CVICALLBACK CB_OnAcceptN (int panel, int control, int event,
1555 void *callbackData, int eventData1, int eventData2) 1556 void *callbackData, int eventData1, int eventData2)
1556 { 1557 {
1558 int measure;
1559
1557 switch (event) { 1560 switch (event) {
1558 case EVENT_COMMIT: 1561 case EVENT_COMMIT:
1559 switch (measuring) { 1562 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure);
1560 case MEASURING_N_Lo: 1563 switch (measure) {
1564 case N_LO:
1561 N1 = round(N_1); 1565 N1 = round(N_1);
1562 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1); 1566 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1);
1563 break; 1567 break;
1564 case MEASURING_N_Hg: 1568 case N_HG:
1565 N2 = round(N_2); 1569 N2 = round(N_2);
1566 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2); 1570 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2);
1567 break; 1571 break;
1568 case MEASURING_N_Sr: 1572 case N_SR:
1569 N3 = round(N_3); 1573 N3 = round(N_3);
1570 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); 1574 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3);
1571 break; 1575 break;
1572 } 1576 }
1573 break; 1577 break;
1585 case EVENT_COMMIT: 1589 case EVENT_COMMIT:
1586 switch (control) { 1590 switch (control) {
1587 case PANEL_N1CALCULUS: 1591 case PANEL_N1CALCULUS:
1588 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1592 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1589 if (! visible) { 1593 if (! visible) {
1590 measuring = MEASURING_N_Lo; 1594 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_LO);
1591 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); 1595 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo");
1592 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); 1596 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1);
1593 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); 1597 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1);
1594 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); 1598 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0);
1595 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1599 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1597 } 1601 }
1598 break; 1602 break;
1599 case PANEL_N2CALCULUS: 1603 case PANEL_N2CALCULUS:
1600 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1604 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1601 if (! visible) { 1605 if (! visible) {
1602 measuring = MEASURING_N_Hg; 1606 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_HG);
1603 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); 1607 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg");
1604 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); 1608 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2);
1605 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); 1609 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2);
1606 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); 1610 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0);
1607 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1611 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1609 } 1613 }
1610 break; 1614 break;
1611 case PANEL_N3CALCULUS: 1615 case PANEL_N3CALCULUS:
1612 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1616 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1613 if (! visible) { 1617 if (! visible) {
1614 measuring = MEASURING_N_Sr; 1618 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_SR);
1615 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); 1619 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr");
1616 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); 1620 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3);
1617 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); 1621 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3);
1618 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); 1622 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0);
1619 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1623 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1627 } 1631 }
1628 1632
1629 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, 1633 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event,
1630 void *callbackData, int eventData1, int eventData2) 1634 void *callbackData, int eventData1, int eventData2)
1631 { 1635 {
1636 int measuring;
1637
1632 switch (event) { 1638 switch (event) {
1633 case EVENT_COMMIT: 1639 case EVENT_COMMIT:
1640 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring);
1634 switch (measuring) { 1641 switch (measuring) {
1635 case MEASURING_N_Lo: 1642 case N_LO:
1636 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); 1643 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1);
1637 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); 1644 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1);
1638 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); 1645 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1);
1639 // convert from kHz to Hz 1646 // convert from kHz to Hz
1640 delta_f_lock_1 = delta_f_lock_1 * 1000.0; 1647 delta_f_lock_1 = delta_f_lock_1 * 1000.0;
1641 Measuring_1 = TRUE; 1648 Measuring_1 = TRUE;
1642 break; 1649 break;
1643 case MEASURING_N_Hg: 1650 case N_HG:
1644 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); 1651 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2);
1645 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); 1652 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2);
1646 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2); 1653 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2);
1647 // convert from kHz to Hz 1654 // convert from kHz to Hz
1648 delta_f_lock_2 = delta_f_lock_2 * 1000.0; 1655 delta_f_lock_2 = delta_f_lock_2 * 1000.0;
1649 Measuring_2 = TRUE; 1656 Measuring_2 = TRUE;
1650 break; 1657 break;
1651 case MEASURING_N_Sr: 1658 case N_SR:
1652 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); 1659 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3);
1653 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); 1660 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3);
1654 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3); 1661 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3);
1655 // convert from kHz to Hz 1662 // convert from kHz to Hz
1656 delta_f_lock_3 = delta_f_lock_3 * 1000.0; 1663 delta_f_lock_3 = delta_f_lock_3 * 1000.0;
1663 } 1670 }
1664 1671
1665 int CVICALLBACK CB_OnNStop (int panel, int control, int event, 1672 int CVICALLBACK CB_OnNStop (int panel, int control, int event,
1666 void *callbackData, int eventData1, int eventData2) 1673 void *callbackData, int eventData1, int eventData2)
1667 { 1674 {
1675 int measuring;
1676
1668 switch (event) { 1677 switch (event) {
1669 case EVENT_COMMIT: 1678 case EVENT_COMMIT:
1670 HidePanel(CalcNPanel); 1679 HidePanel(CalcNPanel);
1680 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring);
1671 switch (measuring) { 1681 switch (measuring) {
1672 case MEASURING_N_Lo: 1682 case N_LO:
1673 Measuring_1 = FALSE; 1683 Measuring_1 = FALSE;
1674 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1684 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
1675 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1685 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
1676 break; 1686 break;
1677 case MEASURING_N_Hg: 1687 case N_HG:
1678 Measuring_2 = FALSE; 1688 Measuring_2 = FALSE;
1679 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1689 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
1680 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1690 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
1681 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1691 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3);
1682 break; 1692 break;
1683 case MEASURING_N_Sr: 1693 case N_SR:
1684 Measuring_3 = FALSE; 1694 Measuring_3 = FALSE;
1685 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); 1695 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE);
1686 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); 1696 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2);
1687 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); 1697 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3);
1688 break; 1698 break;
1906 1916
1907 int CVICALLBACK CB_OnEstimateN (int panel, int control, int event, 1917 int CVICALLBACK CB_OnEstimateN (int panel, int control, int event,
1908 void *callbackData, int eventData1, int eventData2) 1918 void *callbackData, int eventData1, int eventData2)
1909 { 1919 {
1910 int visible; 1920 int visible;
1911 double wl; 1921
1912 1922 switch (event)
1913 switch (event) 1923 {
1914 { 1924 case EVENT_COMMIT:
1915 case EVENT_COMMIT: 1925 GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible);
1916 // be prepared to support more N estimates for different beat notes 1926 if (! visible)
1917 switch (control) 1927 DisplayPanel(EstimateNPanel);
1918 { 1928 // reset N estimate
1929 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0);
1930 // set current frep
1931 SetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, 250e6 + Math1);
1932 switch (control) {
1933 case PANEL_ESTIMATE_N2:
1934 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH);
1935 SetPanelAttribute(panel, ATTR_TITLE, "Estimate N_Hg");
1936 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_HG);
1937 break;
1919 case PANEL_ESTIMATE_N3: 1938 case PANEL_ESTIMATE_N3:
1920 GetPanelAttribute(EstimateN3Panel, ATTR_VISIBLE , &visible); 1939 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH);
1921 if (! visible) 1940 SetPanelAttribute(panel, ATTR_TITLE, "Estimate N_Sr");
1922 DisplayPanel(EstimateN3Panel); 1941 SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_SR);
1923 // set current frep
1924 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_FREP, 250e6 + Math1);
1925 // default wavelenght for Sr cavity
1926 GetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, &wl);
1927 if (wl == 0.0)
1928 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, 698.446);
1929 // reset N3 estimate
1930 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_N, 0.0);
1931 break; 1942 break;
1932 } 1943 }
1933 break; 1944 break;
1934 } 1945 }
1935
1936 return 0; 1946 return 0;
1937 } 1947 }
1938 1948
1939 int CVICALLBACK CB_OnNEstimateCancel (int panel, int control, int event, 1949 int CVICALLBACK CB_OnNEstimateCancel (int panel, int control, int event,
1940 void *callbackData, int eventData1, int eventData2) 1950 void *callbackData, int eventData1, int eventData2)
1953 } 1963 }
1954 1964
1955 int CVICALLBACK CB_OnNEstimateSet (int panel, int control, int event, 1965 int CVICALLBACK CB_OnNEstimateSet (int panel, int control, int event,
1956 void *callbackData, int eventData1, int eventData2) 1966 void *callbackData, int eventData1, int eventData2)
1957 { 1967 {
1958 switch (event) 1968 int estimate;
1959 { 1969
1960 case EVENT_COMMIT: 1970 switch (event)
1961 GetCtrlVal(panel, ESTIMATEN3_N, &N3); 1971 {
1962 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); 1972 case EVENT_COMMIT:
1973 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate);
1974 switch (estimate) {
1975 case N_HG:
1976 GetCtrlVal(panel, ESTIMATEN_N, &N2);
1977 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N2);
1978 break;
1979 case N_SR:
1980 GetCtrlVal(panel, ESTIMATEN_N, &N3);
1981 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3);
1982 break;
1983 }
1963 HidePanel(panel); 1984 HidePanel(panel);
1964 break; 1985 break;
1965 } 1986 }
1966 return 0; 1987 return 0;
1967 } 1988 }
1972 double frep, wl, N; 1993 double frep, wl, N;
1973 1994
1974 switch (event) 1995 switch (event)
1975 { 1996 {
1976 case EVENT_COMMIT: 1997 case EVENT_COMMIT:
1977 GetCtrlVal(panel, ESTIMATEN3_FREP, &frep); 1998 GetCtrlVal(panel, ESTIMATEN_FREP, &frep);
1978 GetCtrlVal(panel, ESTIMATEN3_WAVELENGTH, &wl); 1999 GetCtrlVal(panel, ESTIMATEN_WAVELENGTH, &wl);
1979 N = round(299792458.0 / wl / 1e-9 / frep); 2000 N = round(SPEED_OF_LIGHT / wl / 1e-9 / frep);
1980 SetCtrlVal(panel, ESTIMATEN3_N, N); 2001 SetCtrlVal(panel, ESTIMATEN_N, N);
1981 break; 2002 break;
1982 } 2003 }
1983 return 0; 2004 return 0;
1984 } 2005 }
1985 2006