Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 158:9154291658ef
Simplify DDS frequency juggling in N measurement
Clarify variable names. Update display at the end of the cicle with actual
frequency values. Remove unnecessary SetFrequency() calls after RampFrequency().
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 03 Feb 2014 15:22:35 +0100 |
parents | 4ab8099a18e2 |
children | 07153c41ba16 |
comparison
equal
deleted
inserted
replaced
157:f4633519a628 | 158:9154291658ef |
---|---|
182 | 182 |
183 int Measuring_1 = N_MEASUREMENT_NONE; | 183 int Measuring_1 = N_MEASUREMENT_NONE; |
184 int Measuring_2 = N_MEASUREMENT_NONE; | 184 int Measuring_2 = N_MEASUREMENT_NONE; |
185 int Measuring_3 = N_MEASUREMENT_NONE; | 185 int Measuring_3 = N_MEASUREMENT_NONE; |
186 | 186 |
187 double FrequDDS1=110000000.0; | 187 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3; |
188 | |
188 double Slope_1=0.0, Slope_2=0.0, Slope_3=0.0, Beatslope_2=0.0; | 189 double Slope_1=0.0, Slope_2=0.0, Slope_3=0.0, Beatslope_2=0.0; |
189 double SlopeTime1=40.0, SlopeTime2=40.0, SlopeTime3=40.0; | 190 double SlopeTime1=40.0, SlopeTime2=40.0, SlopeTime3=40.0; |
190 double Ch4Slope = 0.0; | 191 double Ch4Slope = 0.0; |
191 | 192 |
192 double N_1=0.0, N_2=0.0, N_3=0.0; | 193 double N_1=0.0, N_2=0.0, N_3=0.0; |
193 double DeltaT_1=20.0, DeltakHz_1=500.0, t1_1=0.0, t2_1=0.0, t3_1=0.0, Frepplus_1=0.0, Frepminus_1=0.0; | 194 double DeltaT_1=20.0, DeltakHz_1=500.0, t1_1=0.0, t2_1=0.0, t3_1=0.0, Frepplus_1=0.0, Frepminus_1=0.0; |
194 double DeltaT_2=20.0, DeltakHz_2=500.0, t1_2=0.0, t2_2=0.0, t3_2=0.0, Frepplus_2=0.0, Frepminus_2=0.0; | 195 double DeltaT_2=20.0, DeltakHz_2=500.0, t1_2=0.0, t2_2=0.0, t3_2=0.0, Frepplus_2=0.0, Frepminus_2=0.0; |
195 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0; | 196 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0; |
196 | 197 |
197 int n_1=0, n_2=0, n_3=0; | 198 int n_1=0, n_2=0, n_3=0; |
198 | |
199 double FrequencyDDSBesInit = 0.0; | |
200 double FrequencyDDS3Init = 0.0; | |
201 | 199 |
202 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0; | 200 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0; |
203 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; | 201 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; |
204 | 202 |
205 double f_rep_slope, f_beat_slope; | 203 double f_rep_slope, f_beat_slope; |
248 .keep_freq = TRUE, | 246 .keep_freq = TRUE, |
249 .keep_slope = TRUE, | 247 .keep_slope = TRUE, |
250 .freq0 = 70e6, | 248 .freq0 = 70e6, |
251 .threshold = 100.0, | 249 .threshold = 100.0, |
252 .applied = 0.0, | 250 .applied = 0.0, |
253 .interval = 40.0, | 251 .interval = 30.0, |
254 .t0 = 0.0 | 252 .t0 = 0.0 |
255 }; | 253 }; |
256 | 254 |
257 | 255 |
258 // recenter | 256 // recenter |
708 | 706 |
709 // update display. numeric controllers do not format values | 707 // update display. numeric controllers do not format values |
710 // with a thousands separator: use string controllers and a | 708 // with a thousands separator: use string controllers and a |
711 // custom formatting function | 709 // custom formatting function |
712 char buffer[256]; | 710 char buffer[256]; |
713 SetCtrlVal(MainPanel,PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.6f", Math1)); | 711 SetCtrlVal(MainPanel, PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.6f", Math1)); |
714 SetCtrlVal(MainPanel,PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2)); | 712 SetCtrlVal(MainPanel, PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2)); |
715 SetCtrlVal(MainPanel,PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3)); | 713 SetCtrlVal(MainPanel, PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3)); |
716 SetCtrlVal(MainPanel,PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4)); | 714 SetCtrlVal(MainPanel, PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4)); |
717 SetCtrlVal(MainPanel,PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5)); | 715 SetCtrlVal(MainPanel, PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5)); |
718 | 716 |
719 // update timeseries plots | 717 // update timeseries plots |
720 for (struct plot *plot = plots; plot->data; plot++) | 718 for (struct plot *plot = plots; plot->data; plot++) |
721 plot_update(plot); | 719 plot_update(plot); |
722 | 720 |
734 | 732 |
735 case N_MEASUREMENT_INIT: | 733 case N_MEASUREMENT_INIT: |
736 // initialization step | 734 // initialization step |
737 | 735 |
738 // set DDS1 to nominal frequency | 736 // set DDS1 to nominal frequency |
739 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | |
740 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 737 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); |
741 | 738 |
742 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit); | 739 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
743 t2_1 = t3_1 = 0.0; | |
744 t1_1 = utc; | 740 t1_1 = utc; |
745 | 741 t2_1 = 0.0; |
742 t3_1 = 0.0; | |
746 stat_zero(&stat_math1); | 743 stat_zero(&stat_math1); |
747 stat_zero(&stat_ch4); | 744 stat_zero(&stat_ch4); |
748 | 745 |
749 // next step | 746 // next step |
750 Measuring_1 += 1; | 747 Measuring_1 += 1; |
757 stat_accumulate(&stat_ch4, Ch4); | 754 stat_accumulate(&stat_ch4, Ch4); |
758 | 755 |
759 if ((utc - t1_1) > SlopeTime1) { | 756 if ((utc - t1_1) > SlopeTime1) { |
760 Slope_1 = stat_math1.slope; | 757 Slope_1 = stat_math1.slope; |
761 Ch4Slope = stat_ch4.slope; | 758 Ch4Slope = stat_ch4.slope; |
762 SetCtrlVal(CalcNPanel, CALCN_SLOPE, Slope_1); | |
763 | 759 |
764 // frep positive step | 760 // frep positive step |
765 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_1 * 1000.0, FREP_STEP_SIZE); | 761 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + DeltakHz_1 * 1000.0, FREP_STEP_SIZE); |
766 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 + DeltakHz_1 * 1000.0); | |
767 | 762 |
768 // allow counter to settle | 763 // allow counter to settle |
769 settling = 3; | 764 settling = 3; |
770 | 765 |
771 // next step | 766 // next step |
781 settling--; | 776 settling--; |
782 break; | 777 break; |
783 } | 778 } |
784 | 779 |
785 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 780 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
786 fDDS2 += 275000 - Ch4; | 781 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2 + 275000 - Ch4); |
787 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2); | |
788 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | |
789 | 782 |
790 // allow counter to settle | 783 // allow counter to settle |
791 settling = 3; | 784 settling = 3; |
792 | 785 |
793 // next step | 786 // next step |
813 Frepplus_1 = Frepplus_1 / n_1; | 806 Frepplus_1 = Frepplus_1 / n_1; |
814 Ch4Plus = Ch4Plus / n_1; | 807 Ch4Plus = Ch4Plus / n_1; |
815 n_1 = 0; | 808 n_1 = 0; |
816 | 809 |
817 // frep negative step | 810 // frep negative step |
818 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_1 * 1000.0, FREP_STEP_SIZE); | 811 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - DeltakHz_1 * 1000.0, FREP_STEP_SIZE); |
819 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 - DeltakHz_1 * 1000.0); | |
820 | 812 |
821 // allow counter to settle | 813 // allow counter to settle |
822 settling = 3; | 814 settling = 3; |
823 | 815 |
824 // next step | 816 // next step |
855 t3_1 = 0.0; | 847 t3_1 = 0.0; |
856 Frepminus_1 = 0.0; | 848 Frepminus_1 = 0.0; |
857 Frepplus_1 = 0.0; | 849 Frepplus_1 = 0.0; |
858 | 850 |
859 // back to nominal frep | 851 // back to nominal frep |
860 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE); | 852 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
861 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 853 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
862 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | |
863 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
864 | 854 |
865 // done | 855 // done |
866 Measuring_1 = N_MEASUREMENT_NONE; | 856 Measuring_1 = N_MEASUREMENT_NONE; |
867 } | 857 } |
868 break; | 858 break; |
876 | 866 |
877 case N_MEASUREMENT_INIT: | 867 case N_MEASUREMENT_INIT: |
878 // initialization step | 868 // initialization step |
879 | 869 |
880 // set DDS1 to nominal frequency | 870 // set DDS1 to nominal frequency |
881 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 871 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); |
882 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 872 |
883 | 873 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
884 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit); | 874 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
885 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init); | |
886 t1_2 = utc; | 875 t1_2 = utc; |
887 | |
888 stat_zero(&stat_math1); | 876 stat_zero(&stat_math1); |
889 stat_zero(&stat_ch2); | 877 stat_zero(&stat_ch2); |
890 | 878 |
891 Nu1 = N1 * (250000000 + Math1); | 879 Nu1 = N1 * (250000000 + Math1); |
892 | 880 |
901 stat_accumulate(&stat_ch2, Ch2); | 889 stat_accumulate(&stat_ch2, Ch2); |
902 | 890 |
903 if ((utc - t1_2) > SlopeTime2) { | 891 if ((utc - t1_2) > SlopeTime2) { |
904 Slope_2 = stat_math1.slope; | 892 Slope_2 = stat_math1.slope; |
905 Beatslope_2 = stat_ch2.slope; | 893 Beatslope_2 = stat_ch2.slope; |
906 SetCtrlVal(CalcNPanel, CALCN_SLOPE, Beatslope_2); | |
907 | 894 |
908 // frep positive step | 895 // frep positive step |
909 double fDDS1 = FrequDDS1 + DeltakHz_2 * 1000; | 896 double fDDS1 = f0_DDS1 + DeltakHz_2 * 1000; |
910 printf("fDDS1 = %g\n", fDDS1); | |
911 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE); | 897 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE); |
912 SetCtrlVal(MainPanel, PANEL_DDS1, fDDS1); | |
913 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, fDDS1); | |
914 | 898 |
915 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 899 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
916 double fDDS3 = FrequencyDDS3Init - DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2); | 900 double fDDS3 = f0_DDS3 - DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2); |
917 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 901 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
918 printf("deltaDDS3 = %g\n", DeltaDDS3); | |
919 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); | |
920 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 902 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
921 | 903 |
922 // allow counter to settle | 904 // allow counter to settle |
923 settling = 3; | 905 settling = 3; |
924 | 906 |
935 settling--; | 917 settling--; |
936 break; | 918 break; |
937 } | 919 } |
938 | 920 |
939 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; | 921 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; |
940 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2); | |
941 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | 922 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); |
942 | 923 |
943 double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; | 924 double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; |
944 DeltaDDS3 = DeltaDDS3 + 10000 - Ch2; | 925 DeltaDDS3 = DeltaDDS3 + 10000 - Ch2; |
945 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); | |
946 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 926 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
947 | 927 |
948 // allow counter to settle | 928 // allow counter to settle |
949 settling = 3; | 929 settling = 3; |
950 | 930 |
971 Frepplus_2 = Frepplus_2 / n_2; | 951 Frepplus_2 = Frepplus_2 / n_2; |
972 Delta10K_Plus = Delta10K_Plus / n_2; | 952 Delta10K_Plus = Delta10K_Plus / n_2; |
973 n_2 = 0; | 953 n_2 = 0; |
974 | 954 |
975 // negative frequency step | 955 // negative frequency step |
976 double fDDS1 = FrequDDS1 - DeltakHz_2 * 1000; | 956 double fDDS1 = f0_DDS1 - DeltakHz_2 * 1000; |
977 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); | 957 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); |
978 SetCtrlVal(MainPanel, PANEL_DDS1, fDDS1); | |
979 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, fDDS1); | |
980 | 958 |
981 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 959 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
982 double fDDS3 = FrequencyDDS3Init + DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); | 960 double fDDS3 = f0_DDS3 + DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); |
983 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 961 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
984 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); | |
985 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 962 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
986 | 963 |
987 // allow counter to settle | 964 // allow counter to settle |
988 settling = 3; | 965 settling = 3; |
989 | 966 |
1015 // compute N2 | 992 // compute N2 |
1016 N_2 = Sign2*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2)); | 993 N_2 = Sign2*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2)); |
1017 SetCtrlVal(CalcNPanel, CALCN_N, N_2); | 994 SetCtrlVal(CalcNPanel, CALCN_N, N_2); |
1018 | 995 |
1019 // back to nominal frequency | 996 // back to nominal frequency |
1020 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE); | 997 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
1021 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 998 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
1022 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 999 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3 - Beatslope_2 * (utc - t1_2)); |
1023 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | |
1024 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
1025 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2)); | |
1026 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2) ); | |
1027 | 1000 |
1028 t1_2 = 0.0; | 1001 t1_2 = 0.0; |
1029 t2_2 = 0.0; | 1002 t2_2 = 0.0; |
1030 t3_2 = 0.0; | 1003 t3_2 = 0.0; |
1031 Frepminus_2 = 0.0; | 1004 Frepminus_2 = 0.0; |
1046 break; | 1019 break; |
1047 | 1020 |
1048 case N_MEASUREMENT_INIT: | 1021 case N_MEASUREMENT_INIT: |
1049 // init | 1022 // init |
1050 | 1023 |
1051 SetCtrlVal(MainPanel, 1, FrequDDS1); | 1024 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); |
1052 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | |
1053 settling = 3; | 1025 settling = 3; |
1054 | 1026 |
1055 t1_3 = utc; | 1027 t1_3 = utc; |
1056 stat_zero(&stat_math1); | 1028 stat_zero(&stat_math1); |
1057 stat_zero(&stat_ch3); | 1029 stat_zero(&stat_ch3); |
1058 f_rep_plus = f_rep_minus = 0.0; | 1030 f_rep_plus = f_rep_minus = 0.0; |
1059 f_beat_Sr_plus = f_beat_Sr_minus = 0.0; | 1031 f_beat_Sr_plus = f_beat_Sr_minus = 0.0; |
1060 | 1032 |
1061 // record current DDS frequencies | 1033 // record current DDS frequencies |
1062 FrequencyDDSBesInit = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 1034 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
1063 FrequencyDDS3Init = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 1035 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
1064 | 1036 |
1065 // next step | 1037 // next step |
1066 Measuring_3 += 1; | 1038 Measuring_3 += 1; |
1067 break; | 1039 break; |
1068 | 1040 |
1085 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); | 1057 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); |
1086 | 1058 |
1087 t2_3 = utc; | 1059 t2_3 = utc; |
1088 | 1060 |
1089 // frep positive step | 1061 // frep positive step |
1090 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 + DeltakHz_3 * 1000); | 1062 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + DeltakHz_3 * 1000, FREP_STEP_SIZE); |
1091 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 + DeltakHz_3 * 1000, FREP_STEP_SIZE); | 1063 |
1092 // compensate with DDS3 to keep measured beatnote in counter box range | 1064 // adjust DDS3 to keep beatnote within the bandpass filter |
1093 double fDDS3 = FrequencyDDS3Init + Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; | 1065 double fDDS3 = f0_DDS3 + Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; |
1094 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); | |
1095 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 1066 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
1096 | 1067 |
1097 // allow counter to settle | 1068 // allow counter to settle |
1098 settling = 3; | 1069 settling = 3; |
1099 | 1070 |
1111 break; | 1082 break; |
1112 } | 1083 } |
1113 | 1084 |
1114 // adjust DDS frequency to keep 55 MHz tracker oscillator locked | 1085 // adjust DDS frequency to keep 55 MHz tracker oscillator locked |
1115 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; | 1086 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; |
1116 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2); | |
1117 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | 1087 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); |
1118 | 1088 |
1119 // allow counter to settle | 1089 // allow counter to settle |
1120 settling = 3; | 1090 settling = 3; |
1121 | 1091 |
1142 | 1112 |
1143 n_3 = 0; | 1113 n_3 = 0; |
1144 t3_3 = utc; | 1114 t3_3 = utc; |
1145 | 1115 |
1146 // frep negative step | 1116 // frep negative step |
1147 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1 - DeltakHz_3 * 1000); | 1117 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - DeltakHz_3 * 1000, FREP_STEP_SIZE); |
1148 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1 - DeltakHz_3 * 1000, FREP_STEP_SIZE); | 1118 |
1149 // compensate with DDS3 to keep measured beatnote in counter box range | 1119 // adjust DDS3 to keep beatnote within the bandpass filter |
1150 double fDDS3 = FrequencyDDS3Init - Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; | 1120 double fDDS3 = f0_DDS3 - Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; |
1151 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3); | |
1152 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 1121 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
1153 | 1122 |
1154 // allow counter to settle | 1123 // allow counter to settle |
1155 settling = 3; | 1124 settling = 3; |
1156 | 1125 |
1198 t2_3=0.0; | 1167 t2_3=0.0; |
1199 t3_3=0.0; | 1168 t3_3=0.0; |
1200 n_3 = 0; | 1169 n_3 = 0; |
1201 | 1170 |
1202 // back to nominal frep | 1171 // back to nominal frep |
1203 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 1172 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
1204 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE); | 1173 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
1205 // back to initial DDS3 frequency | 1174 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); |
1206 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init); | |
1207 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init); | |
1208 // back to initial DDS2 frequency | |
1209 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | |
1210 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
1211 | 1175 |
1212 // done | 1176 // done |
1213 Measuring_3 = N_MEASUREMENT_NONE; | 1177 Measuring_3 = N_MEASUREMENT_NONE; |
1214 } | 1178 } |
1215 break; | 1179 break; |
1221 if (utc > tbegin1+2) { | 1185 if (utc > tbegin1+2) { |
1222 if (Math1 > Frepbefore1) | 1186 if (Math1 > Frepbefore1) |
1223 Sign1 = -1.0; | 1187 Sign1 = -1.0; |
1224 else | 1188 else |
1225 Sign1 = +1.0; | 1189 Sign1 = +1.0; |
1226 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1); | |
1227 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1); | 1190 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1); |
1228 Getsign1 = FALSE; | 1191 Getsign1 = FALSE; |
1229 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); | 1192 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); |
1230 } | 1193 } |
1231 } | 1194 } |
1240 if (Ch2 > Ch2before) | 1203 if (Ch2 > Ch2before) |
1241 Sign2 = -1.0; | 1204 Sign2 = -1.0; |
1242 else | 1205 else |
1243 Sign2 = +1.0; | 1206 Sign2 = +1.0; |
1244 } | 1207 } |
1245 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2); | |
1246 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2); | 1208 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2); |
1247 Getsign2 = FALSE; | 1209 Getsign2 = FALSE; |
1248 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); | 1210 SetCtrlVal(MainPanel, PANEL_SIGN2, Sign2); |
1249 } | 1211 } |
1250 } | 1212 } |
1252 if (utc > tbegin3+2){ | 1214 if (utc > tbegin3+2){ |
1253 if (Ch3 > Frepbefore3) | 1215 if (Ch3 > Frepbefore3) |
1254 Sign3 = -1.0; | 1216 Sign3 = -1.0; |
1255 else | 1217 else |
1256 Sign3 = +1.0; | 1218 Sign3 = +1.0; |
1257 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3); | |
1258 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3); | 1219 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3); |
1259 Getsign3 = FALSE; | 1220 Getsign3 = FALSE; |
1260 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); | 1221 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); |
1261 } | 1222 } |
1262 } | 1223 } |
1336 if (recenter.lo) { | 1297 if (recenter.lo) { |
1337 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz | 1298 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz |
1338 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 1299 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
1339 double adj = 275000.0 - rollmean_ch4.mean; | 1300 double adj = 275000.0 - rollmean_ch4.mean; |
1340 freq = freq + adj; | 1301 freq = freq + adj; |
1341 SetCtrlVal(MainPanel, PANEL_DDS2, freq); | |
1342 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); | 1302 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); |
1343 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); | 1303 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); |
1344 } | 1304 } |
1345 | 1305 |
1346 if (recenter.hg) { | 1306 if (recenter.hg) { |
1347 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz | 1307 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz |
1348 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 1308 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
1349 double adj = 10000 - rollmean_ch2.mean; | 1309 double adj = 10000 - rollmean_ch2.mean; |
1350 freq = freq + adj; | 1310 freq = freq + adj; |
1351 SetCtrlVal(MainPanel, PANEL_DDS3, freq); | |
1352 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); | 1311 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); |
1353 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); | 1312 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); |
1354 } | 1313 } |
1355 | 1314 |
1356 if (recenter.sr) { | 1315 if (recenter.sr) { |
1357 // adjust DDS3 frequency to keep Ch3 reading at 10 kHz | 1316 // adjust DDS3 frequency to keep Ch3 reading at 10 kHz |
1358 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 1317 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
1359 double adj = 10000 - rollmean_ch3.mean; | 1318 double adj = 10000 - rollmean_ch3.mean; |
1360 freq = freq + adj; | 1319 freq = freq + adj; |
1361 SetCtrlVal(MainPanel, PANEL_DDS3, freq); | |
1362 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); | 1320 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); |
1363 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS3 adjustment=%+3e", adj); | 1321 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS3 adjustment=%+3e", adj); |
1364 } | 1322 } |
1365 | 1323 |
1366 recenter.t0 = utc; | 1324 recenter.t0 = utc; |
1367 rollmean_zero(&rollmean_ch2); | 1325 rollmean_zero(&rollmean_ch2); |
1368 rollmean_zero(&rollmean_ch3); | 1326 rollmean_zero(&rollmean_ch3); |
1369 rollmean_zero(&rollmean_ch4); | 1327 rollmean_zero(&rollmean_ch4); |
1370 } | 1328 } |
1371 } | 1329 } |
1330 | |
1331 // update DDS frequencies display | |
1332 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); | |
1333 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); | |
1334 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); | |
1335 SetCtrlVal(MainPanel, PANEL_DDS4, DDS4xAD9912.frequency[3]); | |
1372 | 1336 |
1373 // local time | 1337 // local time |
1374 struct tm *ltime = localtime(&event.time.tv_sec); | 1338 struct tm *ltime = localtime(&event.time.tv_sec); |
1375 // round to milliseconds | 1339 // round to milliseconds |
1376 int msec = round(event.time.tv_usec / 1000.0); | 1340 int msec = round(event.time.tv_usec / 1000.0); |
1660 switch (control) { | 1624 switch (control) { |
1661 case PANEL_N1CALCULUS: | 1625 case PANEL_N1CALCULUS: |
1662 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); | 1626 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); |
1663 if (! visible) { | 1627 if (! visible) { |
1664 measuring = MEASURING_N_Lo; | 1628 measuring = MEASURING_N_Lo; |
1629 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); | |
1665 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); | 1630 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); |
1666 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); | 1631 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); |
1667 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_1); | 1632 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_1); |
1668 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); | |
1669 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | 1633 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); |
1670 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1634 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1671 DisplayPanel(CalcNPanel); | 1635 DisplayPanel(CalcNPanel); |
1672 } | 1636 } |
1673 break; | 1637 break; |
1674 case PANEL_N2CALCULUS: | 1638 case PANEL_N2CALCULUS: |
1675 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); | 1639 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); |
1676 if (! visible) { | 1640 if (! visible) { |
1677 measuring = MEASURING_N_Hg; | 1641 measuring = MEASURING_N_Hg; |
1642 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); | |
1678 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); | 1643 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); |
1679 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); | 1644 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); |
1680 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_2); | 1645 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_2); |
1681 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); | |
1682 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | 1646 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); |
1683 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1647 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1684 DisplayPanel(CalcNPanel); | 1648 DisplayPanel(CalcNPanel); |
1685 } | 1649 } |
1686 break; | 1650 break; |
1687 case PANEL_N3CALCULUS: | 1651 case PANEL_N3CALCULUS: |
1688 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); | 1652 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); |
1689 if (! visible) { | 1653 if (! visible) { |
1690 measuring = MEASURING_N_Sr; | 1654 measuring = MEASURING_N_Sr; |
1655 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); | |
1691 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); | 1656 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); |
1692 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); | 1657 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); |
1693 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_3); | 1658 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_3); |
1694 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); | |
1695 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | 1659 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); |
1696 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1660 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1697 DisplayPanel(CalcNPanel); | 1661 DisplayPanel(CalcNPanel); |
1698 } | 1662 } |
1699 break; | 1663 break; |
1740 case EVENT_COMMIT: | 1704 case EVENT_COMMIT: |
1741 HidePanel(CalcNPanel); | 1705 HidePanel(CalcNPanel); |
1742 switch (measuring) { | 1706 switch (measuring) { |
1743 case MEASURING_N_Lo: | 1707 case MEASURING_N_Lo: |
1744 Measuring_1 = FALSE; | 1708 Measuring_1 = FALSE; |
1745 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 1709 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
1746 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 1710 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
1747 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | |
1748 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
1749 break; | 1711 break; |
1750 case MEASURING_N_Hg: | 1712 case MEASURING_N_Hg: |
1751 Measuring_2 = FALSE; | 1713 Measuring_2 = FALSE; |
1752 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 1714 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
1753 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 1715 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
1754 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | 1716 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); |
1755 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
1756 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init); | |
1757 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init); | |
1758 break; | 1717 break; |
1759 case MEASURING_N_Sr: | 1718 case MEASURING_N_Sr: |
1760 Measuring_3 = FALSE; | 1719 Measuring_3 = FALSE; |
1761 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 1720 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
1762 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, FrequDDS1, FREP_STEP_SIZE); | 1721 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
1763 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | 1722 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); |
1764 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
1765 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init); | |
1766 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init); | |
1767 break; | 1723 break; |
1768 } | 1724 } |
1725 | |
1726 // update DDS frequencies display | |
1727 SetCtrlVal(MainPanel, PANEL_DDS1, DDS4xAD9912.frequency[0]); | |
1728 SetCtrlVal(MainPanel, PANEL_DDS2, DDS4xAD9912.frequency[1]); | |
1729 SetCtrlVal(MainPanel, PANEL_DDS3, DDS4xAD9912.frequency[2]); | |
1730 SetCtrlVal(MainPanel, PANEL_DDS4, DDS4xAD9912.frequency[3]); | |
1731 | |
1769 break; | 1732 break; |
1770 } | 1733 } |
1771 return 0; | 1734 return 0; |
1772 } | 1735 } |
1773 | 1736 |
1845 { | 1808 { |
1846 switch (event) | 1809 switch (event) |
1847 { | 1810 { |
1848 case EVENT_COMMIT: | 1811 case EVENT_COMMIT: |
1849 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); | 1812 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); |
1850 FrequDDS1 = 880000000.0 / Ndiv; | 1813 f0_DDS1 = 880000000.0 / Ndiv; |
1851 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 1814 SetCtrlVal(MainPanel, PANEL_DDS1, f0_DDS1); |
1852 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 1815 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); |
1853 break; | 1816 break; |
1854 } | 1817 } |
1855 return 0; | 1818 return 0; |
1856 } | 1819 } |
1857 | 1820 |