comparison FXAnalyse.c @ 256:708de02ef948

Implement limit to frequency adjustment during recenter
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 05 Jun 2015 21:00:54 +0200
parents 67c8ace9d5f6
children 8cbfce046d41
comparison
equal deleted inserted replaced
255:ada536bc461b 256:708de02ef948
255 return 0; 255 return 0;
256 } 256 }
257 257
258 258
259 enum { 259 enum {
260 LO = 1, 260 LO,
261 HG = 2, 261 HG,
262 SR = 4, 262 SR,
263 _N_BEATS,
263 }; 264 };
264 265
265 enum { 266 enum {
266 N_MEASUREMENT_NONE, 267 N_MEASUREMENT_NONE,
267 N_MEASUREMENT_INIT, 268 N_MEASUREMENT_INIT,
497 } 498 }
498 499
499 500
500 // recenter 501 // recenter
501 struct recenter { 502 struct recenter {
502 int enabled; // recenter enabled 503 int active; // recenter enabled
503 int lo; // recenter microwave beatnote 504 int enabled[_N_BEATS]; // which beatnotes to recenter
504 int sr; // recenter Sr beatnote 505 double threshold[_N_BEATS]; // maximum frequency correction
505 int hg; // recenter Hg beatnote 506 double interval; // interval
506 double interval; // interval 507 double t0; // beginning of current interval
507 double t0; // beginning of current interval
508 }; 508 };
509 509
510 struct recenter recenter = { 510 struct recenter recenter = {
511 .enabled = FALSE, 511 .active = FALSE,
512 .lo = FALSE, 512 .enabled = { FALSE, FALSE, FALSE },
513 .sr = FALSE, 513 .threshold = { 10.0, 2000.0, 2000.0 },
514 .hg = FALSE,
515 .interval = 1800.0, 514 .interval = 1800.0,
516 .t0 = 0.0 515 .t0 = 0.0
517 }; 516 };
517
518
519 int recenter_enabled()
520 {
521 if (! recenter.active)
522 return FALSE;
523
524 for (int i = 0; i < _N_BEATS; i++)
525 if (recenter.enabled[i])
526 return TRUE;
527
528 return FALSE;
529 }
530
531
532 void recenter_update()
533 {
534 if (! recenter_enabled())
535 return;
536
537 rollmean_accumulate(&rollmean_ch2, Ch2);
538 rollmean_accumulate(&rollmean_ch3, Ch3);
539 rollmean_accumulate(&rollmean_ch4, Ch4);
540
541 if ((utc - recenter.t0) > recenter.interval) {
542
543 if (recenter.enabled[LO]) {
544 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz
545 double freq = ad9912.frequency[1];
546 double adj = 275000.0 - rollmean_ch4.mean;
547 if (fabs(adj) > recenter.threshold[LO]) {
548 logmessage(WARNING, "not recenter ch4 to 275 kHz: DDS2 adjustment=%+3e exceeds threshold", adj);
549 } else {
550 freq = freq + adj;
551 ad9912_set_frequency_w(&ad9912, 1, freq);
552 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
553 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj);
554 }
555 }
556
557 if (recenter.enabled[HG]) {
558 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz
559 double freq = ad9912.frequency[2];
560 double adj = 10000 - rollmean_ch2.mean;
561 if (fabs(adj) > recenter.threshold[HG]) {
562 logmessage(WARNING, "not recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e exceeds threshold", adj);
563 } else {
564 freq = freq + adj;
565 ad9912_set_frequency_w(&ad9912, 2, freq);
566 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
567 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj);
568 }
569 }
570
571 if (recenter.enabled[SR]) {
572 // adjust DDS4 frequency to keep Ch3 reading at 10 kHz
573 double freq = ad9912.frequency[3];
574 double adj = 10000 - rollmean_ch3.mean;
575 if (fabs(adj) > recenter.threshold[SR]) {
576 logmessage(WARNING, "not recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e exceeds threshold", adj);
577 } else {
578 freq = freq + adj;
579 ad9912_set_frequency_w(&ad9912, 3, freq);
580 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
581 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj);
582 }
583 }
584
585 recenter.t0 = utc;
586 rollmean_zero(&rollmean_ch2);
587 rollmean_zero(&rollmean_ch3);
588 rollmean_zero(&rollmean_ch4);
589 }
590 }
518 591
519 592
520 // data loggging 593 // data loggging
521 static char *datafolder; 594 static char *datafolder;
522 595
1472 1545
1473 // dedrift 1546 // dedrift
1474 dedrift_update(f); 1547 dedrift_update(f);
1475 1548
1476 // recenter 1549 // recenter
1477 if (recenter.enabled) 1550 recenter_update();
1478 {
1479 rollmean_accumulate(&rollmean_ch2, Ch2);
1480 rollmean_accumulate(&rollmean_ch3, Ch3);
1481 rollmean_accumulate(&rollmean_ch4, Ch4);
1482
1483 if ((utc - recenter.t0) > recenter.interval) {
1484
1485 if (recenter.lo) {
1486 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz
1487 double freq = ad9912.frequency[1];
1488 double adj = 275000.0 - rollmean_ch4.mean;
1489 freq = freq + adj;
1490 ad9912_set_frequency_w(&ad9912, 1, freq);
1491 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]);
1492 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj);
1493 }
1494
1495 if (recenter.hg) {
1496 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz
1497 double freq = ad9912.frequency[2];
1498 double adj = 10000 - rollmean_ch2.mean;
1499 freq = freq + adj;
1500 ad9912_set_frequency_w(&ad9912, 2, freq);
1501 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]);
1502 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj);
1503 }
1504
1505 if (recenter.sr) {
1506 // adjust DDS4 frequency to keep Ch3 reading at 10 kHz
1507 double freq = ad9912.frequency[3];
1508 double adj = 10000 - rollmean_ch3.mean;
1509 freq = freq + adj;
1510 ad9912_set_frequency_w(&ad9912, 3, freq);
1511 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]);
1512 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj);
1513 }
1514
1515 recenter.t0 = utc;
1516 rollmean_zero(&rollmean_ch2);
1517 rollmean_zero(&rollmean_ch3);
1518 rollmean_zero(&rollmean_ch4);
1519 }
1520 }
1521 1551
1522 struct tm *time = gmtime(&ev.time.tv_sec); 1552 struct tm *time = gmtime(&ev.time.tv_sec);
1523 // round to milliseconds 1553 // round to milliseconds
1524 int msec = round(ev.time.tv_usec / 1000.0); 1554 int msec = round(ev.time.tv_usec / 1000.0);
1525 while (msec >= 1000) { 1555 while (msec >= 1000) {
2019 void *callbackData, int eventData1, int eventData2) 2049 void *callbackData, int eventData1, int eventData2)
2020 { 2050 {
2021 switch (event) 2051 switch (event)
2022 { 2052 {
2023 case EVENT_COMMIT: 2053 case EVENT_COMMIT:
2024 GetCtrlVal(panel, control, &recenter.enabled); 2054 GetCtrlVal(panel, control, &recenter.active);
2025 recenter.t0 = utc; 2055 recenter.t0 = utc;
2026 rollmean_zero(&rollmean_ch2); 2056 rollmean_zero(&rollmean_ch2);
2027 rollmean_zero(&rollmean_ch3); 2057 rollmean_zero(&rollmean_ch3);
2028 rollmean_zero(&rollmean_ch4); 2058 rollmean_zero(&rollmean_ch4);
2029 break; 2059 break;
2198 { 2228 {
2199 case EVENT_COMMIT: 2229 case EVENT_COMMIT:
2200 switch (control) 2230 switch (control)
2201 { 2231 {
2202 case PANEL_RECENTER_LO: 2232 case PANEL_RECENTER_LO:
2203 GetCtrlVal(panel, control, &recenter.lo); 2233 GetCtrlVal(panel, control, &recenter.enabled[LO]);
2204 break; 2234 break;
2205 case PANEL_RECENTER_HG: 2235 case PANEL_RECENTER_HG:
2206 GetCtrlVal(panel, control, &recenter.hg); 2236 GetCtrlVal(panel, control, &recenter.enabled[HG]);
2207 break; 2237 break;
2208 case PANEL_RECENTER_SR: 2238 case PANEL_RECENTER_SR:
2209 GetCtrlVal(panel, control, &recenter.sr); 2239 GetCtrlVal(panel, control, &recenter.enabled[SR]);
2240 break;
2241 }
2242 break;
2243 }
2244 return 0;
2245 }
2246
2247 int CVICALLBACK CB_RecenterThreshold (int panel, int control, int event,
2248 void *callbackData, int eventData1, int eventData2)
2249 {
2250 switch (event)
2251 {
2252 case EVENT_COMMIT:
2253 switch (control)
2254 {
2255 case PANEL_RECENTER_THRESHOLD_LO:
2256 GetCtrlVal(panel, control, &recenter.threshold[LO]);
2257 break;
2258 case PANEL_RECENTER_THRESHOLD_HG:
2259 GetCtrlVal(panel, control, &recenter.threshold[HG]);
2260 break;
2261 case PANEL_RECENTER_THRESHOLD_SR:
2262 GetCtrlVal(panel, control, &recenter.threshold[SR]);
2210 break; 2263 break;
2211 } 2264 }
2212 break; 2265 break;
2213 } 2266 }
2214 return 0; 2267 return 0;
2407 HidePanel(panel); 2460 HidePanel(panel);
2408 break; 2461 break;
2409 } 2462 }
2410 return 0; 2463 return 0;
2411 } 2464 }
2465