Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 26:4bb197635664
Cleanup N1 measurement code
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 02 Oct 2012 16:31:32 +0200 |
parents | fde495ba28d2 |
children | 419db63a9949 |
comparison
equal
deleted
inserted
replaced
25:fde495ba28d2 | 26:4bb197635664 |
---|---|
74 N_MEASUREMENT_STEP_0, | 74 N_MEASUREMENT_STEP_0, |
75 N_MEASUREMENT_STEP_1, | 75 N_MEASUREMENT_STEP_1, |
76 N_MEASUREMENT_STEP_2, | 76 N_MEASUREMENT_STEP_2, |
77 N_MEASUREMENT_STEP_3, | 77 N_MEASUREMENT_STEP_3, |
78 N_MEASUREMENT_STEP_4, | 78 N_MEASUREMENT_STEP_4, |
79 }; | |
80 | |
81 enum { | |
82 N_MEASUREMENT_NONE, | |
83 N_MEASUREMENT_INIT, | |
84 N_MEASUREMENT_SLOPE, | |
85 N_MEASUREMENT_ADJUST_FREQ_PLUS, | |
86 N_MEASUREMENT_FREP_PLUS, | |
87 N_MEASUREMENT_ADJUST_FREQ_MINUS, | |
88 N_MEASUREMENT_FREP_MINUS, | |
79 }; | 89 }; |
80 | 90 |
81 int settling = 0; | 91 int settling = 0; |
82 | 92 |
83 volatile bool Measuring_1 = FALSE,Step1_1 = FALSE,Step2_1 = FALSE,Step3_1 = FALSE, Measuring_2 = FALSE,Step1_2 = FALSE,Step2_2 = FALSE,Step3_2 = FALSE; | 93 volatile bool Measuring_1 = FALSE,Step1_1 = FALSE,Step2_1 = FALSE,Step3_1 = FALSE, Measuring_2 = FALSE,Step1_2 = FALSE,Step2_2 = FALSE,Step3_2 = FALSE; |
781 } | 791 } |
782 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked) ; | 792 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked) ; |
783 if (BoxChecked) { | 793 if (BoxChecked) { |
784 Allan_AddFrequency(&AllanMath5, Math5) ; | 794 Allan_AddFrequency(&AllanMath5, Math5) ; |
785 } | 795 } |
796 | |
786 // Calcul de N | 797 // Calcul de N |
787 | 798 |
788 if (Measuring_1==TRUE) | 799 switch (Measuring_1) { |
789 { | 800 |
790 if (Step1_1==FALSE) { | 801 case N_MEASUREMENT_NONE: |
791 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; | 802 // not measuring |
803 break; | |
804 | |
805 case N_MEASUREMENT_INIT: | |
806 // initialization step | |
807 | |
808 // set DDS1 to nominal frequency | |
809 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | |
810 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | |
811 | |
812 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit); | |
813 t2_1 = t3_1 = 0.0; | |
814 t1_1 = utc; | |
815 Frequ_slope_1 = Math1; | |
816 Moy_slope_1 = Frequ_slope_1; | |
817 Ch4_slope = Ch4; | |
818 Moy_Ch4slope_1 = Ch4_slope; | |
819 N_slope_1 = 1; | |
820 | |
821 // next step | |
822 Measuring_1 += 1; | |
823 break; | |
824 | |
825 case N_MEASUREMENT_SLOPE: | |
826 // slope measurement | |
827 | |
828 N_slope_1 = N_slope_1 + 1; | |
829 Frequ_slope_1 = Math1; | |
830 Ch4_slope = Ch4; | |
831 Moy_slope_1 = ((N_slope_1-1)*Moy_slope_1 + Frequ_slope_1)/N_slope_1; | |
832 Moy_Ch4slope_1 = ((N_slope_1-1)*Moy_Ch4slope_1 + Ch4_slope)/N_slope_1; | |
833 Slope_slope_1 = (Slope_slope_1*(N_slope_1-2) + 6*(Frequ_slope_1-Moy_slope_1)/N_slope_1)/(N_slope_1+1); | |
834 Slope_Ch4slope_1 = (Slope_Ch4slope_1*(N_slope_1-2) + 6*(Ch4_slope-Moy_Ch4slope_1)/N_slope_1)/(N_slope_1+1); | |
835 | |
836 if ((utc - t1_1) > SlopeTime1) { | |
837 Slope_1 = Slope_slope_1; | |
838 Ch4Slope = Slope_Ch4slope_1; | |
839 | |
840 N_slope_1 = 0; | |
841 Frequ_slope_1 = 0.0; | |
842 Moy_slope_1 = 0.0; | |
843 Slope_slope_1 = 0.0; | |
844 Ch4_slope = 0.0; | |
845 Moy_Ch4slope_1 = 0.0; | |
846 Slope_Ch4slope_1 = 0.0; | |
847 | |
848 // frep positive step | |
849 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv ); | |
850 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_1*1000)); | |
851 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_1*1000)); | |
852 | |
853 // allow counter to settle | |
854 settling = 3; | |
855 | |
856 // next step | |
857 Measuring_1 += 1; | |
858 } | |
859 break; | |
860 | |
861 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | |
862 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | |
863 // adjust DDS frequency to keep beatnote within the bandpass filter | |
864 | |
865 if (settling > 0) { | |
866 settling--; | |
867 break; | |
868 } | |
869 | |
870 DeltaFrep275 = 275000 - Ch4; | |
871 double fDDS2 = FrequencyDDSBesInit + (DeltaFrep275); | |
872 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2) ; | |
873 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2); | |
874 | |
875 // allow counter to settle | |
876 settling = 3; | |
877 | |
878 // next step | |
879 Measuring_1 += 1; | |
880 break; | |
881 | |
882 | |
883 case N_MEASUREMENT_FREP_PLUS: | |
884 // frep positive step | |
885 | |
886 if (settling > 0) { | |
887 settling--; | |
888 break; | |
889 } | |
890 | |
891 if (t2_1 == 0.0) | |
892 t2_1 = utc; | |
893 | |
894 Frepplus_1 = Frepplus_1 + Math1 - Slope_1 * (utc - t2_1); | |
895 Ch4Plus = Ch4Plus + Ch4 - Ch4Slope * (utc - t2_1); | |
896 n_1 += 1; | |
897 | |
898 if ((utc - t2_1) > DeltaT_1) { | |
899 Frepplus_1 = Frepplus_1 / n_1; | |
900 Ch4Plus = Ch4Plus / n_1; | |
901 n_1 = 0; | |
902 | |
903 // frep negative step | |
904 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, (FrequDDS1+DeltakHz_1*1000),(FrequDDS1-DeltakHz_1*1000), Step1/Ndiv); | |
905 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_1*1000)); | |
906 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1-DeltakHz_1*1000)); | |
907 | |
908 // allow counter to settle | |
909 settling = 3; | |
910 | |
911 // next step | |
912 Measuring_1 += 1; | |
913 } | |
914 break; | |
915 | |
916 case N_MEASUREMENT_FREP_MINUS: | |
917 // frep negative step | |
918 | |
919 if (settling > 0) { | |
920 settling--; | |
921 break; | |
922 } | |
923 | |
924 if (t3_1 == 0.0) | |
925 t3_1 = utc; | |
926 | |
927 Frepminus_1 = Frepminus_1 + Math1 - Slope_1 * (utc - t3_1); | |
928 Ch4Minus = Ch4Minus + Ch4 - Ch4Slope * (utc - t3_1); | |
929 n_1 += 1; | |
930 | |
931 if ((utc - t3_1) > DeltaT_1) { | |
932 Frepminus_1 = Frepminus_1 / n_1; | |
933 Ch4Minus = Ch4Minus / n_1; | |
934 n_1 = 0; | |
935 | |
936 t1_1 = 0.0; | |
937 t2_1 = 0.0; | |
938 t3_1 = 0.0; | |
939 Frepminus_1 = 0.0; | |
940 Frepplus_1 = 0.0; | |
941 | |
942 // compute N1 | |
943 N_1 = Signe1 * (2*Ndiv * DeltakHz_1 * 1000)/(Frepminus_1 - Frepplus_1 - Slope_1 * (t3_1 - t2_1)); | |
944 | |
945 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912, 1, FrequDDS1-DeltakHz_1*1000,FrequDDS1, Step1/Ndiv ); | |
946 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | |
792 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 947 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); |
948 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); | |
949 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); | |
793 | 950 |
794 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit) ; | 951 // done |
795 t1_1=utc; | 952 Measuring_1 = N_MEASUREMENT_NONE; |
796 Frequ_slope_1=Math1; | 953 } |
797 Moy_slope_1= Frequ_slope_1; | 954 break; |
798 Ch4_slope=Ch4; | 955 } |
799 Moy_Ch4slope_1= Ch4_slope; | |
800 N_slope_1=1; | |
801 Step1_1=TRUE ; | |
802 } | |
803 else { | |
804 if(Step2_1==FALSE){ | |
805 N_slope_1=N_slope_1+1; | |
806 Frequ_slope_1=Math1; | |
807 Ch4_slope=Ch4; | |
808 Moy_slope_1=((N_slope_1-1)*Moy_slope_1 + Frequ_slope_1)/N_slope_1; | |
809 Moy_Ch4slope_1=((N_slope_1-1)*Moy_Ch4slope_1 + Ch4_slope)/N_slope_1; | |
810 Slope_slope_1 = (Slope_slope_1*(N_slope_1-2) + 6*(Frequ_slope_1-Moy_slope_1)/N_slope_1)/(N_slope_1+1) ; | |
811 Slope_Ch4slope_1 = (Slope_Ch4slope_1*(N_slope_1-2) + 6*(Ch4_slope-Moy_Ch4slope_1)/N_slope_1)/(N_slope_1+1) ; | |
812 if (utc-t1_1>SlopeTime1) { | |
813 Slope_1 = Slope_slope_1; | |
814 Ch4Slope = Slope_Ch4slope_1; | |
815 Step2_1=TRUE ; | |
816 N_slope_1=0; | |
817 Frequ_slope_1=0.0; | |
818 Moy_slope_1=0.0; | |
819 Slope_slope_1 =0.0; | |
820 Ch4_slope=0.0; | |
821 Moy_Ch4slope_1=0.0; | |
822 Slope_Ch4slope_1=0.0; | |
823 | |
824 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv ) ; | |
825 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_1*1000)) ; | |
826 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_1*1000)); | |
827 | |
828 } | |
829 } | |
830 else { | |
831 if (DDSBesChanged1==FALSE){ | |
832 | |
833 if (nDDSChange<3) | |
834 { nDDSChange=nDDSChange+1;} | |
835 | |
836 else | |
837 { | |
838 nDDSChange=0; | |
839 | |
840 DeltaFrep275=275000-Ch4; | |
841 FrequencyDDSBes=FrequencyDDSBesInit+(DeltaFrep275); | |
842 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ; | |
843 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes); | |
844 DDSBesChanged1=TRUE; | |
845 t2_1=utc; | |
846 | |
847 } | |
848 | |
849 } | |
850 else{ | |
851 | |
852 if(Step3_1==FALSE){ | |
853 if (nstabilization<3) | |
854 {nstabilization= nstabilization+1; | |
855 TimetoBegin=TRUE;} | |
856 else | |
857 { | |
858 if (utc-t2_1<DeltaT_1) { | |
859 if (TimetoBegin==TRUE) | |
860 { | |
861 t2_1=utc; | |
862 TimetoBegin=FALSE; | |
863 } | |
864 Frepplus_1=Frepplus_1 +Math1-Slope_1*(utc-t2_1); | |
865 Ch4Plus=Ch4Plus + Ch4 -Ch4Slope*(utc-t2_1); | |
866 n_1=n_1+1; | |
867 } | |
868 else{ | |
869 Frepplus_1=Frepplus_1/n_1; | |
870 Ch4Plus=Ch4Plus/n_1; | |
871 n_1=0; | |
872 Step3_1=TRUE ; | |
873 nstabilization=0; | |
874 DDS4xAD9912_FrequencyRampe ( &DDS4xAD9912,1, (FrequDDS1+DeltakHz_1*1000),(FrequDDS1-DeltakHz_1*1000), Step1/Ndiv ) ; | |
875 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_1*1000)) ; | |
876 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1-DeltakHz_1*1000)); | |
877 } | |
878 } | |
879 } | |
880 | |
881 else { | |
882 if (DDSBesChanged2==FALSE){ | |
883 | |
884 if (nDDSChange<3) | |
885 { nDDSChange=nDDSChange+1;} | |
886 | |
887 else | |
888 { | |
889 nDDSChange=0; | |
890 | |
891 | |
892 DeltaFrep275=275000-Ch4; | |
893 FrequencyDDSBes=FrequencyDDSBes+(DeltaFrep275) ; | |
894 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ; | |
895 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes); | |
896 DDSBesChanged2=TRUE; | |
897 t3_1=utc; | |
898 | |
899 | |
900 } | |
901 } | |
902 | |
903 else{ | |
904 if (nstabilization<3) | |
905 { nstabilization=nstabilization+1; | |
906 TimetoBegin=TRUE;} | |
907 else | |
908 { | |
909 if (utc-t3_1<DeltaT_1) { | |
910 if (TimetoBegin==TRUE) | |
911 { | |
912 t3_1=utc; | |
913 TimetoBegin=FALSE; | |
914 } | |
915 | |
916 Frepminus_1=Frepminus_1 +Math1-Slope_1*(utc-t3_1); | |
917 Ch4Minus=Ch4Minus+Ch4-Ch4Slope*(utc-t3_1); | |
918 n_1=n_1+1; | |
919 } | |
920 else{ | |
921 Frepminus_1=Frepminus_1/(n_1); | |
922 Ch4Minus=Ch4Minus/(n_1); | |
923 N_1 = Signe1*(2*Ndiv*DeltakHz_1*1000 /*-(Ch4Plus-Ch4Minus)-Ch4Slope*(t3_1-t2_1)*/)/(Frepminus_1-Frepplus_1-Slope_1*(t3_1-t2_1)); | |
924 n_1=0; | |
925 Frepminus_1=0.0; | |
926 Frepplus_1=0.0; | |
927 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_1*1000,FrequDDS1, Step1/Ndiv ) ; | |
928 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; | |
929 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1); | |
930 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBesInit); | |
931 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ; | |
932 Measuring_1=FALSE ; | |
933 Step1_1=FALSE ; | |
934 Step2_1=FALSE ; | |
935 Step3_1=FALSE ; | |
936 t1_1=0.0; | |
937 t2_1=0.0; | |
938 t3_1=0.0; | |
939 DDSBesChanged1=FALSE; | |
940 DDSBesChanged2=FALSE; | |
941 FrequencyDDSBes=0.0; | |
942 nstabilization=0; | |
943 | |
944 } | |
945 } | |
946 } | |
947 } | |
948 } | |
949 } | |
950 } | |
951 } | |
952 | |
953 | |
954 | |
955 | |
956 | |
957 | 956 |
958 if (Measuring_2==TRUE) | 957 if (Measuring_2==TRUE) |
959 { | 958 { |
960 if (Step1_2==FALSE) { | 959 if (Step1_2==FALSE) { |
961 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; | 960 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; |