comparison FXAnalyse.c @ 227:a2f99632a80c

Implement N estimate tacking into account measured beatnote frequency
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 19 Sep 2014 19:04:47 +0200
parents c244a1ecb6c3
children 5e69d9abbbf2
comparison
equal deleted inserted replaced
226:c244a1ecb6c3 227:a2f99632a80c
22 #include "config.h" 22 #include "config.h"
23 #include "logging.h" 23 #include "logging.h"
24 24
25 25
26 #define FREP_STEP_SIZE 50000.0 26 #define FREP_STEP_SIZE 50000.0
27
27 #define SPEED_OF_LIGHT 299792458.0 // m/s 28 #define SPEED_OF_LIGHT 299792458.0 // m/s
28 #define SR_WAVELENGTH 698.4460 // nm 29
29 #define HG_WAVELENGTH 1062.4000 // nm 30 #define SR_FREQUENCY 429.228293 // THz
31 #define SR_WAVELENGTH (SPEED_OF_LIGHT / SR_FREQUENCY / 1.0e3) // nm
32
33 #define HG_FREQUENCY 282.143 // THz
34 #define HG_WAVELENGTH (SPEED_OF_LIGHT / HG_FREQUENCY / 1.0e3) // nm
30 35
31 36
32 // select which data provider to use 37 // select which data provider to use
33 #ifdef NDEBUG 38 #ifdef NDEBUG
34 #define DataProvider KKDataProvider 39 #define DataProvider KKDataProvider
1614 case EVENT_COMMIT: 1619 case EVENT_COMMIT:
1615 switch (control) { 1620 switch (control) {
1616 case PANEL_N1CALCULUS: 1621 case PANEL_N1CALCULUS:
1617 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1622 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1618 if (! visible) { 1623 if (! visible) {
1619 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, LO); 1624 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(LO));
1620 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); 1625 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo");
1621 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_1); 1626 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_1);
1622 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_1); 1627 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_1);
1623 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0); 1628 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_1 / 1000.0);
1624 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1629 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1626 } 1631 }
1627 break; 1632 break;
1628 case PANEL_N2CALCULUS: 1633 case PANEL_N2CALCULUS:
1629 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1634 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1630 if (! visible) { 1635 if (! visible) {
1631 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, HG); 1636 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG));
1632 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); 1637 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg");
1633 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_2); 1638 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_2);
1634 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_2); 1639 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_2);
1635 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0); 1640 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_2 / 1000.0);
1636 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1641 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1638 } 1643 }
1639 break; 1644 break;
1640 case PANEL_N3CALCULUS: 1645 case PANEL_N3CALCULUS:
1641 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); 1646 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible);
1642 if (! visible) { 1647 if (! visible) {
1643 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, SR); 1648 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR));
1644 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); 1649 SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr");
1645 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_3); 1650 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_3);
1646 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_3); 1651 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_3);
1647 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0); 1652 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock_3 / 1000.0);
1648 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); 1653 SetCtrlVal(CalcNPanel, CALCN_N, 0.0);
1656 } 1661 }
1657 1662
1658 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, 1663 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event,
1659 void *callbackData, int eventData1, int eventData2) 1664 void *callbackData, int eventData1, int eventData2)
1660 { 1665 {
1666 void *v;
1661 int measuring; 1667 int measuring;
1662 1668
1663 switch (event) { 1669 switch (event) {
1664 case EVENT_COMMIT: 1670 case EVENT_COMMIT:
1665 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); 1671 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
1672 measuring = PTR_TO_INT(v);
1666 switch (measuring) { 1673 switch (measuring) {
1667 case LO: 1674 case LO:
1668 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_1); 1675 GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_1);
1669 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_1); 1676 GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &slope_time_1);
1670 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); 1677 GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1);
1695 } 1702 }
1696 1703
1697 int CVICALLBACK CB_OnNStop (int panel, int control, int event, 1704 int CVICALLBACK CB_OnNStop (int panel, int control, int event,
1698 void *callbackData, int eventData1, int eventData2) 1705 void *callbackData, int eventData1, int eventData2)
1699 { 1706 {
1707 void *v;
1700 int measuring; 1708 int measuring;
1701 1709
1702 switch (event) { 1710 switch (event) {
1703 case EVENT_COMMIT: 1711 case EVENT_COMMIT:
1704 HidePanel(CalcNPanel); 1712 HidePanel(CalcNPanel);
1705 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); 1713 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
1714 measuring = PTR_TO_INT(v);
1706 switch (measuring) { 1715 switch (measuring) {
1707 case LO: 1716 case LO:
1708 n_measurement_1 = FALSE; 1717 n_measurement_1 = FALSE;
1709 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE); 1718 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS1, FREP_STEP_SIZE);
1710 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2); 1719 ad9912_set_frequency_w(&ad9912, 1, f0_DDS2);
1934 break; 1943 break;
1935 } 1944 }
1936 return 0; 1945 return 0;
1937 } 1946 }
1938 1947
1939 int CVICALLBACK CB_OnEstimateN (int panel, int control, int event,
1940 void *callbackData, int eventData1, int eventData2)
1941 {
1942 int visible;
1943
1944 switch (event)
1945 {
1946 case EVENT_COMMIT:
1947 // reset N estimate
1948 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0);
1949 // set current frep
1950 SetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, 250e6 + Math1);
1951 switch (control) {
1952 case PANEL_ESTIMATE_N2:
1953 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH);
1954 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg");
1955 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, HG);
1956 break;
1957 case PANEL_ESTIMATE_N3:
1958 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH);
1959 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr");
1960 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, SR);
1961 break;
1962 }
1963 GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible);
1964 if (! visible)
1965 DisplayPanel(EstimateNPanel);
1966 break;
1967 }
1968 return 0;
1969 }
1970
1971 int CVICALLBACK CB_OnNEstimateCancel (int panel, int control, int event,
1972 void *callbackData, int eventData1, int eventData2)
1973 {
1974 int visible;
1975
1976 switch (event)
1977 {
1978 case EVENT_COMMIT:
1979 GetPanelAttribute(panel, ATTR_VISIBLE, &visible);
1980 if (visible)
1981 HidePanel(panel);
1982 break;
1983 }
1984 return 0;
1985 }
1986
1987 int CVICALLBACK CB_OnNEstimateSet (int panel, int control, int event,
1988 void *callbackData, int eventData1, int eventData2)
1989 {
1990 int estimate;
1991
1992 switch (event)
1993 {
1994 case EVENT_COMMIT:
1995 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate);
1996 switch (estimate) {
1997 case HG:
1998 GetCtrlVal(panel, ESTIMATEN_N, &N2);
1999 SetCtrlVal(MainPanel, PANEL_N2, N2);
2000 break;
2001 case SR:
2002 GetCtrlVal(panel, ESTIMATEN_N, &N3);
2003 SetCtrlVal(MainPanel, PANEL_N3, N3);
2004 break;
2005 }
2006 HidePanel(panel);
2007 break;
2008 }
2009 return 0;
2010 }
2011
2012 int CVICALLBACK CB_OnNEstimate (int panel, int control, int event,
2013 void *callbackData, int eventData1, int eventData2)
2014 {
2015 double frep, wl, N;
2016
2017 switch (event)
2018 {
2019 case EVENT_COMMIT:
2020 GetCtrlVal(panel, ESTIMATEN_FREP, &frep);
2021 GetCtrlVal(panel, ESTIMATEN_WAVELENGTH, &wl);
2022 N = round(SPEED_OF_LIGHT / wl / 1e-9 / frep);
2023 SetCtrlVal(panel, ESTIMATEN_N, N);
2024 break;
2025 }
2026 return 0;
2027 }
2028
2029 int CVICALLBACK CB_SetSlope (int panel, int control, int event, 1948 int CVICALLBACK CB_SetSlope (int panel, int control, int event,
2030 void *callbackData, int eventData1, int eventData2) 1949 void *callbackData, int eventData1, int eventData2)
2031 { 1950 {
2032 switch (event) 1951 switch (event)
2033 { 1952 {
2217 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied); 2136 ad9956_set_w(&ad9956, dedrift.freq0, dedrift.applied);
2218 break; 2137 break;
2219 } 2138 }
2220 return 0; 2139 return 0;
2221 } 2140 }
2141
2142
2143 //
2144 // N estimate
2145 //
2146
2147 static void estimateN (void)
2148 {
2149 double nu, fbeat, frep, N;
2150 int sign;
2151
2152 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, &nu);
2153 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, &frep);
2154 GetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, &fbeat);
2155 GetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, &sign);
2156
2157 N = (nu * 1.0e12 - sign * fbeat) / frep;
2158
2159 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, N);
2160 }
2161
2162 int CVICALLBACK cb_onEstimateN (int panel, int control, int event,
2163 void *callbackData, int eventData1, int eventData2)
2164 {
2165 int visible;
2166
2167 switch (event)
2168 {
2169 case EVENT_COMMIT:
2170 // reset N estimate
2171 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0);
2172 // set current frep
2173 SetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, 250e6 + Math1);
2174 switch (control) {
2175 case PANEL_ESTIMATE_N2:
2176 // expected frequency
2177 SetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, HG_FREQUENCY);
2178 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH);
2179 // sign
2180 SetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, (int)Sign2);
2181 // f_DDS
2182 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[2]);
2183 // f_counter
2184 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch2);
2185 // f_beat
2186 SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[2] - Ch2);
2187
2188 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg");
2189 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG));
2190 break;
2191 case PANEL_ESTIMATE_N3:
2192 // expected frequency
2193 SetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, SR_FREQUENCY);
2194 SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH);
2195 // sign
2196 SetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, (int)Sign3);
2197 // f_DDS
2198 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[3]);
2199 // f_counter
2200 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch3);
2201 // f_beat
2202 SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[3] - Ch3);
2203
2204 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr");
2205 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR));
2206 break;
2207 }
2208
2209 // display dialog
2210 GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible);
2211 if (! visible)
2212 DisplayPanel(EstimateNPanel);
2213
2214 // compute
2215 estimateN();
2216 break;
2217 }
2218 return 0;
2219 }
2220
2221 int CVICALLBACK cb_onEstimateNWaveleght (int panel, int control, int event,
2222 void *callbackData, int eventData1, int eventData2)
2223 {
2224 double wavelenght, frequency;
2225
2226 switch (event)
2227 {
2228 case EVENT_COMMIT:
2229 GetCtrlVal(panel, control, &wavelenght);
2230 frequency = SPEED_OF_LIGHT / (wavelenght * 1.0e-9) / 1.0e12;
2231 SetCtrlVal(panel, ESTIMATEN_FREQUENCY, frequency);
2232 estimateN();
2233 break;
2234 }
2235 return 0;
2236 }
2237
2238 int CVICALLBACK cb_onEstimateNFrequency (int panel, int control, int event,
2239 void *callbackData, int eventData1, int eventData2)
2240 {
2241 double wavelenght, frequency;
2242
2243 switch (event)
2244 {
2245 case EVENT_COMMIT:
2246 GetCtrlVal(panel, control, &frequency);
2247 wavelenght = SPEED_OF_LIGHT / (frequency * 1.0e12) / 1.0e-9;
2248 SetCtrlVal(panel, ESTIMATEN_WAVELENGTH, wavelenght);
2249 estimateN();
2250 break;
2251 }
2252 return 0;
2253 }
2254
2255 int CVICALLBACK cb_onEstimateNChange (int panel, int control, int event,
2256 void *callbackData, int eventData1, int eventData2)
2257 {
2258 switch (event)
2259 {
2260 case EVENT_COMMIT:
2261 estimateN();
2262 break;
2263 }
2264 return 0;
2265 }
2266
2267 int CVICALLBACK cb_onEstimateNClose (int panel, int control, int event,
2268 void *callbackData, int eventData1, int eventData2)
2269 {
2270 int visible;
2271
2272 switch (event)
2273 {
2274 case EVENT_COMMIT:
2275 GetPanelAttribute(panel, ATTR_VISIBLE, &visible);
2276 if (visible)
2277 HidePanel(panel);
2278 break;
2279 }
2280 return 0;
2281 }
2282
2283 int CVICALLBACK cb_onEstimateNSet (int panel, int control, int event,
2284 void *callbackData, int eventData1, int eventData2)
2285 {
2286 void *v;
2287 int estimate = 0;
2288
2289 switch (event)
2290 {
2291 case EVENT_COMMIT:
2292 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v);
2293 estimate = PTR_TO_INT(v);
2294 switch (estimate) {
2295 case HG:
2296 GetCtrlVal(panel, ESTIMATEN_N, &N2);
2297 SetCtrlVal(MainPanel, PANEL_N2, N2);
2298 break;
2299 case SR:
2300 GetCtrlVal(panel, ESTIMATEN_N, &N3);
2301 SetCtrlVal(MainPanel, PANEL_N3, N3);
2302 break;
2303 }
2304 HidePanel(panel);
2305 break;
2306 }
2307 return 0;
2308 }