Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 159:07153c41ba16
Code cleanup
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Mon, 03 Feb 2014 17:32:47 +0100 |
parents | 9154291658ef |
children | f609fb29536b |
comparison
equal
deleted
inserted
replaced
158:9154291658ef | 159:07153c41ba16 |
---|---|
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 f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3; | 187 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3; |
188 | 188 |
189 double Slope_1=0.0, Slope_2=0.0, Slope_3=0.0, Beatslope_2=0.0; | |
190 double SlopeTime1=40.0, SlopeTime2=40.0, SlopeTime3=40.0; | |
191 double Ch4Slope = 0.0; | |
192 | |
193 double N_1=0.0, N_2=0.0, N_3=0.0; | 189 double N_1=0.0, N_2=0.0, N_3=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; | 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; |
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; | 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; |
196 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.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; |
197 | 193 |
198 int n_1=0, n_2=0, n_3=0; | 194 int n_1=0, n_2=0, n_3=0; |
199 | 195 |
200 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0; | 196 double DeltaDDS3=0.0; |
201 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; | 197 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; |
202 | 198 |
203 double f_rep_slope, f_beat_slope; | 199 double f_rep_slope, f_beat_slope; |
204 double f_rep_plus, f_rep_minus; | 200 double f_rep_plus, f_rep_minus; |
205 double f_beat_Sr_plus, f_beat_Sr_minus; | 201 double f_beat_plus, f_beat_minus; |
206 | |
207 double Ch4Plus=0.0,Ch4Minus=0.0; | |
208 | 202 |
209 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; | 203 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0; |
210 double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0; | 204 double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0; |
211 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; | 205 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; |
212 | 206 |
213 int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; | 207 int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; |
214 double Sign1=1.0, Sign2=1.0, Sign3=0.0; | 208 double Sign1=1.0, Sign2=1.0, Sign3=0.0; |
215 | 209 |
216 | 210 |
217 struct stat stat_math1, stat_ch2, stat_ch3, stat_ch4, freq; | 211 struct stat stat_math1, stat_ch2, stat_ch3, freq; |
218 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; | 212 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; |
219 | 213 |
220 | 214 |
221 // dedrift | 215 // dedrift |
222 struct dedrift { | 216 struct dedrift { |
720 | 714 |
721 // update allan deviation plots | 715 // update allan deviation plots |
722 for (struct adev *adev = adevs; adev->data; adev++) | 716 for (struct adev *adev = adevs; adev->data; adev++) |
723 adev_update(adev); | 717 adev_update(adev); |
724 | 718 |
725 // Calcul de N | 719 // N measurement |
726 | 720 |
727 switch (Measuring_1) { | 721 switch (Measuring_1) { |
728 | 722 |
729 case N_MEASUREMENT_NONE: | 723 case N_MEASUREMENT_NONE: |
730 // not measuring | 724 // not measuring |
731 break; | 725 break; |
732 | 726 |
733 case N_MEASUREMENT_INIT: | 727 case N_MEASUREMENT_INIT: |
734 // initialization step | 728 // initialization step |
735 | 729 |
736 // set DDS1 to nominal frequency | 730 // set DDS1 to nominal frequency |
737 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 731 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, f0_DDS1); |
738 | 732 |
739 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 733 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
740 t1_1 = utc; | 734 t1_1 = utc; |
741 t2_1 = 0.0; | 735 t2_1 = 0.0; |
742 t3_1 = 0.0; | 736 t3_1 = 0.0; |
743 stat_zero(&stat_math1); | 737 stat_zero(&stat_math1); |
744 stat_zero(&stat_ch4); | |
745 | 738 |
746 // next step | 739 // next step |
747 Measuring_1 += 1; | 740 Measuring_1 += 1; |
748 break; | 741 break; |
749 | 742 |
750 case N_MEASUREMENT_SLOPE: | 743 case N_MEASUREMENT_SLOPE: |
751 // slope measurement | 744 // slope measurement |
752 | 745 |
753 stat_accumulate(&stat_math1, Math1); | 746 stat_accumulate(&stat_math1, Math1); |
754 stat_accumulate(&stat_ch4, Ch4); | |
755 | 747 |
756 if ((utc - t1_1) > SlopeTime1) { | 748 if ((utc - t1_1) > SlopeTime1) { |
757 Slope_1 = stat_math1.slope; | 749 f_rep_slope = stat_math1.slope; |
758 Ch4Slope = stat_ch4.slope; | |
759 | 750 |
760 // frep positive step | 751 // frep positive step |
761 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + DeltakHz_1 * 1000.0, FREP_STEP_SIZE); | 752 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE); |
762 | 753 |
763 // allow counter to settle | 754 // allow counter to settle |
764 settling = 3; | 755 settling = 3; |
765 | 756 |
766 // next step | 757 // next step |
770 | 761 |
771 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | 762 case N_MEASUREMENT_ADJUST_FREQ_PLUS: |
772 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 763 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
773 // adjust DDS frequency to keep beatnote within the bandpass filter | 764 // adjust DDS frequency to keep beatnote within the bandpass filter |
774 | 765 |
775 if (settling > 0) { | 766 if (settling-- > 0) |
776 settling--; | |
777 break; | 767 break; |
778 } | |
779 | 768 |
780 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 769 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
781 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2 + 275000 - Ch4); | 770 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2 + 275000 - Ch4); |
782 | 771 |
783 // allow counter to settle | 772 // allow counter to settle |
788 break; | 777 break; |
789 | 778 |
790 case N_MEASUREMENT_FREP_PLUS: | 779 case N_MEASUREMENT_FREP_PLUS: |
791 // frep positive step | 780 // frep positive step |
792 | 781 |
793 if (settling > 0) { | 782 if (settling-- > 0) |
794 settling--; | |
795 break; | 783 break; |
796 } | |
797 | 784 |
798 if (t2_1 == 0.0) | 785 if (t2_1 == 0.0) |
799 t2_1 = utc; | 786 t2_1 = utc; |
800 | 787 |
801 Frepplus_1 = Frepplus_1 + Math1 - Slope_1 * (utc - t2_1); | 788 f_rep_plus += Math1 - f_rep_slope * (utc - t2_1); |
802 Ch4Plus = Ch4Plus + Ch4 - Ch4Slope * (utc - t2_1); | |
803 n_1 += 1; | 789 n_1 += 1; |
804 | 790 |
805 if ((utc - t2_1) > DeltaT_1) { | 791 if ((utc - t2_1) > DeltaT_1) { |
806 Frepplus_1 = Frepplus_1 / n_1; | 792 f_rep_plus = f_rep_plus / n_1; |
807 Ch4Plus = Ch4Plus / n_1; | |
808 n_1 = 0; | 793 n_1 = 0; |
809 | 794 |
810 // frep negative step | 795 // frep negative step |
811 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - DeltakHz_1 * 1000.0, FREP_STEP_SIZE); | 796 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE); |
812 | 797 |
813 // allow counter to settle | 798 // allow counter to settle |
814 settling = 3; | 799 settling = 3; |
815 | 800 |
816 // next step | 801 // next step |
819 break; | 804 break; |
820 | 805 |
821 case N_MEASUREMENT_FREP_MINUS: | 806 case N_MEASUREMENT_FREP_MINUS: |
822 // frep negative step | 807 // frep negative step |
823 | 808 |
824 if (settling > 0) { | 809 if (settling-- > 0) |
825 settling--; | |
826 break; | 810 break; |
827 } | |
828 | 811 |
829 if (t3_1 == 0.0) | 812 if (t3_1 == 0.0) |
830 t3_1 = utc; | 813 t3_1 = utc; |
831 | 814 |
832 Frepminus_1 = Frepminus_1 + Math1 - Slope_1 * (utc - t3_1); | 815 f_rep_minus += Math1 - f_rep_slope * (utc - t2_1); |
833 Ch4Minus = Ch4Minus + Ch4 - Ch4Slope * (utc - t3_1); | |
834 n_1 += 1; | 816 n_1 += 1; |
835 | 817 |
836 if ((utc - t3_1) > DeltaT_1) { | 818 if ((utc - t3_1) > DeltaT_1) { |
837 Frepminus_1 = Frepminus_1 / n_1; | 819 f_rep_minus = f_rep_minus / n_1; |
838 Ch4Minus = Ch4Minus / n_1; | |
839 n_1 = 0; | 820 n_1 = 0; |
840 | 821 |
841 // compute N1 | 822 // compute N1 |
842 N_1 = Sign1 * (2*Ndiv * DeltakHz_1 * 1000)/(Frepminus_1 - Frepplus_1 - Slope_1 * (t3_1 - t2_1)); | 823 double delta_f_rep = f_rep_minus - f_rep_plus; |
824 N_1 = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep; | |
843 SetCtrlVal(CalcNPanel, CALCN_N, N_1); | 825 SetCtrlVal(CalcNPanel, CALCN_N, N_1); |
844 | 826 |
845 t1_1 = 0.0; | 827 t1_1 = t2_1 = t3_1 = 0.0; |
846 t2_1 = 0.0; | 828 f_rep_minus = f_rep_plus = 0.0; |
847 t3_1 = 0.0; | |
848 Frepminus_1 = 0.0; | |
849 Frepplus_1 = 0.0; | |
850 | 829 |
851 // back to nominal frep | 830 // back to nominal frep |
852 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); | 831 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
853 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); | 832 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
854 | 833 |
887 | 866 |
888 stat_accumulate(&stat_math1, Math1); | 867 stat_accumulate(&stat_math1, Math1); |
889 stat_accumulate(&stat_ch2, Ch2); | 868 stat_accumulate(&stat_ch2, Ch2); |
890 | 869 |
891 if ((utc - t1_2) > SlopeTime2) { | 870 if ((utc - t1_2) > SlopeTime2) { |
892 Slope_2 = stat_math1.slope; | 871 f_rep_slope = stat_math1.slope; |
893 Beatslope_2 = stat_ch2.slope; | 872 f_beat_slope = stat_ch2.slope; |
894 | 873 |
895 // frep positive step | 874 // frep positive step |
896 double fDDS1 = f0_DDS1 + DeltakHz_2 * 1000; | 875 double fDDS1 = f0_DDS1 + delta_f_lock_2; |
897 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE); | 876 DDS4xAD9912_RampFrequency(&DDS4xAD9912,1, fDDS1, FREP_STEP_SIZE); |
898 | 877 |
899 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 878 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
900 double fDDS3 = f0_DDS3 - DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2); | 879 double fDDS3 = f0_DDS3 - delta_f_lock_2 *(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1) - f_beat_slope * (utc-t1_2); |
901 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 880 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
902 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 881 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
903 | 882 |
904 // allow counter to settle | 883 // allow counter to settle |
905 settling = 3; | 884 settling = 3; |
911 | 890 |
912 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | 891 case N_MEASUREMENT_ADJUST_FREQ_PLUS: |
913 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 892 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
914 // adjust DDS frequency to keep beatnote within the bandpass filter | 893 // adjust DDS frequency to keep beatnote within the bandpass filter |
915 | 894 |
916 if (settling > 0) { | 895 if (settling-- > 0) |
917 settling--; | |
918 break; | 896 break; |
919 } | |
920 | 897 |
921 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; | 898 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; |
922 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | 899 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); |
923 | 900 |
924 double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; | 901 double fDDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3) + 10000 - Ch2; |
933 break; | 910 break; |
934 | 911 |
935 case N_MEASUREMENT_FREP_PLUS: | 912 case N_MEASUREMENT_FREP_PLUS: |
936 // frep positive step | 913 // frep positive step |
937 | 914 |
938 if (settling > 0) { | 915 if (settling-- > 0) |
939 settling--; | |
940 break; | 916 break; |
941 } | |
942 | 917 |
943 if (t2_1 == 0.0) | 918 if (t2_1 == 0.0) |
944 t2_1 = utc; | 919 t2_1 = utc; |
945 | 920 |
946 Frepplus_2 = Frepplus_2 + Math1 + 250000000 - Slope_2 * (utc - t2_2); | 921 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2_2); |
947 Delta10K_Plus = Delta10K_Plus + 10000 - (Ch2 - Beatslope_2 * (utc - t2_2)); | 922 f_beat_plus += Ch2 - f_beat_slope * (utc - t2_2); |
948 n_2 += 1; | 923 n_2 += 1; |
949 | 924 |
950 if ((utc - t2_2) > DeltaT_2) { | 925 if ((utc - t2_2) > DeltaT_2) { |
951 Frepplus_2 = Frepplus_2 / n_2; | 926 f_rep_plus = f_rep_plus / n_2; |
952 Delta10K_Plus = Delta10K_Plus / n_2; | 927 f_beat_plus = f_beat_plus / n_2; |
953 n_2 = 0; | 928 n_2 = 0; |
954 | 929 |
955 // negative frequency step | 930 // negative frequency step |
956 double fDDS1 = f0_DDS1 - DeltakHz_2 * 1000; | 931 double fDDS1 = f0_DDS1 - delta_f_lock_2; |
957 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); | 932 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, fDDS1, FREP_STEP_SIZE); |
958 | 933 |
959 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 934 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
960 double fDDS3 = f0_DDS3 + DeltakHz_2*1000*(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); | 935 double fDDS3 = f0_DDS3 + delta_f_lock_2 *(-Sign1/Sign2)*Ndiv*(Nu2)/(Nu1); |
961 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 936 DeltaDDS3 = fDDS3 - DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
962 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 937 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
963 | 938 |
964 // allow counter to settle | 939 // allow counter to settle |
965 settling = 3; | 940 settling = 3; |
970 break; | 945 break; |
971 | 946 |
972 case N_MEASUREMENT_FREP_MINUS: | 947 case N_MEASUREMENT_FREP_MINUS: |
973 // frep negative step | 948 // frep negative step |
974 | 949 |
975 if (settling > 0) { | 950 if (settling-- > 0) |
976 settling--; | |
977 break; | 951 break; |
978 } | |
979 | 952 |
980 if (t3_1 == 0.0) | 953 if (t3_1 == 0.0) |
981 t3_1 = utc; | 954 t3_1 = utc; |
982 | 955 |
983 Frepminus_2 = Frepminus_2 + Math1 + 250000000 - Slope_2 * (utc - t3_2); | 956 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2_2); |
984 Delta10K_Minus = Delta10K_Minus + 10000 - (Ch2 - Beatslope_2 * (utc - t3_2)); | 957 f_beat_minus += Ch2 + f_beat_slope * (utc - t2_2); |
985 n_2 += 1; | 958 n_2 += 1; |
986 | 959 |
987 if ((utc -t3_2) > DeltaT_2) { | 960 if ((utc -t3_2) > DeltaT_2) { |
988 Frepminus_2 = Frepminus_2 / n_2; | 961 f_rep_minus = f_rep_minus / n_2; |
989 Delta10K_Minus = Delta10K_Minus / n_2; | 962 f_beat_minus = f_beat_minus / n_2; |
990 n_2 = 0; | 963 n_2 = 0; |
991 | 964 |
992 // compute N2 | 965 // compute N2 |
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)); | 966 double delta_f_rep = f_rep_minus - f_rep_plus; |
967 N_2 = -Sign2 * (DeltaDDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; | |
994 SetCtrlVal(CalcNPanel, CALCN_N, N_2); | 968 SetCtrlVal(CalcNPanel, CALCN_N, N_2); |
995 | 969 |
996 // back to nominal frequency | 970 // back to nominal frequency |
997 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); | 971 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); |
998 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); | 972 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); |
999 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3 - Beatslope_2 * (utc - t1_2)); | 973 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); |
1000 | 974 |
1001 t1_2 = 0.0; | 975 t1_2 = t2_2 = t3_2 = 0.0; |
1002 t2_2 = 0.0; | 976 f_rep_minus = f_rep_plus = 0.0; |
1003 t3_2 = 0.0; | 977 f_beat_minus = f_beat_plus = 0.0; |
1004 Frepminus_2 = 0.0; | |
1005 Frepplus_2 = 0.0; | |
1006 Delta10K_Minus = 0.0; | |
1007 Delta10K_Plus = 0.0; | |
1008 | 978 |
1009 // done | 979 // done |
1010 Measuring_2 = N_MEASUREMENT_NONE; | 980 Measuring_2 = N_MEASUREMENT_NONE; |
1011 } | 981 } |
1012 break; | 982 break; |
1026 | 996 |
1027 t1_3 = utc; | 997 t1_3 = utc; |
1028 stat_zero(&stat_math1); | 998 stat_zero(&stat_math1); |
1029 stat_zero(&stat_ch3); | 999 stat_zero(&stat_ch3); |
1030 f_rep_plus = f_rep_minus = 0.0; | 1000 f_rep_plus = f_rep_minus = 0.0; |
1031 f_beat_Sr_plus = f_beat_Sr_minus = 0.0; | 1001 f_beat_plus = f_beat_minus = 0.0; |
1032 | 1002 |
1033 // record current DDS frequencies | 1003 // record current DDS frequencies |
1034 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | 1004 f0_DDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); |
1035 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | 1005 f0_DDS3 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); |
1036 | 1006 |
1039 break; | 1009 break; |
1040 | 1010 |
1041 case N_MEASUREMENT_SLOPE: | 1011 case N_MEASUREMENT_SLOPE: |
1042 // slope measurement | 1012 // slope measurement |
1043 | 1013 |
1044 if (settling > 0) { | 1014 if (settling-- > 0) |
1045 settling--; | |
1046 break; | 1015 break; |
1047 } | |
1048 | 1016 |
1049 stat_accumulate(&stat_math1, Math1); | 1017 stat_accumulate(&stat_math1, Math1); |
1050 stat_accumulate(&stat_ch3, Ch3); | 1018 stat_accumulate(&stat_ch3, Ch3); |
1051 | 1019 |
1052 if (utc - t1_3 > SlopeTime3) { | 1020 if (utc - t1_3 > SlopeTime3) { |
1057 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); | 1025 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); |
1058 | 1026 |
1059 t2_3 = utc; | 1027 t2_3 = utc; |
1060 | 1028 |
1061 // frep positive step | 1029 // frep positive step |
1062 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + DeltakHz_3 * 1000, FREP_STEP_SIZE); | 1030 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 + delta_f_lock_3, FREP_STEP_SIZE); |
1063 | 1031 |
1064 // adjust DDS3 to keep beatnote within the bandpass filter | 1032 // adjust DDS3 to keep beatnote within the bandpass filter |
1065 double fDDS3 = f0_DDS3 + Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; | 1033 double fDDS3 = f0_DDS3 + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; |
1066 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 1034 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
1067 | 1035 |
1068 // allow counter to settle | 1036 // allow counter to settle |
1069 settling = 3; | 1037 settling = 3; |
1070 | 1038 |
1075 | 1043 |
1076 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | 1044 case N_MEASUREMENT_ADJUST_FREQ_PLUS: |
1077 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 1045 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
1078 // adjust DDS frequency to keep beatnote within the bandpass filter | 1046 // adjust DDS frequency to keep beatnote within the bandpass filter |
1079 | 1047 |
1080 if (settling > 0) { | 1048 if (settling-- > 0) |
1081 settling--; | |
1082 break; | 1049 break; |
1083 } | |
1084 | 1050 |
1085 // adjust DDS frequency to keep 55 MHz tracker oscillator locked | 1051 // adjust DDS frequency to keep 55 MHz tracker oscillator locked |
1086 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; | 1052 double fDDS2 = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2) + 275000 - Ch4; |
1087 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | 1053 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); |
1088 | 1054 |
1094 break; | 1060 break; |
1095 | 1061 |
1096 case N_MEASUREMENT_FREP_PLUS: | 1062 case N_MEASUREMENT_FREP_PLUS: |
1097 // frep positive step | 1063 // frep positive step |
1098 | 1064 |
1099 if (settling > 0) { | 1065 if (settling-- > 0) |
1100 settling--; | |
1101 break; | 1066 break; |
1102 } | |
1103 | 1067 |
1104 n_3++; | 1068 n_3++; |
1105 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); | 1069 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); |
1106 f_beat_Sr_plus += Ch3 - f_beat_slope * (utc - t3_2); | 1070 f_beat_plus += Ch3 - f_beat_slope * (utc - t3_2); |
1107 | 1071 |
1108 if (utc - t2_3 > DeltaT_3) { | 1072 if (utc - t2_3 > DeltaT_3) { |
1109 // positive step measurement | 1073 // positive step measurement |
1110 f_rep_plus = f_rep_plus / n_3; | 1074 f_rep_plus = f_rep_plus / n_3; |
1111 f_beat_Sr_plus = f_beat_Sr_plus / n_3; | 1075 f_beat_plus = f_beat_plus / n_3; |
1112 | 1076 |
1113 n_3 = 0; | 1077 n_3 = 0; |
1114 t3_3 = utc; | 1078 t3_3 = utc; |
1115 | 1079 |
1116 // frep negative step | 1080 // frep negative step |
1117 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - DeltakHz_3 * 1000, FREP_STEP_SIZE); | 1081 DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1 - delta_f_lock_3, FREP_STEP_SIZE); |
1118 | 1082 |
1119 // adjust DDS3 to keep beatnote within the bandpass filter | 1083 // adjust DDS3 to keep beatnote within the bandpass filter |
1120 double fDDS3 = f0_DDS3 - Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; | 1084 double fDDS3 = f0_DDS3 - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; |
1121 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); | 1085 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3); |
1122 | 1086 |
1123 // allow counter to settle | 1087 // allow counter to settle |
1124 settling = 3; | 1088 settling = 3; |
1125 | 1089 |
1129 break; | 1093 break; |
1130 | 1094 |
1131 case N_MEASUREMENT_FREP_MINUS: | 1095 case N_MEASUREMENT_FREP_MINUS: |
1132 // frep negative step | 1096 // frep negative step |
1133 | 1097 |
1134 if (settling > 0) { | 1098 if (settling-- > 0) |
1135 settling--; | |
1136 break; | 1099 break; |
1137 } | |
1138 | 1100 |
1139 n_3++; | 1101 n_3++; |
1140 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); | 1102 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t3_2); |
1141 f_beat_Sr_minus += Ch3 - f_beat_slope * (utc - t3_2); | 1103 f_beat_minus += Ch3 - f_beat_slope * (utc - t3_2); |
1142 | 1104 |
1143 if (utc - t3_3 > DeltaT_3) { | 1105 if (utc - t3_3 > DeltaT_3) { |
1144 // negative step measurement | 1106 // negative step measurement |
1145 f_rep_minus = f_rep_minus / n_3; | 1107 f_rep_minus = f_rep_minus / n_3; |
1146 f_beat_Sr_minus = f_beat_Sr_minus / n_3; | 1108 f_beat_minus = f_beat_minus / n_3; |
1147 | 1109 |
1148 // check delta frep | 1110 // check delta frep |
1149 double delta_f_rep_m = f_rep_plus - f_rep_minus; | 1111 double delta_f_rep_m = f_rep_plus - f_rep_minus; |
1150 double delta_f_rep = Sign1 * Ndiv * 2.0 * DeltakHz_3 * 1000.0 / N1; | 1112 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; |
1151 logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e", | 1113 logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e", |
1152 delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); | 1114 delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); |
1153 | 1115 |
1154 logmsg("f_beat_Sr_minus=%.12e", f_beat_Sr_minus); | 1116 logmsg("f_beat_minus=%.12e", f_beat_minus); |
1155 logmsg("f_beat_Sr_plus =%.12e", f_beat_Sr_plus); | 1117 logmsg("f_beat_plus =%.12e", f_beat_plus); |
1156 | 1118 |
1157 // compute N3 | 1119 // compute N3 |
1158 double delta_f_beat_Sr = f_beat_Sr_plus - f_beat_Sr_minus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * DeltakHz_3 * 1000; | 1120 double delta_f_beat = f_beat_plus - f_beat_minus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; |
1159 double delta_f_beat_Sr_expected = delta_f_rep * N3; | 1121 double delta_f_beat_expected = delta_f_rep * N3; |
1160 logmsg("delta fbeat: measured=%.12e expected=%.12e difference=%.12e", | 1122 logmsg("delta fbeat: measured=%.12e expected=%.12e difference=%.12e", |
1161 delta_f_beat_Sr, delta_f_beat_Sr_expected, delta_f_beat_Sr - delta_f_beat_Sr_expected); | 1123 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); |
1162 N_3 = delta_f_beat_Sr / delta_f_rep; | 1124 N_3 = delta_f_beat / delta_f_rep; |
1163 logmsg("measured N3=%.3f", N_3); | 1125 logmsg("measured N3=%.3f", N_3); |
1164 SetCtrlVal(CalcNPanel, CALCN_N, N_3); | 1126 SetCtrlVal(CalcNPanel, CALCN_N, N_3); |
1165 | 1127 |
1166 t1_3=0.0; | 1128 t1_3=0.0; |
1167 t2_3=0.0; | 1129 t2_3=0.0; |
1627 if (! visible) { | 1589 if (! visible) { |
1628 measuring = MEASURING_N_Lo; | 1590 measuring = MEASURING_N_Lo; |
1629 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); | 1591 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); |
1630 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); | 1592 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); |
1631 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); | 1593 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); |
1632 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_1); | 1594 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); |
1633 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | |
1634 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1595 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1635 DisplayPanel(CalcNPanel); | 1596 DisplayPanel(CalcNPanel); |
1636 } | 1597 } |
1637 break; | 1598 break; |
1638 case PANEL_N2CALCULUS: | 1599 case PANEL_N2CALCULUS: |
1640 if (! visible) { | 1601 if (! visible) { |
1641 measuring = MEASURING_N_Hg; | 1602 measuring = MEASURING_N_Hg; |
1642 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); | 1603 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); |
1643 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); | 1604 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); |
1644 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); | 1605 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); |
1645 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_2); | 1606 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); |
1646 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | |
1647 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1607 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1648 DisplayPanel(CalcNPanel); | 1608 DisplayPanel(CalcNPanel); |
1649 } | 1609 } |
1650 break; | 1610 break; |
1651 case PANEL_N3CALCULUS: | 1611 case PANEL_N3CALCULUS: |
1653 if (! visible) { | 1613 if (! visible) { |
1654 measuring = MEASURING_N_Sr; | 1614 measuring = MEASURING_N_Sr; |
1655 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); | 1615 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); |
1656 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); | 1616 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); |
1657 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); | 1617 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); |
1658 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_3); | 1618 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); |
1659 SetCtrlVal(CalcNPanel, CALCN_SLOPE, 0.0); | |
1660 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1619 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1661 DisplayPanel(CalcNPanel); | 1620 DisplayPanel(CalcNPanel); |
1662 } | 1621 } |
1663 break; | 1622 break; |
1664 } | 1623 } |
1674 case EVENT_COMMIT: | 1633 case EVENT_COMMIT: |
1675 switch (measuring) { | 1634 switch (measuring) { |
1676 case MEASURING_N_Lo: | 1635 case MEASURING_N_Lo: |
1677 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); | 1636 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); |
1678 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); | 1637 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); |
1679 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_1); | 1638 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); |
1639 // convert from kHz to Hz | |
1640 delta_f_lock_1 = delta_f_lock_1 * 1000.0; | |
1680 Measuring_1 = TRUE; | 1641 Measuring_1 = TRUE; |
1681 break; | 1642 break; |
1682 case MEASURING_N_Hg: | 1643 case MEASURING_N_Hg: |
1683 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); | 1644 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); |
1684 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); | 1645 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); |
1685 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_2); | 1646 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2); |
1647 // convert from kHz to Hz | |
1648 delta_f_lock_2 = delta_f_lock_2 * 1000.0; | |
1686 Measuring_2 = TRUE; | 1649 Measuring_2 = TRUE; |
1687 break; | 1650 break; |
1688 case MEASURING_N_Sr: | 1651 case MEASURING_N_Sr: |
1689 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); | 1652 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); |
1690 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); | 1653 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); |
1691 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_3); | 1654 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3); |
1655 // convert from kHz to Hz | |
1656 delta_f_lock_3 = delta_f_lock_3 * 1000.0; | |
1692 Measuring_3 = TRUE; | 1657 Measuring_3 = TRUE; |
1693 break; | 1658 break; |
1694 } | 1659 } |
1695 break; | 1660 break; |
1696 } | 1661 } |