comparison FXAnalyse.c @ 223:7875436125dd

Variable names clarification and cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 18 Sep 2014 18:03:27 +0200
parents db051dbf8d6e
children c244a1ecb6c3
comparison
equal deleted inserted replaced
222:db051dbf8d6e 223:7875436125dd
239 N_MEASUREMENT_FREP_PLUS, 239 N_MEASUREMENT_FREP_PLUS,
240 N_MEASUREMENT_ADJUST_FREQ_MINUS, 240 N_MEASUREMENT_ADJUST_FREQ_MINUS,
241 N_MEASUREMENT_FREP_MINUS, 241 N_MEASUREMENT_FREP_MINUS,
242 }; 242 };
243 243
244 int Measuring_1 = N_MEASUREMENT_NONE; 244 int n_measurement_1 = N_MEASUREMENT_NONE;
245 int Measuring_2 = N_MEASUREMENT_NONE; 245 int n_measurement_2 = N_MEASUREMENT_NONE;
246 int Measuring_3 = N_MEASUREMENT_NONE; 246 int n_measurement_3 = N_MEASUREMENT_NONE;
247 247
248 int nobs = 0; 248 int nobs = 0;
249 int settling = 0; 249 int settling = 0;
250 250
251 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3, f0_DDS4, df_DDS3; 251 double f0_DDS1 = 110000000.0, f0_DDS2, f0_DDS3, f0_DDS4, df_DDS3;
252 252
253 double SlopeTime1 = 40.0, DeltaT_1 = 40.0, delta_f_lock_1 = 500e3; 253 double slope_time_1 = 40.0, integration_time_1 = 40.0, delta_f_lock_1 = 500e3;
254 double SlopeTime2 = 40.0, DeltaT_2 = 40.0, delta_f_lock_2 = 500e3; 254 double slope_time_2 = 40.0, integration_time_2 = 40.0, delta_f_lock_2 = 500e3;
255 double SlopeTime3 = 40.0, DeltaT_3 = 40.0, delta_f_lock_3 = 500e3; 255 double slope_time_3 = 40.0, integration_time_3 = 40.0, delta_f_lock_3 = 500e3;
256 256
257 double t1, t2, t3; 257 double t1, t2, t3;
258 double f_rep_slope, f_beat_slope; 258 double f_rep_slope, f_beat_slope;
259 double f_rep_plus, f_rep_minus; 259 double f_rep_plus, f_rep_minus;
260 double f_beat_plus, f_beat_minus; 260 double f_beat_plus, f_beat_minus;
261 double N_measured; 261
262 262
263 // Beatnote sign determination is done stepping the repetition rate by 263 // Beatnote sign determination is done stepping the repetition rate by
264 // stepping the comb phase-lock offset frequency f_lock generated by 264 // stepping the comb phase-lock offset frequency f_lock generated by
265 // DDS1. A lock frequency step delta_f_lock determines a change in the 265 // DDS1. A lock frequency step delta_f_lock determines a change in the
266 // repetition rate given by: 266 // repetition rate given by:
750 read = CmtReadTSQData(queueHandle, &event, 1, TSQ_INFINITE_TIMEOUT, 0); 750 read = CmtReadTSQData(queueHandle, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
751 if (read != 1) 751 if (read != 1)
752 logmsg("Error!"); 752 logmsg("Error!");
753 value = value - read; 753 value = value - read;
754 754
755 // unpack event
755 utc = event.time.tv_sec + event.time.tv_usec * 1e-6; 756 utc = event.time.tv_sec + event.time.tv_usec * 1e-6;
756 Ch1 = event.data[0]; 757 Ch1 = event.data[0];
757 Ch2 = event.data[1]; 758 Ch2 = event.data[1];
758 Ch3 = event.data[2]; 759 Ch3 = event.data[2];
759 Ch4 = event.data[3]; 760 Ch4 = event.data[3];
790 for (struct adev *adev = adevs; adev->data; adev++) 791 for (struct adev *adev = adevs; adev->data; adev++)
791 adev_update(adev); 792 adev_update(adev);
792 793
793 // N measurement 794 // N measurement
794 795
795 switch (Measuring_1) { 796 switch (n_measurement_1) {
796 797
797 case N_MEASUREMENT_NONE: 798 case N_MEASUREMENT_NONE:
798 // not measuring 799 // not measuring
799 break; 800 break;
800 801
813 nobs = 0; 814 nobs = 0;
814 stat_zero(&stat_math1); 815 stat_zero(&stat_math1);
815 f_rep_plus = f_rep_minus = 0.0; 816 f_rep_plus = f_rep_minus = 0.0;
816 817
817 // next step 818 // next step
818 Measuring_1 += 1; 819 n_measurement_1 += 1;
819 break; 820 break;
820 821
821 case N_MEASUREMENT_SLOPE: 822 case N_MEASUREMENT_SLOPE:
822 // slope measurement 823 // slope measurement
823 824
824 stat_accumulate(&stat_math1, Math1); 825 stat_accumulate(&stat_math1, Math1);
825 826
826 if ((utc - t1) > SlopeTime1) { 827 if ((utc - t1) > slope_time_1) {
827 f_rep_slope = stat_math1.slope; 828 f_rep_slope = stat_math1.slope;
828 829
829 // frep positive step 830 // frep positive step
830 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE); 831 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 + delta_f_lock_1, FREP_STEP_SIZE);
831 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 832 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
832 833
833 // allow counter to settle 834 // allow counter to settle
834 settling = 3; 835 settling = 3;
835 836
836 // next step 837 // next step
837 Measuring_1 += 1; 838 n_measurement_1 += 1;
838 } 839 }
839 break; 840 break;
840 841
841 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 842 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
842 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 843 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
851 852
852 // allow counter to settle 853 // allow counter to settle
853 settling = 3; 854 settling = 3;
854 855
855 // next step 856 // next step
856 Measuring_1 += 1; 857 n_measurement_1 += 1;
857 break; 858 break;
858 859
859 case N_MEASUREMENT_FREP_PLUS: 860 case N_MEASUREMENT_FREP_PLUS:
860 // frep positive step 861 // frep positive step
861 862
866 t2 = utc; 867 t2 = utc;
867 868
868 f_rep_plus += Math1 - f_rep_slope * (utc - t2); 869 f_rep_plus += Math1 - f_rep_slope * (utc - t2);
869 nobs += 1; 870 nobs += 1;
870 871
871 if ((utc - t2) > DeltaT_1) { 872 if ((utc - t2) > integration_time_1) {
872 f_rep_plus = f_rep_plus / nobs; 873 f_rep_plus = f_rep_plus / nobs;
873 nobs = 0; 874 nobs = 0;
874 875
875 // frep negative step 876 // frep negative step
876 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE); 877 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1 - delta_f_lock_1, FREP_STEP_SIZE);
878 879
879 // allow counter to settle 880 // allow counter to settle
880 settling = 3; 881 settling = 3;
881 882
882 // next step 883 // next step
883 Measuring_1 += 1; 884 n_measurement_1 += 1;
884 } 885 }
885 break; 886 break;
886 887
887 case N_MEASUREMENT_FREP_MINUS: 888 case N_MEASUREMENT_FREP_MINUS:
888 // frep negative step 889 // frep negative step
894 t3 = utc; 895 t3 = utc;
895 896
896 f_rep_minus += Math1 - f_rep_slope * (utc - t2); 897 f_rep_minus += Math1 - f_rep_slope * (utc - t2);
897 nobs += 1; 898 nobs += 1;
898 899
899 if ((utc - t3) > DeltaT_1) { 900 if ((utc - t3) > integration_time_1) {
900 f_rep_minus = f_rep_minus / nobs; 901 f_rep_minus = f_rep_minus / nobs;
901 nobs = 0; 902 nobs = 0;
902 903
903 // compute N1 904 // compute N1
904 double delta_f_rep = f_rep_minus - f_rep_plus; 905 double delta_f_rep = f_rep_minus - f_rep_plus;
905 N_measured = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep; 906 double measured = Sign1 * 2 * Ndiv * delta_f_lock_1 / delta_f_rep;
906 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 907 SetCtrlVal(CalcNPanel, CALCN_N, measured);
907 908
908 // back to nominal frep 909 // back to nominal frep
909 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 910 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
910 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 911 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
911 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 912 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
912 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 913 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
913 914
914 // done 915 // done
915 Measuring_1 = N_MEASUREMENT_NONE; 916 n_measurement_1 = N_MEASUREMENT_NONE;
916 } 917 }
917 break; 918 break;
918 } 919 }
919 920
920 switch (Measuring_2) { 921 switch (n_measurement_2) {
921 922
922 case N_MEASUREMENT_NONE: 923 case N_MEASUREMENT_NONE:
923 // not measuring 924 // not measuring
924 break; 925 break;
925 926
941 stat_zero(&stat_ch2); 942 stat_zero(&stat_ch2);
942 f_rep_plus = f_rep_minus = 0.0; 943 f_rep_plus = f_rep_minus = 0.0;
943 f_beat_plus = f_beat_minus = 0.0; 944 f_beat_plus = f_beat_minus = 0.0;
944 945
945 // next step 946 // next step
946 Measuring_2 += 1; 947 n_measurement_2 += 1;
947 break; 948 break;
948 949
949 case N_MEASUREMENT_SLOPE: 950 case N_MEASUREMENT_SLOPE:
950 // slope measurement 951 // slope measurement
951 952
952 stat_accumulate(&stat_math1, Math1); 953 stat_accumulate(&stat_math1, Math1);
953 stat_accumulate(&stat_ch2, Ch2); 954 stat_accumulate(&stat_ch2, Ch2);
954 955
955 if ((utc - t1) > SlopeTime2) { 956 if ((utc - t1) > slope_time_2) {
956 f_rep_slope = stat_math1.slope; 957 f_rep_slope = stat_math1.slope;
957 f_beat_slope = stat_ch2.slope; 958 f_beat_slope = stat_ch2.slope;
958 959
959 // frep positive step 960 // frep positive step
960 double fDDS1 = f0_DDS1 + delta_f_lock_2; 961 double fDDS1 = f0_DDS1 + delta_f_lock_2;
969 970
970 // allow counter to settle 971 // allow counter to settle
971 settling = 3; 972 settling = 3;
972 973
973 // next step 974 // next step
974 Measuring_2 += 1; 975 n_measurement_2 += 1;
975 } 976 }
976 break; 977 break;
977 978
978 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 979 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
979 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 980 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
993 994
994 // allow counter to settle 995 // allow counter to settle
995 settling = 3; 996 settling = 3;
996 997
997 // next step 998 // next step
998 Measuring_2 += 1; 999 n_measurement_2 += 1;
999 break; 1000 break;
1000 1001
1001 case N_MEASUREMENT_FREP_PLUS: 1002 case N_MEASUREMENT_FREP_PLUS:
1002 // frep positive step 1003 // frep positive step
1003 1004
1009 1010
1010 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1011 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1011 f_beat_plus += Ch2 - f_beat_slope * (utc - t2); 1012 f_beat_plus += Ch2 - f_beat_slope * (utc - t2);
1012 nobs += 1; 1013 nobs += 1;
1013 1014
1014 if ((utc - t2) > DeltaT_2) { 1015 if ((utc - t2) > integration_time_2) {
1015 f_rep_plus = f_rep_plus / nobs; 1016 f_rep_plus = f_rep_plus / nobs;
1016 f_beat_plus = f_beat_plus / nobs; 1017 f_beat_plus = f_beat_plus / nobs;
1017 nobs = 0; 1018 nobs = 0;
1018 1019
1019 // negative frequency step 1020 // negative frequency step
1029 1030
1030 // allow counter to settle 1031 // allow counter to settle
1031 settling = 3; 1032 settling = 3;
1032 1033
1033 // next step 1034 // next step
1034 Measuring_2 += 1; 1035 n_measurement_2 += 1;
1035 } 1036 }
1036 break; 1037 break;
1037 1038
1038 case N_MEASUREMENT_FREP_MINUS: 1039 case N_MEASUREMENT_FREP_MINUS:
1039 // frep negative step 1040 // frep negative step
1046 1047
1047 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1048 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1048 f_beat_minus += Ch2 + f_beat_slope * (utc - t2); 1049 f_beat_minus += Ch2 + f_beat_slope * (utc - t2);
1049 nobs += 1; 1050 nobs += 1;
1050 1051
1051 if ((utc -t3) > DeltaT_2) { 1052 if ((utc -t3) > integration_time_2) {
1052 f_rep_minus = f_rep_minus / nobs; 1053 f_rep_minus = f_rep_minus / nobs;
1053 f_beat_minus = f_beat_minus / nobs; 1054 f_beat_minus = f_beat_minus / nobs;
1054 nobs = 0; 1055 nobs = 0;
1055 1056
1056 // compute N2 1057 // compute N2
1059 double delta = delta_f_rep_m - delta_f_rep; 1060 double delta = delta_f_rep_m - delta_f_rep;
1060 1061
1061 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", 1062 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e",
1062 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); 1063 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep);
1063 1064
1064 N_measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; 1065 double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep;
1065 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 1066 SetCtrlVal(CalcNPanel, CALCN_N, measured);
1066 1067
1067 // back to nominal frequency 1068 // back to nominal frequency
1068 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1069 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1069 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1070 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1070 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3); 1071 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
1071 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1072 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1072 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 1073 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1073 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); 1074 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1074 1075
1075 // done 1076 // done
1076 Measuring_2 = N_MEASUREMENT_NONE; 1077 n_measurement_2 = N_MEASUREMENT_NONE;
1077 } 1078 }
1078 break; 1079 break;
1079 } 1080 }
1080 1081
1081 switch (Measuring_3) { 1082 switch (n_measurement_3) {
1082 1083
1083 case N_MEASUREMENT_NONE: 1084 case N_MEASUREMENT_NONE:
1084 // not measuring N3 1085 // not measuring N3
1085 break; 1086 break;
1086 1087
1102 stat_zero(&stat_ch3); 1103 stat_zero(&stat_ch3);
1103 f_rep_plus = f_rep_minus = 0.0; 1104 f_rep_plus = f_rep_minus = 0.0;
1104 f_beat_plus = f_beat_minus = 0.0; 1105 f_beat_plus = f_beat_minus = 0.0;
1105 1106
1106 // next step 1107 // next step
1107 Measuring_3 += 1; 1108 n_measurement_3 += 1;
1108 break; 1109 break;
1109 1110
1110 case N_MEASUREMENT_SLOPE: 1111 case N_MEASUREMENT_SLOPE:
1111 // slope measurement 1112 // slope measurement
1112 1113
1114 break; 1115 break;
1115 1116
1116 stat_accumulate(&stat_math1, Math1); 1117 stat_accumulate(&stat_math1, Math1);
1117 stat_accumulate(&stat_ch3, Ch3); 1118 stat_accumulate(&stat_ch3, Ch3);
1118 1119
1119 if (utc - t1 > SlopeTime3) { 1120 if (utc - t1 > slope_time_3) {
1120 // slope measurement 1121 // slope measurement
1121 f_rep_slope = stat_math1.slope; 1122 f_rep_slope = stat_math1.slope;
1122 f_beat_slope = stat_ch3.slope; 1123 f_beat_slope = stat_ch3.slope;
1123 1124
1124 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); 1125 logmsg("f_rep_slope=%e Hz/s", f_rep_slope);
1135 1136
1136 // allow counter to settle 1137 // allow counter to settle
1137 settling = 3; 1138 settling = 3;
1138 1139
1139 // next step 1140 // next step
1140 Measuring_3 += 1; 1141 n_measurement_3 += 1;
1141 } 1142 }
1142 break; 1143 break;
1143 1144
1144 case N_MEASUREMENT_ADJUST_FREQ_PLUS: 1145 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
1145 case N_MEASUREMENT_ADJUST_FREQ_MINUS: 1146 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
1155 1156
1156 // allow counter to settle 1157 // allow counter to settle
1157 settling = 3; 1158 settling = 3;
1158 1159
1159 // next step 1160 // next step
1160 Measuring_3 += 1; 1161 n_measurement_3 += 1;
1161 break; 1162 break;
1162 1163
1163 case N_MEASUREMENT_FREP_PLUS: 1164 case N_MEASUREMENT_FREP_PLUS:
1164 // frep positive step 1165 // frep positive step
1165 1166
1171 1172
1172 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1173 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1173 f_beat_plus += Ch3 - f_beat_slope * (utc - t2); 1174 f_beat_plus += Ch3 - f_beat_slope * (utc - t2);
1174 nobs += 1; 1175 nobs += 1;
1175 1176
1176 if (utc - t2 > DeltaT_3) { 1177 if (utc - t2 > integration_time_3) {
1177 f_rep_plus = f_rep_plus / nobs; 1178 f_rep_plus = f_rep_plus / nobs;
1178 f_beat_plus = f_beat_plus / nobs; 1179 f_beat_plus = f_beat_plus / nobs;
1179 nobs = 0; 1180 nobs = 0;
1180 1181
1181 // frep negative step 1182 // frep negative step
1189 1190
1190 // allow counter to settle 1191 // allow counter to settle
1191 settling = 3; 1192 settling = 3;
1192 1193
1193 // next step 1194 // next step
1194 Measuring_3 += 1; 1195 n_measurement_3 += 1;
1195 } 1196 }
1196 break; 1197 break;
1197 1198
1198 case N_MEASUREMENT_FREP_MINUS: 1199 case N_MEASUREMENT_FREP_MINUS:
1199 // frep negative step 1200 // frep negative step
1206 1207
1207 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); 1208 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2);
1208 f_beat_minus += Ch3 - f_beat_slope * (utc - t2); 1209 f_beat_minus += Ch3 - f_beat_slope * (utc - t2);
1209 nobs += 1; 1210 nobs += 1;
1210 1211
1211 if (utc - t3 > DeltaT_3) { 1212 if (utc - t3 > integration_time_3) {
1212 f_rep_minus = f_rep_minus / nobs; 1213 f_rep_minus = f_rep_minus / nobs;
1213 f_beat_minus = f_beat_minus / nobs; 1214 f_beat_minus = f_beat_minus / nobs;
1214 nobs = 0; 1215 nobs = 0;
1215 1216
1216 // check delta frep 1217 // check delta frep
1226 double delta_f_beat_expected = delta_f_rep * N3; 1227 double delta_f_beat_expected = delta_f_rep * N3;
1227 1228
1228 logmsg("delta fbeat: measured=%e expected=%e difference=%e", 1229 logmsg("delta fbeat: measured=%e expected=%e difference=%e",
1229 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); 1230 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected);
1230 1231
1231 N_measured = delta_f_beat / delta_f_rep; 1232 double measured = delta_f_beat / delta_f_rep;
1232 SetCtrlVal(CalcNPanel, CALCN_N, N_measured); 1233 SetCtrlVal(CalcNPanel, CALCN_N, measured);
1233 1234
1234 logmsg("measured N3=%.3f", N_measured); 1235 logmsg("measured N3=%.3f", measured);
1235 1236
1236 // back to nominal frep 1237 // back to nominal frep
1237 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1238 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1238 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1239 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1239 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4); 1240 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4);
1240 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); 1241 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]);
1241 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); 1242 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1242 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); 1243 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1243 1244
1244 // done 1245 // done
1245 Measuring_3 = N_MEASUREMENT_NONE; 1246 n_measurement_3 = N_MEASUREMENT_NONE;
1246 } 1247 }
1247 break; 1248 break;
1248 } 1249 }
1249 1250
1250 // beatnote sign determination 1251 // beatnote sign determination
1575 1576
1576 int CVICALLBACK CB_OnAcceptN (int panel, int control, int event, 1577 int CVICALLBACK CB_OnAcceptN (int panel, int control, int event,
1577 void *callbackData, int eventData1, int eventData2) 1578 void *callbackData, int eventData1, int eventData2)
1578 { 1579 {
1579 int measure; 1580 int measure;
1580 1581 double measured;
1582
1581 switch (event) { 1583 switch (event) {
1582 case EVENT_COMMIT: 1584 case EVENT_COMMIT:
1583 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure); 1585 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure);
1586 GetCtrlVal(panel, CALCN_N, &measured);
1584 switch (measure) { 1587 switch (measure) {
1585 case LO: 1588 case LO:
1586 N1 = round(N_measured); 1589 N1 = round(measured);
1587 SetCtrlVal(MainPanel, PANEL_N1, N1); 1590 SetCtrlVal(MainPanel, PANEL_N1, N1);
1588 break; 1591 break;
1589 case HG: 1592 case HG:
1590 N2 = round(N_measured); 1593 N2 = round(measured);
1591 SetCtrlVal(MainPanel, PANEL_N2, N2); 1594 SetCtrlVal(MainPanel, PANEL_N2, N2);
1592 break; 1595 break;
1593 case SR: 1596 case SR:
1594 N3 = round(N_measured); 1597 N3 = round(measured);
1595 SetCtrlVal(MainPanel, PANEL_N3, N3); 1598 SetCtrlVal(MainPanel, PANEL_N3, N3);
1596 break; 1599 break;
1597 } 1600 }
1598 break; 1601 break;
1599 } 1602 }
1611 case PANEL_N1CALCULUS: 1614 case PANEL_N1CALCULUS:
1612 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1615 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1613 if (! visible) { 1616 if (! visible) {
1614 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, LO); 1617 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, LO);
1615 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); 1618 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo");
1616 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); 1619 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_1);
1617 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); 1620 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_1);
1618 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); 1621 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0);
1619 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1622 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1620 DisplayPanel(CalcNPanel); 1623 DisplayPanel(CalcNPanel);
1621 } 1624 }
1622 break; 1625 break;
1623 case PANEL_N2CALCULUS: 1626 case PANEL_N2CALCULUS:
1624 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1627 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1625 if (! visible) { 1628 if (! visible) {
1626 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, HG); 1629 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, HG);
1627 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); 1630 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg");
1628 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); 1631 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_2);
1629 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); 1632 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_2);
1630 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); 1633 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0);
1631 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1634 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1632 DisplayPanel(CalcNPanel); 1635 DisplayPanel(CalcNPanel);
1633 } 1636 }
1634 break; 1637 break;
1635 case PANEL_N3CALCULUS: 1638 case PANEL_N3CALCULUS:
1636 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1639 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1637 if (! visible) { 1640 if (! visible) {
1638 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, SR); 1641 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, SR);
1639 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); 1642 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr");
1640 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); 1643 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_3);
1641 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); 1644 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_3);
1642 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); 1645 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0);
1643 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1646 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1644 DisplayPanel(CalcNPanel); 1647 DisplayPanel(CalcNPanel);
1645 } 1648 }
1646 break; 1649 break;
1658 switch (event) { 1661 switch (event) {
1659 case EVENT_COMMIT: 1662 case EVENT_COMMIT:
1660 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); 1663 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring);
1661 switch (measuring) { 1664 switch (measuring) {
1662 case LO: 1665 case LO:
1663 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); 1666 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_1);
1664 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); 1667 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_1);
1665 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); 1668 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1);
1666 // convert from kHz to Hz 1669 // convert from kHz to Hz
1667 delta_f_lock_1 = delta_f_lock_1 * 1000.0; 1670 delta_f_lock_1 = delta_f_lock_1 * 1000.0;
1668 Measuring_1 = TRUE; 1671 n_measurement_1 = TRUE;
1669 break; 1672 break;
1670 case HG: 1673 case HG:
1671 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); 1674 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_2);
1672 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); 1675 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_2);
1673 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2); 1676 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2);
1674 // convert from kHz to Hz 1677 // convert from kHz to Hz
1675 delta_f_lock_2 = delta_f_lock_2 * 1000.0; 1678 delta_f_lock_2 = delta_f_lock_2 * 1000.0;
1676 Measuring_2 = TRUE; 1679 n_measurement_2 = TRUE;
1677 break; 1680 break;
1678 case SR: 1681 case SR:
1679 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); 1682 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_3);
1680 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); 1683 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_3);
1681 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3); 1684 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3);
1682 // convert from kHz to Hz 1685 // convert from kHz to Hz
1683 delta_f_lock_3 = delta_f_lock_3 * 1000.0; 1686 delta_f_lock_3 = delta_f_lock_3 * 1000.0;
1684 Measuring_3 = TRUE; 1687 n_measurement_3 = TRUE;
1685 break; 1688 break;
1686 } 1689 }
1687 break; 1690 break;
1688 } 1691 }
1689 return 0; 1692 return 0;
1698 case EVENT_COMMIT: 1701 case EVENT_COMMIT:
1699 HidePanel(CalcNPanel); 1702 HidePanel(CalcNPanel);
1700 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); 1703 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring);
1701 switch (measuring) { 1704 switch (measuring) {
1702 case LO: 1705 case LO:
1703 Measuring_1 = FALSE; 1706 n_measurement_1 = FALSE;
1704 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1707 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1705 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1708 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1706 break; 1709 break;
1707 case HG: 1710 case HG:
1708 Measuring_2 = FALSE; 1711 n_measurement_2 = FALSE;
1709 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1712 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1710 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1713 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1711 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3); 1714 ad9912_set_frequency_w(&ad9912, 2, f0_DDS3);
1712 break; 1715 break;
1713 case SR: 1716 case SR:
1714 Measuring_3 = FALSE; 1717 n_measurement_3 = FALSE;
1715 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1718 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1716 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1719 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1717 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4); 1720 ad9912_set_frequency_w(&ad9912, 3, f0_DDS4);
1718 break; 1721 break;
1719 } 1722 }