Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 269:3f395eab72eb
Whitespace
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 10 Jul 2015 13:40:36 +0200 |
parents | ec4462c7f8b7 |
children | a451d4618dbf |
comparison
equal
deleted
inserted
replaced
268:ec4462c7f8b7 | 269:3f395eab72eb |
---|---|
1 #include <zmq.h> | 1 #include <zmq.h> |
2 #include <tcpsupp.h> | 2 #include <tcpsupp.h> |
3 #include <utility.h> | 3 #include <utility.h> |
4 #include <ansi_c.h> | 4 #include <ansi_c.h> |
5 #include <lowlvlio.h> | 5 #include <lowlvlio.h> |
6 #include <cvirte.h> | 6 #include <cvirte.h> |
7 #include <userint.h> | 7 #include <userint.h> |
8 #include <formatio.h> | 8 #include <formatio.h> |
9 #include <inifile.h> | 9 #include <inifile.h> |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include "FXAnalyse.h" | 12 #include "FXAnalyse.h" |
13 #include "Plot.h" | 13 #include "Plot.h" |
14 #include "Allan.h" | 14 #include "Allan.h" |
15 #include "ad9912.h" | 15 #include "ad9912.h" |
16 #include "ad9956.h" | 16 #include "ad9956.h" |
17 #include "muParserDLL.h" | 17 #include "muParserDLL.h" |
18 #include "utils.h" | 18 #include "utils.h" |
19 #include "stat.h" | 19 #include "stat.h" |
20 #include "future.h" | 20 #include "future.h" |
21 #include "data-provider.h" | 21 #include "data-provider.h" |
53 // ZMQ | 53 // ZMQ |
54 void *zmqcontext; | 54 void *zmqcontext; |
55 void *zmqsocket; | 55 void *zmqsocket; |
56 | 56 |
57 // utility function to send data through ZMQ socket framed by an envelope | 57 // utility function to send data through ZMQ socket framed by an envelope |
58 // see "Pub-Sub Message Envelopes" in chapter 2 "Sockets and Patterns" | 58 // see "Pub-Sub Message Envelopes" in chapter 2 "Sockets and Patterns" |
59 // of "ZMQ The Guide" http://zguide.zeromq.org/page:all#toc49 | 59 // of "ZMQ The Guide" http://zguide.zeromq.org/page:all#toc49 |
60 int zmq_xpub(void *socket, char *envelope, void *data, size_t len) | 60 int zmq_xpub(void *socket, char *envelope, void *data, size_t len) |
61 { | 61 { |
62 int r; | 62 int r; |
63 | 63 |
64 r = zmq_send(socket, envelope, strlen(envelope), ZMQ_SNDMORE); | 64 r = zmq_send(socket, envelope, strlen(envelope), ZMQ_SNDMORE); |
65 if (r < 0) | 65 if (r < 0) |
66 return zmq_errno(); | 66 return zmq_errno(); |
67 | 67 |
68 r = zmq_send(socket, data, len, 0); | 68 r = zmq_send(socket, data, len, 0); |
69 if (r < 0) | 69 if (r < 0) |
70 return zmq_errno(); | 70 return zmq_errno(); |
71 | 71 |
72 return 0; | 72 return 0; |
73 } | 73 } |
74 | 74 |
75 | 75 |
76 struct event ev; | 76 struct event ev; |
77 double utc; | 77 double utc; |
78 #define Ch1 ev.data[0] | 78 #define Ch1 ev.data[0] |
79 #define Ch2 ev.data[1] | 79 #define Ch2 ev.data[1] |
225 | 225 |
226 | 226 |
227 static int ad9956_set_w(struct ad9956 *d, double f, double s) | 227 static int ad9956_set_w(struct ad9956 *d, double f, double s) |
228 { | 228 { |
229 int r; | 229 int r; |
230 | 230 |
231 r = ad9956_sweep_stop(d); | 231 r = ad9956_sweep_stop(d); |
232 if (r) { | 232 if (r) { |
233 logmessage(ERROR, "ad9956 sweep stop error=%d", -r); | 233 logmessage(ERROR, "ad9956 sweep stop error=%d", -r); |
234 return r; | 234 return r; |
235 } | 235 } |
236 | 236 |
237 r = ad9956_set_frequency(d, f); | 237 r = ad9956_set_frequency(d, f); |
238 if (r) { | 238 if (r) { |
239 logmessage(ERROR, "ad9956 set frequency error=%d", -r); | 239 logmessage(ERROR, "ad9956 set frequency error=%d", -r); |
240 return r; | 240 return r; |
241 } | 241 } |
242 | 242 |
243 r = ad9956_set_sweep_rate(d, s); | 243 r = ad9956_set_sweep_rate(d, s); |
244 if (r) { | 244 if (r) { |
245 logmessage(ERROR, "ad9956 set sweep rate error=%d", -r); | 245 logmessage(ERROR, "ad9956 set sweep rate error=%d", -r); |
246 return r; | 246 return r; |
247 } | 247 } |
248 | 248 |
249 r = ad9956_sweep_start(d); | 249 r = ad9956_sweep_start(d); |
250 if (r) { | 250 if (r) { |
251 logmessage(ERROR, "ad9956 sweep start error=%d", -r); | 251 logmessage(ERROR, "ad9956 sweep start error=%d", -r); |
252 return r; | 252 return r; |
253 } | 253 } |
254 | 254 |
255 return 0; | 255 return 0; |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 enum { | 259 enum { |
260 NONE = -1, | 260 NONE = -1, |
283 | 283 |
284 double t1, t2, t3; | 284 double t1, t2, t3; |
285 double f_rep_slope, f_beat_slope; | 285 double f_rep_slope, f_beat_slope; |
286 double f_rep_plus, f_rep_minus; | 286 double f_rep_plus, f_rep_minus; |
287 double f_beat_plus, f_beat_minus; | 287 double f_beat_plus, f_beat_minus; |
288 | 288 |
289 double f0_DDS[4] = { 110000000.0, 0.0, 0.0, 0.0 }; | 289 double f0_DDS[4] = { 110000000.0, 0.0, 0.0, 0.0 }; |
290 double df_DDS3 = 0.0; | 290 double df_DDS3 = 0.0; |
291 | 291 |
292 int nobs = 0; | 292 int nobs = 0; |
293 int settling = 0; | 293 int settling = 0; |
294 | 294 |
295 | 295 |
296 // Beatnote sign determination is done stepping the repetition rate by | 296 // Beatnote sign determination is done stepping the repetition rate by |
297 // stepping the comb phase-lock offset frequency f_lock generated by | 297 // stepping the comb phase-lock offset frequency f_lock generated by |
298 // DDS1. A lock frequency step delta_f_lock determines a change in the | 298 // DDS1. A lock frequency step delta_f_lock determines a change in the |
299 // repetition rate given by: | 299 // repetition rate given by: |
300 // | 300 // |
301 // abs(delta_f_rep) = Ndiv * delta_f_lock / N1 | 301 // abs(delta_f_rep) = Ndiv * delta_f_lock / N1 |
302 // | 302 // |
303 // where Ndiv = 8 and N1 ~= 8 x 10^5 obtaining that | 303 // where Ndiv = 8 and N1 ~= 8 x 10^5 obtaining that |
304 // | 304 // |
305 // abs(delta_f_rep) ~= delta_f_lock / 10^5 | 305 // abs(delta_f_rep) ~= delta_f_lock / 10^5 |
306 // | 306 // |
307 // For the determination of the comb locking beatnote sign we detect | 307 // For the determination of the comb locking beatnote sign we detect |
308 // the sign of delta_f_rep caused by a positive delta_f_lock. f_rep is | 308 // the sign of delta_f_rep caused by a positive delta_f_lock. f_rep is |
309 // measured should be small enough to do not exceed the 200x PLL | 309 // measured should be small enough to do not exceed the 200x PLL |
310 // bandwidth but still be clearly identified. | 310 // bandwidth but still be clearly identified. |
311 // | 311 // |
312 // For the optical beatnotes we detect the sign of delta_f_beat caused | 312 // For the optical beatnotes we detect the sign of delta_f_beat caused |
313 // by a positive delta_f_lock thus we need to take into account the | 313 // by a positive delta_f_lock thus we need to take into account the |
314 // sign of the comb locking beatnote. The optical beatnote frequency | 314 // sign of the comb locking beatnote. The optical beatnote frequency |
315 // change is given by | 315 // change is given by |
316 // | 316 // |
317 // abs(delta_f_beat) = abs(delta_f_rep) * Nx | 317 // abs(delta_f_beat) = abs(delta_f_rep) * Nx |
318 // | 318 // |
319 // where Nx ~= 10^6 obtaining that | 319 // where Nx ~= 10^6 obtaining that |
320 // | 320 // |
321 // abs(delta_f_beat) ~= delta_f_lock * 10 | 321 // abs(delta_f_beat) ~= delta_f_lock * 10 |
322 // | 322 // |
323 // this need to do not exceed the beatnote filters bandwidth. Given | 323 // this need to do not exceed the beatnote filters bandwidth. Given |
324 // those contraints the following f_lock steps are chosen: | 324 // those contraints the following f_lock steps are chosen: |
325 | 325 |
388 | 388 |
389 | 389 |
390 void dedrift_update_enable() | 390 void dedrift_update_enable() |
391 { | 391 { |
392 logmsg("dedrift: automatic slope update enabled"); | 392 logmsg("dedrift: automatic slope update enabled"); |
393 | 393 |
394 dedrift.enabled = TRUE; | 394 dedrift.enabled = TRUE; |
395 dedrift.t0 = utc; | 395 dedrift.t0 = utc; |
396 stat_zero(&dedrift.stat); | 396 stat_zero(&dedrift.stat); |
397 dedrift.stat.previous = NaN; | 397 dedrift.stat.previous = NaN; |
398 } | 398 } |
440 } | 440 } |
441 } | 441 } |
442 | 442 |
443 | 443 |
444 void dedrift_update(double f) | 444 void dedrift_update(double f) |
445 { | 445 { |
446 if (! dedrift.enabled) | 446 if (! dedrift.enabled) |
447 return; | 447 return; |
448 | 448 |
449 // update measurement | 449 // update measurement |
450 stat_accumulate_resilient(&dedrift.stat, f, dedrift.threshold, &dedrift.badcount); | 450 stat_accumulate_resilient(&dedrift.stat, f, dedrift.threshold, &dedrift.badcount); |
451 if (dedrift.badcount) { | 451 if (dedrift.badcount) { |
452 // bad data point detected | 452 // bad data point detected |
453 logmsg("dedrift: bad data point detected"); | 453 logmsg("dedrift: bad data point detected"); |
454 | 454 |
455 // too many consecutive bad data points detected | 455 // too many consecutive bad data points detected |
456 if (dedrift.safety && (dedrift.badcount > dedrift.badcountmax)) { | 456 if (dedrift.safety && (dedrift.badcount > dedrift.badcountmax)) { |
457 logmsg("dedrift: maximum number of consecutive bad data points exceeded"); | 457 logmsg("dedrift: maximum number of consecutive bad data points exceeded"); |
458 dedrift_update_disable(); | 458 dedrift_update_disable(); |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 // check if the previous check disabled slope update | 462 // check if the previous check disabled slope update |
463 if (! dedrift.enabled) | 463 if (! dedrift.enabled) |
464 return; | 464 return; |
465 | 465 |
466 // update display | 466 // update display |
467 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, dedrift.stat.slope); | 467 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, dedrift.stat.slope); |
468 | 468 |
469 // update applied slope | 469 // update applied slope |
470 if ((utc - dedrift.t0) > dedrift.interval) { | 470 if ((utc - dedrift.t0) > dedrift.interval) { |
471 | 471 |
472 // target frequency | 472 // target frequency |
473 if (dedrift.f0 == 0.0) | 473 if (dedrift.f0 == 0.0) |
474 dedrift.f0 = dedrift.stat.mean; | 474 dedrift.f0 = dedrift.stat.mean; |
475 | 475 |
476 // compute correction | 476 // compute correction |
477 double dt = utc - dedrift.t0; | 477 double dt = utc - dedrift.t0; |
478 double corr = dedrift.stat.slope \ | 478 double corr = dedrift.stat.slope \ |
479 + dedrift.proportional * ((dedrift.stat.mean - dedrift.f0) / dt + 0.5 * dedrift.stat.slope); | 479 + dedrift.proportional * ((dedrift.stat.mean - dedrift.f0) / dt + 0.5 * dedrift.stat.slope); |
480 | 480 |
481 // update | 481 // update |
482 dedrift.applied += dedrift.sign * corr * (dedrift.x2 ? 2 : 1); | 482 dedrift.applied += dedrift.sign * corr * (dedrift.x2 ? 2 : 1); |
483 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied); | 483 ad9956_set_sweep_rate_w(&ad9956, dedrift.applied); |
484 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); | 484 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); |
485 logmsg("dedrift: update correction=%+3e slope=%+3e", corr, dedrift.applied); | 485 logmsg("dedrift: update correction=%+3e slope=%+3e", corr, dedrift.applied); |
486 | 486 |
487 // start over. keep track of the last updated data point to | 487 // start over. keep track of the last updated data point to |
488 // avoid gaps in the detectrion of bad data points based on | 488 // avoid gaps in the detectrion of bad data points based on |
489 // threshold on the difference between current data point and | 489 // threshold on the difference between current data point and |
490 // previous one | 490 // previous one |
491 double prev = dedrift.stat.previous; | 491 double prev = dedrift.stat.previous; |
516 | 516 |
517 int recenter_enabled() | 517 int recenter_enabled() |
518 { | 518 { |
519 if (! recenter.active) | 519 if (! recenter.active) |
520 return FALSE; | 520 return FALSE; |
521 | 521 |
522 for (int i = 0; i < NBEATNOTES; i++) | 522 for (int i = 0; i < NBEATNOTES; i++) |
523 if (recenter.enabled[i]) | 523 if (recenter.enabled[i]) |
524 return TRUE; | 524 return TRUE; |
525 | 525 |
526 return FALSE; | 526 return FALSE; |
529 | 529 |
530 void recenter_update() | 530 void recenter_update() |
531 { | 531 { |
532 if (! recenter_enabled()) | 532 if (! recenter_enabled()) |
533 return; | 533 return; |
534 | 534 |
535 rollmean_accumulate(&rollmean_ch2, Ch2); | 535 rollmean_accumulate(&rollmean_ch2, Ch2); |
536 rollmean_accumulate(&rollmean_ch3, Ch3); | 536 rollmean_accumulate(&rollmean_ch3, Ch3); |
537 rollmean_accumulate(&rollmean_ch4, Ch4); | 537 rollmean_accumulate(&rollmean_ch4, Ch4); |
538 | 538 |
539 if ((utc - recenter.t0) > recenter.interval) { | 539 if ((utc - recenter.t0) > recenter.interval) { |
540 | 540 |
541 if (recenter.enabled[LO]) { | 541 if (recenter.enabled[LO]) { |
542 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz | 542 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz |
543 double freq = ad9912.frequency[1]; | 543 double freq = ad9912.frequency[1]; |
544 double adj = 275000.0 - rollmean_ch4.mean; | 544 double adj = 275000.0 - rollmean_ch4.mean; |
545 if (fabs(adj) > recenter.threshold[LO]) { | 545 if (fabs(adj) > recenter.threshold[LO]) { |
549 ad9912_set_frequency_w(&ad9912, 1, freq); | 549 ad9912_set_frequency_w(&ad9912, 1, freq); |
550 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 550 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
551 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); | 551 logmsg("recenter ch4 to 275 kHz: DDS2 adjustment=%+3e", adj); |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 if (recenter.enabled[HG]) { | 555 if (recenter.enabled[HG]) { |
556 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz | 556 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz |
557 double freq = ad9912.frequency[2]; | 557 double freq = ad9912.frequency[2]; |
558 double adj = 10000 - rollmean_ch2.mean; | 558 double adj = 10000 - rollmean_ch2.mean; |
559 if (fabs(adj) > recenter.threshold[HG]) { | 559 if (fabs(adj) > recenter.threshold[HG]) { |
563 ad9912_set_frequency_w(&ad9912, 2, freq); | 563 ad9912_set_frequency_w(&ad9912, 2, freq); |
564 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 564 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
565 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); | 565 logmsg("recenter Hg beatnote (ch2) to 10 kHz: DDS3 adjustment=%+3e", adj); |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 if (recenter.enabled[SR]) { | 569 if (recenter.enabled[SR]) { |
570 // adjust DDS4 frequency to keep Ch3 reading at 10 kHz | 570 // adjust DDS4 frequency to keep Ch3 reading at 10 kHz |
571 double freq = ad9912.frequency[3]; | 571 double freq = ad9912.frequency[3]; |
572 double adj = 10000 - rollmean_ch3.mean; | 572 double adj = 10000 - rollmean_ch3.mean; |
573 if (fabs(adj) > recenter.threshold[SR]) { | 573 if (fabs(adj) > recenter.threshold[SR]) { |
577 ad9912_set_frequency_w(&ad9912, 3, freq); | 577 ad9912_set_frequency_w(&ad9912, 3, freq); |
578 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); | 578 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); |
579 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj); | 579 logmsg("recenter Sr beatnote (ch3) to 10 kHz: DDS4 adjustment=%+3e", adj); |
580 } | 580 } |
581 } | 581 } |
582 | 582 |
583 recenter.t0 = utc; | 583 recenter.t0 = utc; |
584 rollmean_zero(&rollmean_ch2); | 584 rollmean_zero(&rollmean_ch2); |
585 rollmean_zero(&rollmean_ch3); | 585 rollmean_zero(&rollmean_ch3); |
586 rollmean_zero(&rollmean_ch4); | 586 rollmean_zero(&rollmean_ch4); |
587 } | 587 } |
619 DATAFILE("Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE), | 619 DATAFILE("Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE), |
620 { NULL, } | 620 { NULL, } |
621 }; | 621 }; |
622 | 622 |
623 | 623 |
624 static void write_data(const char *folder, const char *name, const char *id, | 624 static void write_data(const char *folder, const char *name, const char *id, |
625 const char *timestr, double utc, double *v, int nchan) | 625 const char *timestr, double utc, double *v, int nchan) |
626 { | 626 { |
627 int i, fd, len; | 627 int i, fd, len; |
628 char line[1024]; | 628 char line[1024]; |
629 char filename[FILENAME_MAX]; | 629 char filename[FILENAME_MAX]; |
630 | 630 |
631 // construct filename in the form folder\\id-name.txt | 631 // construct filename in the form folder\\id-name.txt |
632 snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); | 632 snprintf(filename, sizeof(filename), "%s\\%s-%s.txt", folder, id, name); |
633 | 633 |
634 fd = open(filename, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP); | 634 fd = open(filename, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP); |
635 if (fd < 0) { | 635 if (fd < 0) { |
636 logmessage(ERROR, "open data file %s: %s", filename, strerror(errno)); | 636 logmessage(ERROR, "open data file %s: %s", filename, strerror(errno)); |
637 return; | 637 return; |
638 } | 638 } |
639 | 639 |
640 // timestamp | 640 // timestamp |
641 len = snprintf(line, sizeof(line), "%s\t%.3f", timestr, utc); | 641 len = snprintf(line, sizeof(line), "%s\t%.3f", timestr, utc); |
642 | 642 |
643 // data channels | 643 // data channels |
644 for (i = 0; i < nchan; i++) | 644 for (i = 0; i < nchan; i++) |
645 len += snprintf(line + len, sizeof(line) - len, "\t%.16e", v[i]); | 645 len += snprintf(line + len, sizeof(line) - len, "\t%.16e", v[i]); |
646 | 646 |
647 // newline | 647 // newline |
648 line[len++] = '\r'; | 648 line[len++] = '\r'; |
649 line[len++] = '\n'; | 649 line[len++] = '\n'; |
650 | 650 |
651 // write to file | 651 // write to file |
652 write(fd, line, len); | 652 write(fd, line, len); |
653 | 653 |
654 close(fd); | 654 close(fd); |
655 } | 655 } |
656 | 656 |
657 | 657 |
658 static inline void datafile_append(struct datafile *d, char *id, char *timestr) | 658 static inline void datafile_append(struct datafile *d, char *id, char *timestr) |
672 | 672 |
673 | 673 |
674 static void * muParserNew() | 674 static void * muParserNew() |
675 { | 675 { |
676 void *parser = mupCreate(); | 676 void *parser = mupCreate(); |
677 | 677 |
678 mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ" | 678 mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ" |
679 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | 679 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
680 "+-*^/?<>=#!$%&|~'_"); | 680 "+-*^/?<>=#!$%&|~'_"); |
681 | 681 |
682 mupDefineVar(parser, "Ch1", &Ch1); | 682 mupDefineVar(parser, "Ch1", &Ch1); |
683 mupDefineVar(parser, "Ch2", &Ch2); | 683 mupDefineVar(parser, "Ch2", &Ch2); |
684 mupDefineVar(parser, "Ch3", &Ch3); | 684 mupDefineVar(parser, "Ch3", &Ch3); |
685 mupDefineVar(parser, "Ch4", &Ch4); | 685 mupDefineVar(parser, "Ch4", &Ch4); |
686 mupDefineVar(parser, "DDS1", &(ad9912.frequency[0])); | 686 mupDefineVar(parser, "DDS1", &(ad9912.frequency[0])); |
692 mupDefineVar(parser, "N3", &N3); | 692 mupDefineVar(parser, "N3", &N3); |
693 mupDefineVar(parser, "Sign1", &Sign1); | 693 mupDefineVar(parser, "Sign1", &Sign1); |
694 mupDefineVar(parser, "Sign2", &Sign2); | 694 mupDefineVar(parser, "Sign2", &Sign2); |
695 mupDefineVar(parser, "Sign3", &Sign3); | 695 mupDefineVar(parser, "Sign3", &Sign3); |
696 mupDefineVar(parser, "Ndiv", &Ndiv); | 696 mupDefineVar(parser, "Ndiv", &Ndiv); |
697 | 697 |
698 mupDefinePostfixOprt(parser, "P", &Peta, 1); | 698 mupDefinePostfixOprt(parser, "P", &Peta, 1); |
699 mupDefinePostfixOprt(parser, "T", &Tera, 1); | 699 mupDefinePostfixOprt(parser, "T", &Tera, 1); |
700 mupDefinePostfixOprt(parser, "G", &Giga, 1); | 700 mupDefinePostfixOprt(parser, "G", &Giga, 1); |
701 mupDefinePostfixOprt(parser, "M", &Mega, 1); | 701 mupDefinePostfixOprt(parser, "M", &Mega, 1); |
702 mupDefinePostfixOprt(parser, "k", &kilo, 1); | 702 mupDefinePostfixOprt(parser, "k", &kilo, 1); |
704 mupDefinePostfixOprt(parser, "u", µ, 1); | 704 mupDefinePostfixOprt(parser, "u", µ, 1); |
705 mupDefinePostfixOprt(parser, "µ", µ, 1); | 705 mupDefinePostfixOprt(parser, "µ", µ, 1); |
706 mupDefinePostfixOprt(parser, "n", &nano, 1); | 706 mupDefinePostfixOprt(parser, "n", &nano, 1); |
707 mupDefinePostfixOprt(parser, "p", &pico, 1); | 707 mupDefinePostfixOprt(parser, "p", &pico, 1); |
708 mupDefinePostfixOprt(parser, "f", &femto, 1); | 708 mupDefinePostfixOprt(parser, "f", &femto, 1); |
709 | 709 |
710 return parser; | 710 return parser; |
711 } | 711 } |
712 | 712 |
713 | 713 |
714 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, | 714 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, |
730 if ((EstimateNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN)) < 0) | 730 if ((EstimateNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN)) < 0) |
731 return -1; | 731 return -1; |
732 | 732 |
733 // logging | 733 // logging |
734 logger_init(&onerror); | 734 logger_init(&onerror); |
735 | 735 |
736 // load configuration file | 736 // load configuration file |
737 char path[MAX_PATHNAME_LEN]; | 737 char path[MAX_PATHNAME_LEN]; |
738 GetIniFilePath(path); | 738 GetIniFilePath(path); |
739 IniText configuration = Ini_New(TRUE); | 739 IniText configuration = Ini_New(TRUE); |
740 Ini_ReadFromFile(configuration, path); | 740 Ini_ReadFromFile(configuration, path); |
743 rv = Ini_GetInt(configuration, "KK", "nchan", &nchan); | 743 rv = Ini_GetInt(configuration, "KK", "nchan", &nchan); |
744 if (rv < 1) | 744 if (rv < 1) |
745 nchan = 4; | 745 nchan = 4; |
746 // update number of channels to save to disk | 746 // update number of channels to save to disk |
747 datafiles[0].nchan = nchan; | 747 datafiles[0].nchan = nchan; |
748 | 748 |
749 // data folder | 749 // data folder |
750 rv = Ini_GetStringCopy(configuration, "data", "folder", &datafolder); | 750 rv = Ini_GetStringCopy(configuration, "data", "folder", &datafolder); |
751 if (rv > 0) { | 751 if (rv > 0) { |
752 logmessage(INFO, "writing data files in '%s'", datafolder); | 752 logmessage(INFO, "writing data files in '%s'", datafolder); |
753 } else { | 753 } else { |
754 logmessage(ERROR, "data folder not configured in %s", path); | 754 logmessage(ERROR, "data folder not configured in %s", path); |
755 // do not allow to start the acquisition | 755 // do not allow to start the acquisition |
756 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); | 756 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); |
757 } | 757 } |
758 | 758 |
759 // ad9956 configuration parameters | 759 // ad9956 configuration parameters |
760 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host)); | 760 rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host)); |
761 if (! rv) | 761 if (! rv) |
762 return -1; | 762 return -1; |
763 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock); | 763 rv = Ini_GetDouble(configuration, "AD9956", "clock", &clock); |
764 if (! rv) | 764 if (! rv) |
765 return -1; | 765 return -1; |
766 | 766 |
767 // initialize AD9956 dedrift DDS | 767 // initialize AD9956 dedrift DDS |
768 rv = ad9956_init(&ad9956, host, clock); | 768 rv = ad9956_init(&ad9956, host, clock); |
769 if (rv) | 769 if (rv) |
770 logmessage(ERROR, "ad9956 init erorr=%d", -rv); | 770 logmessage(ERROR, "ad9956 init erorr=%d", -rv); |
771 ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied); | 771 ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied); |
772 | 772 |
773 // AD9912 configuration parameters | 773 // AD9912 configuration parameters |
774 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host)); | 774 rv = Ini_GetStringIntoBuffer(configuration, "AD9912", "host", host, sizeof(host)); |
775 if (! rv) | 775 if (! rv) |
776 return -1; | 776 return -1; |
777 rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock); | 777 rv = Ini_GetDouble(configuration, "AD9912", "clock", &clock); |
778 if (! rv) | 778 if (! rv) |
779 return -1; | 779 return -1; |
780 | 780 |
781 // initialize AD9912 DDS box | 781 // initialize AD9912 DDS box |
782 rv = ad9912_init(&ad9912, host, clock); | 782 rv = ad9912_init(&ad9912, host, clock); |
783 if (rv) | 783 if (rv) |
784 logmessage(ERROR, "ad9912 init erorr=%d", -rv); | 784 logmessage(ERROR, "ad9912 init erorr=%d", -rv); |
785 | 785 |
786 // try to read back current frequency from DDS | 786 // try to read back current frequency from DDS |
787 for (i = 0; i < 4; i++) { | 787 for (i = 0; i < 4; i++) { |
788 rv = ad9912_get_frequency(&ad9912, i, &frequency); | 788 rv = ad9912_get_frequency(&ad9912, i, &frequency); |
789 if ((rv) || (frequency == 0.0)) { | 789 if ((rv) || (frequency == 0.0)) { |
790 logmessage(WARNING, "reset DDS%d frequency to default value", i + 1); | 790 logmessage(WARNING, "reset DDS%d frequency to default value", i + 1); |
804 zmqsocket = zmq_socket(zmqcontext, ZMQ_PUB); | 804 zmqsocket = zmq_socket(zmqcontext, ZMQ_PUB); |
805 rv = zmq_bind(zmqsocket, socket); | 805 rv = zmq_bind(zmqsocket, socket); |
806 if (rv) | 806 if (rv) |
807 logmessage(ERROR, "cannot bind ZMQ socket '%s': %s", socket, zmq_strerror(zmq_errno())); | 807 logmessage(ERROR, "cannot bind ZMQ socket '%s': %s", socket, zmq_strerror(zmq_errno())); |
808 free(socket); | 808 free(socket); |
809 | 809 |
810 // dispose configuration | 810 // dispose configuration |
811 Ini_Dispose(configuration); | 811 Ini_Dispose(configuration); |
812 | 812 |
813 // Sr data logger | 813 // Sr data logger |
814 sr_datalogger_init(&datalogger); | 814 sr_datalogger_init(&datalogger); |
815 | 815 |
816 GetCtrlVal(MainPanel, PANEL_N1, &N1); | 816 GetCtrlVal(MainPanel, PANEL_N1, &N1); |
817 GetCtrlVal(MainPanel, PANEL_N2, &N2); | 817 GetCtrlVal(MainPanel, PANEL_N2, &N2); |
818 GetCtrlVal(MainPanel, PANEL_N3, &N3); | 818 GetCtrlVal(MainPanel, PANEL_N3, &N3); |
819 | 819 |
820 MathParser1 = muParserNew(); | 820 MathParser1 = muParserNew(); |
821 GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr); | 821 GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr); |
822 mupSetExpr(MathParser1, expr); | 822 mupSetExpr(MathParser1, expr); |
823 | 823 |
824 MathParser2 = muParserNew(); | 824 MathParser2 = muParserNew(); |
825 mupDefineVar(MathParser2, "Math1", &Math1); | 825 mupDefineVar(MathParser2, "Math1", &Math1); |
826 GetCtrlVal(MainPanel, PANEL_MATHSTRING2, expr); | 826 GetCtrlVal(MainPanel, PANEL_MATHSTRING2, expr); |
827 mupSetExpr(MathParser2, expr); | 827 mupSetExpr(MathParser2, expr); |
828 | 828 |
829 MathParser3 = muParserNew(); | 829 MathParser3 = muParserNew(); |
830 mupDefineVar(MathParser3, "Math1", &Math1); | 830 mupDefineVar(MathParser3, "Math1", &Math1); |
831 mupDefineVar(MathParser3, "Math2", &Math2); | 831 mupDefineVar(MathParser3, "Math2", &Math2); |
832 GetCtrlVal(MainPanel, PANEL_MATHSTRING3, expr); | 832 GetCtrlVal(MainPanel, PANEL_MATHSTRING3, expr); |
833 mupSetExpr(MathParser3, expr); | 833 mupSetExpr(MathParser3, expr); |
834 | 834 |
835 MathParser4 = muParserNew(); | 835 MathParser4 = muParserNew(); |
836 mupDefineVar(MathParser4, "Math1", &Math1); | 836 mupDefineVar(MathParser4, "Math1", &Math1); |
837 mupDefineVar(MathParser4, "Math2", &Math2); | 837 mupDefineVar(MathParser4, "Math2", &Math2); |
838 mupDefineVar(MathParser4, "Math3", &Math3); | 838 mupDefineVar(MathParser4, "Math3", &Math3); |
839 GetCtrlVal(MainPanel, PANEL_MATHSTRING4, expr); | 839 GetCtrlVal(MainPanel, PANEL_MATHSTRING4, expr); |
840 mupSetExpr(MathParser4, expr); | 840 mupSetExpr(MathParser4, expr); |
841 | 841 |
842 MathParser5 = muParserNew(); | 842 MathParser5 = muParserNew(); |
843 mupDefineVar(MathParser5, "Math1", &Math1); | 843 mupDefineVar(MathParser5, "Math1", &Math1); |
844 mupDefineVar(MathParser5, "Math2", &Math2); | 844 mupDefineVar(MathParser5, "Math2", &Math2); |
845 mupDefineVar(MathParser5, "Math3", &Math3); | 845 mupDefineVar(MathParser5, "Math3", &Math3); |
846 mupDefineVar(MathParser5, "Math4", &Math4); | 846 mupDefineVar(MathParser5, "Math4", &Math4); |
847 GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr); | 847 GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr); |
848 mupSetExpr(MathParser5, expr); | 848 mupSetExpr(MathParser5, expr); |
849 | 849 |
850 // data queue | 850 // data queue |
851 CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue); | 851 CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue); |
852 | 852 |
853 // register callback to execute when data will be in the data queue | 853 // register callback to execute when data will be in the data queue |
854 CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, 1, | 854 CmtInstallTSQCallback(dataQueue, EVENT_TSQ_ITEMS_IN_QUEUE, 1, |
855 DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL); | 855 DataAvailableCB, NULL, CmtGetCurrentThreadID(), NULL); |
856 | 856 |
857 DisplayPanel(MainPanel); | 857 DisplayPanel(MainPanel); |
858 | 858 |
859 RunUserInterface(); | 859 RunUserInterface(); |
860 | 860 |
861 DiscardPanel(MainPanel); | 861 DiscardPanel(MainPanel); |
862 return 0; | 862 return 0; |
863 } | 863 } |
864 | 864 |
865 int CVICALLBACK QuitCallback (int panel, int control, int event, | 865 int CVICALLBACK QuitCallback (int panel, int control, int event, |
877 int CVICALLBACK CB_OnEventMain(int panel, int event, | 877 int CVICALLBACK CB_OnEventMain(int panel, int event, |
878 void *callbackData, int eventData1, int eventData2) | 878 void *callbackData, int eventData1, int eventData2) |
879 { | 879 { |
880 int control, index; | 880 int control, index; |
881 double step; | 881 double step; |
882 | 882 |
883 #define do_arrow(__DDS, __STEP) \ | 883 #define do_arrow(__DDS, __STEP) \ |
884 do { \ | 884 do { \ |
885 GetCtrlIndex(panel, __STEP, &index); \ | 885 GetCtrlIndex(panel, __STEP, &index); \ |
886 if ((eventData1 == VAL_RIGHT_ARROW_VKEY) && (index < 14)) \ | 886 if ((eventData1 == VAL_RIGHT_ARROW_VKEY) && (index < 14)) \ |
887 SetCtrlIndex(panel, __STEP, index + 1); \ | 887 SetCtrlIndex(panel, __STEP, index + 1); \ |
888 if ((eventData1 == VAL_LEFT_ARROW_VKEY) && (index > 0)) \ | 888 if ((eventData1 == VAL_LEFT_ARROW_VKEY) && (index > 0)) \ |
889 SetCtrlIndex(panel, __STEP, index - 1); \ | 889 SetCtrlIndex(panel, __STEP, index - 1); \ |
890 GetCtrlVal(panel, __STEP, &step); \ | 890 GetCtrlVal(panel, __STEP, &step); \ |
891 SetCtrlAttribute(panel, __DDS, ATTR_INCR_VALUE, step); \ | 891 SetCtrlAttribute(panel, __DDS, ATTR_INCR_VALUE, step); \ |
892 } while (0) | 892 } while (0) |
893 | 893 |
894 switch (event) { | 894 switch (event) { |
895 case EVENT_KEYPRESS: | 895 case EVENT_KEYPRESS: |
896 /* key code */ | 896 /* key code */ |
897 switch (eventData1) { | 897 switch (eventData1) { |
898 case VAL_RIGHT_ARROW_VKEY: | 898 case VAL_RIGHT_ARROW_VKEY: |
899 case VAL_LEFT_ARROW_VKEY: | 899 case VAL_LEFT_ARROW_VKEY: |
900 control = GetActiveCtrl(panel); | 900 control = GetActiveCtrl(panel); |
901 switch (control) { | 901 switch (control) { |
902 case PANEL_DDS1: | 902 case PANEL_DDS1: |
903 case PANEL_DDS1STEP: | 903 case PANEL_DDS1STEP: |
904 do_arrow(PANEL_DDS1, PANEL_DDS1STEP); | 904 do_arrow(PANEL_DDS1, PANEL_DDS1STEP); |
945 break; | 945 break; |
946 | 946 |
947 logmsg("start"); | 947 logmsg("start"); |
948 SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); | 948 SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE); |
949 acquiring = 1; | 949 acquiring = 1; |
950 | 950 |
951 // start data provider thread | 951 // start data provider thread |
952 CmtScheduleThreadPoolFunctionAdv( | 952 CmtScheduleThreadPoolFunctionAdv( |
953 DEFAULT_THREAD_POOL_HANDLE, DataProvider, NULL, | 953 DEFAULT_THREAD_POOL_HANDLE, DataProvider, NULL, |
954 THREAD_PRIORITY_HIGHEST, NULL, 0, NULL, 0, &dataProviderThread); | 954 THREAD_PRIORITY_HIGHEST, NULL, 0, NULL, 0, &dataProviderThread); |
955 | 955 |
963 { | 963 { |
964 switch (event) { | 964 switch (event) { |
965 case EVENT_COMMIT: | 965 case EVENT_COMMIT: |
966 if (! acquiring) | 966 if (! acquiring) |
967 break; | 967 break; |
968 | 968 |
969 logmsg("stop"); | 969 logmsg("stop"); |
970 acquiring = 0; | 970 acquiring = 0; |
971 | 971 |
972 // wait for data provider thread to terminate | 972 // wait for data provider thread to terminate |
973 CmtWaitForThreadPoolFunctionCompletion( | 973 CmtWaitForThreadPoolFunctionCompletion( |
975 OPT_TP_PROCESS_EVENTS_WHILE_WAITING); | 975 OPT_TP_PROCESS_EVENTS_WHILE_WAITING); |
976 CmtReleaseThreadPoolFunctionID( | 976 CmtReleaseThreadPoolFunctionID( |
977 DEFAULT_THREAD_POOL_HANDLE, dataProviderThread); | 977 DEFAULT_THREAD_POOL_HANDLE, dataProviderThread); |
978 | 978 |
979 SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, FALSE); | 979 SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, FALSE); |
980 | 980 |
981 break; | 981 break; |
982 } | 982 } |
983 return 0; | 983 return 0; |
984 } | 984 } |
985 | 985 |
986 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, | 986 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event, |
987 int value, void *callbackData) | 987 int value, void *callbackData) |
988 { | 988 { |
989 int read; | 989 int read; |
990 | 990 |
991 switch (event) { | 991 switch (event) { |
992 case EVENT_TSQ_ITEMS_IN_QUEUE: | 992 case EVENT_TSQ_ITEMS_IN_QUEUE: |
993 // read data from the data queue | 993 // read data from the data queue |
994 while (value > 0) { | 994 while (value > 0) { |
995 | 995 |
996 read = CmtReadTSQData(queueHandle, &ev, 1, TSQ_INFINITE_TIMEOUT, 0); | 996 read = CmtReadTSQData(queueHandle, &ev, 1, TSQ_INFINITE_TIMEOUT, 0); |
997 if (read != 1) | 997 if (read != 1) |
998 logmsg("Error!"); | 998 logmsg("Error!"); |
999 value = value - read; | 999 value = value - read; |
1000 | 1000 |
1001 // unpack event | 1001 // unpack event |
1002 utc = ev.time.tv_sec + ev.time.tv_usec * 1e-6; | 1002 utc = ev.time.tv_sec + ev.time.tv_usec * 1e-6; |
1003 | 1003 |
1004 // update display | 1004 // update display |
1005 SetCtrlVal(MainPanel, PANEL_UTC, utc); | 1005 SetCtrlVal(MainPanel, PANEL_UTC, utc); |
1006 SetCtrlVal(MainPanel, PANEL_CH1, Ch1); | 1006 SetCtrlVal(MainPanel, PANEL_CH1, Ch1); |
1007 SetCtrlVal(MainPanel, PANEL_CH2, Ch2); | 1007 SetCtrlVal(MainPanel, PANEL_CH2, Ch2); |
1008 SetCtrlVal(MainPanel, PANEL_CH3, Ch3); | 1008 SetCtrlVal(MainPanel, PANEL_CH3, Ch3); |
1009 SetCtrlVal(MainPanel, PANEL_CH4, Ch4); | 1009 SetCtrlVal(MainPanel, PANEL_CH4, Ch4); |
1010 | 1010 |
1011 // compute | 1011 // compute |
1012 Math1 = mupEval(MathParser1); | 1012 Math1 = mupEval(MathParser1); |
1013 Math2 = mupEval(MathParser2); | 1013 Math2 = mupEval(MathParser2); |
1014 Math3 = mupEval(MathParser3); | 1014 Math3 = mupEval(MathParser3); |
1015 Math4 = mupEval(MathParser4); | 1015 Math4 = mupEval(MathParser4); |
1016 Math5 = mupEval(MathParser5); | 1016 Math5 = mupEval(MathParser5); |
1017 | 1017 |
1018 // update display. numeric controllers do not format values | 1018 // update display. numeric controllers do not format values |
1019 // with a thousands separator: use string controllers and a | 1019 // with a thousands separator: use string controllers and a |
1020 // custom formatting function | 1020 // custom formatting function |
1021 char buffer[256]; | 1021 char buffer[256]; |
1022 SetCtrlVal(MainPanel, PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.6f", Math1)); | 1022 SetCtrlVal(MainPanel, PANEL_MATH1, thousands(buffer, sizeof(buffer), "%.6f", Math1)); |
1023 SetCtrlVal(MainPanel, PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2)); | 1023 SetCtrlVal(MainPanel, PANEL_MATH2, thousands(buffer, sizeof(buffer), "%.3f", Math2)); |
1024 SetCtrlVal(MainPanel, PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3)); | 1024 SetCtrlVal(MainPanel, PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3)); |
1030 plot_update(plot); | 1030 plot_update(plot); |
1031 | 1031 |
1032 // update allan deviation plots | 1032 // update allan deviation plots |
1033 for (struct adev *adev = adevs; adev->data; adev++) | 1033 for (struct adev *adev = adevs; adev->data; adev++) |
1034 adev_update(adev); | 1034 adev_update(adev); |
1035 | 1035 |
1036 // N measurement | 1036 // N measurement |
1037 | 1037 |
1038 switch (n_measurement[LO]) { | 1038 switch (n_measurement[LO]) { |
1039 | 1039 |
1040 case N_MEASUREMENT_NONE: | 1040 case N_MEASUREMENT_NONE: |
1041 // not measuring | 1041 // not measuring |
1042 break; | 1042 break; |
1043 | 1043 |
1044 case N_MEASUREMENT_INIT: | 1044 case N_MEASUREMENT_INIT: |
1045 // initialization step | 1045 // initialization step |
1046 | 1046 |
1047 // set DDS1 to nominal frequency | 1047 // set DDS1 to nominal frequency |
1048 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); | 1048 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); |
1049 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1049 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1050 | 1050 |
1051 // record current DDS frequencies | 1051 // record current DDS frequencies |
1052 f0_DDS[1] = ad9912.frequency[1]; | 1052 f0_DDS[1] = ad9912.frequency[1]; |
1053 | 1053 |
1054 t1 = utc; | 1054 t1 = utc; |
1055 t2 = t3 = 0.0; | 1055 t2 = t3 = 0.0; |
1056 nobs = 0; | 1056 nobs = 0; |
1057 stat_zero(&stat_math1); | 1057 stat_zero(&stat_math1); |
1058 f_rep_plus = f_rep_minus = 0.0; | 1058 f_rep_plus = f_rep_minus = 0.0; |
1059 | 1059 |
1060 // next step | 1060 // next step |
1061 n_measurement[LO] += 1; | 1061 n_measurement[LO] += 1; |
1062 break; | 1062 break; |
1063 | 1063 |
1064 case N_MEASUREMENT_SLOPE: | 1064 case N_MEASUREMENT_SLOPE: |
1065 // slope measurement | 1065 // slope measurement |
1066 | 1066 |
1067 stat_accumulate(&stat_math1, Math1); | 1067 stat_accumulate(&stat_math1, Math1); |
1068 | 1068 |
1069 if ((utc - t1) > slope_time[LO]) { | 1069 if ((utc - t1) > slope_time[LO]) { |
1070 f_rep_slope = stat_math1.slope; | 1070 f_rep_slope = stat_math1.slope; |
1071 | 1071 |
1072 // frep positive step | 1072 // frep positive step |
1073 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[LO], FREP_STEP_SIZE); | 1073 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[LO], FREP_STEP_SIZE); |
1074 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1074 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1075 | 1075 |
1076 // allow counter to settle | 1076 // allow counter to settle |
1077 settling = 3; | 1077 settling = 3; |
1078 | 1078 |
1079 // next step | 1079 // next step |
1080 n_measurement[LO] += 1; | 1080 n_measurement[LO] += 1; |
1081 } | 1081 } |
1082 break; | 1082 break; |
1083 | 1083 |
1084 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | 1084 case N_MEASUREMENT_ADJUST_FREQ_PLUS: |
1085 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 1085 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
1086 // adjust DDS frequency to keep beatnote within the bandpass filter | 1086 // adjust DDS frequency to keep beatnote within the bandpass filter |
1087 | 1087 |
1088 if (settling-- > 0) | 1088 if (settling-- > 0) |
1089 break; | 1089 break; |
1090 | 1090 |
1091 double fDDS2 = ad9912.frequency[1]; | 1091 double fDDS2 = ad9912.frequency[1]; |
1092 ad9912_set_frequency_w(&ad9912, 1, fDDS2 + 275000 - Ch4); | 1092 ad9912_set_frequency_w(&ad9912, 1, fDDS2 + 275000 - Ch4); |
1093 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1093 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1094 | 1094 |
1095 // allow counter to settle | 1095 // allow counter to settle |
1096 settling = 3; | 1096 settling = 3; |
1097 | 1097 |
1098 // next step | 1098 // next step |
1099 n_measurement[LO] += 1; | 1099 n_measurement[LO] += 1; |
1100 break; | 1100 break; |
1101 | 1101 |
1102 case N_MEASUREMENT_FREP_PLUS: | 1102 case N_MEASUREMENT_FREP_PLUS: |
1103 // frep positive step | 1103 // frep positive step |
1104 | 1104 |
1105 if (settling-- > 0) | 1105 if (settling-- > 0) |
1106 break; | 1106 break; |
1107 | 1107 |
1108 if (t2 == 0.0) | 1108 if (t2 == 0.0) |
1109 t2 = utc; | 1109 t2 = utc; |
1110 | 1110 |
1111 f_rep_plus += Math1 - f_rep_slope * (utc - t2); | 1111 f_rep_plus += Math1 - f_rep_slope * (utc - t2); |
1112 nobs += 1; | 1112 nobs += 1; |
1113 | 1113 |
1114 if ((utc - t2) > integration_time[LO]) { | 1114 if ((utc - t2) > integration_time[LO]) { |
1115 f_rep_plus = f_rep_plus / nobs; | 1115 f_rep_plus = f_rep_plus / nobs; |
1116 nobs = 0; | 1116 nobs = 0; |
1117 | 1117 |
1118 // frep negative step | 1118 // frep negative step |
1119 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[LO], FREP_STEP_SIZE); | 1119 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[LO], FREP_STEP_SIZE); |
1120 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1120 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1121 | 1121 |
1122 // allow counter to settle | 1122 // allow counter to settle |
1123 settling = 3; | 1123 settling = 3; |
1124 | 1124 |
1125 // next step | 1125 // next step |
1126 n_measurement[LO] += 1; | 1126 n_measurement[LO] += 1; |
1127 } | 1127 } |
1128 break; | 1128 break; |
1129 | 1129 |
1130 case N_MEASUREMENT_FREP_MINUS: | 1130 case N_MEASUREMENT_FREP_MINUS: |
1131 // frep negative step | 1131 // frep negative step |
1132 | 1132 |
1133 if (settling-- > 0) | 1133 if (settling-- > 0) |
1134 break; | 1134 break; |
1135 | 1135 |
1136 if (t3 == 0.0) | 1136 if (t3 == 0.0) |
1137 t3 = utc; | 1137 t3 = utc; |
1138 | 1138 |
1139 f_rep_minus += Math1 - f_rep_slope * (utc - t2); | 1139 f_rep_minus += Math1 - f_rep_slope * (utc - t2); |
1140 nobs += 1; | 1140 nobs += 1; |
1141 | 1141 |
1142 if ((utc - t3) > integration_time[LO]) { | 1142 if ((utc - t3) > integration_time[LO]) { |
1143 f_rep_minus = f_rep_minus / nobs; | 1143 f_rep_minus = f_rep_minus / nobs; |
1144 nobs = 0; | 1144 nobs = 0; |
1145 | 1145 |
1146 // compute N1 | 1146 // compute N1 |
1147 double delta_f_rep = f_rep_minus - f_rep_plus; | 1147 double delta_f_rep = f_rep_minus - f_rep_plus; |
1148 double measured = Sign1 * 2 * Ndiv * delta_f_lock[LO] / delta_f_rep; | 1148 double measured = Sign1 * 2 * Ndiv * delta_f_lock[LO] / delta_f_rep; |
1149 SetCtrlVal(CalcNPanel, CALCN_N, measured); | 1149 SetCtrlVal(CalcNPanel, CALCN_N, measured); |
1150 | 1150 |
1151 // back to nominal frep | 1151 // back to nominal frep |
1152 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); | 1152 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); |
1153 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); | 1153 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); |
1154 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1154 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1155 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1155 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1156 | 1156 |
1157 // done | 1157 // done |
1158 n_measurement[LO] = N_MEASUREMENT_NONE; | 1158 n_measurement[LO] = N_MEASUREMENT_NONE; |
1159 } | 1159 } |
1160 break; | 1160 break; |
1161 } | 1161 } |
1163 switch (n_measurement[HG]) { | 1163 switch (n_measurement[HG]) { |
1164 | 1164 |
1165 case N_MEASUREMENT_NONE: | 1165 case N_MEASUREMENT_NONE: |
1166 // not measuring | 1166 // not measuring |
1167 break; | 1167 break; |
1168 | 1168 |
1169 case N_MEASUREMENT_INIT: | 1169 case N_MEASUREMENT_INIT: |
1170 // initialization step | 1170 // initialization step |
1171 | 1171 |
1172 // set DDS1 to nominal frequency | 1172 // set DDS1 to nominal frequency |
1173 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); | 1173 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); |
1174 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1174 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1175 | 1175 |
1176 // record current DDS frequencies | 1176 // record current DDS frequencies |
1177 f0_DDS[1] = ad9912.frequency[1]; | 1177 f0_DDS[1] = ad9912.frequency[1]; |
1178 f0_DDS[2] = ad9912.frequency[2]; | 1178 f0_DDS[2] = ad9912.frequency[2]; |
1179 | 1179 |
1180 t1 = utc; | 1180 t1 = utc; |
1181 t2 = t3 = 0.0; | 1181 t2 = t3 = 0.0; |
1182 nobs = 0; | 1182 nobs = 0; |
1183 stat_zero(&stat_math1); | 1183 stat_zero(&stat_math1); |
1184 stat_zero(&stat_ch2); | 1184 stat_zero(&stat_ch2); |
1185 f_rep_plus = f_rep_minus = 0.0; | 1185 f_rep_plus = f_rep_minus = 0.0; |
1186 f_beat_plus = f_beat_minus = 0.0; | 1186 f_beat_plus = f_beat_minus = 0.0; |
1187 | 1187 |
1188 // next step | 1188 // next step |
1189 n_measurement[HG] += 1; | 1189 n_measurement[HG] += 1; |
1190 break; | 1190 break; |
1191 | 1191 |
1192 case N_MEASUREMENT_SLOPE: | 1192 case N_MEASUREMENT_SLOPE: |
1193 // slope measurement | 1193 // slope measurement |
1194 | 1194 |
1195 stat_accumulate(&stat_math1, Math1); | 1195 stat_accumulate(&stat_math1, Math1); |
1196 stat_accumulate(&stat_ch2, Ch2); | 1196 stat_accumulate(&stat_ch2, Ch2); |
1197 | 1197 |
1198 if ((utc - t1) > slope_time[HG]) { | 1198 if ((utc - t1) > slope_time[HG]) { |
1199 f_rep_slope = stat_math1.slope; | 1199 f_rep_slope = stat_math1.slope; |
1200 f_beat_slope = stat_ch2.slope; | 1200 f_beat_slope = stat_ch2.slope; |
1201 | 1201 |
1202 // frep positive step | 1202 // frep positive step |
1203 double fDDS1 = f0_DDS[0] + delta_f_lock[HG]; | 1203 double fDDS1 = f0_DDS[0] + delta_f_lock[HG]; |
1204 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); | 1204 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); |
1205 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1205 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1206 | 1206 |
1207 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 1207 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
1208 double fDDS3 = f0_DDS[2] + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; | 1208 double fDDS3 = f0_DDS[2] + Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; |
1209 df_DDS3 = fDDS3 - ad9912.frequency[2]; | 1209 df_DDS3 = fDDS3 - ad9912.frequency[2]; |
1210 ad9912_set_frequency_w(&ad9912, 2, fDDS3); | 1210 ad9912_set_frequency_w(&ad9912, 2, fDDS3); |
1211 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 1211 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
1212 | 1212 |
1213 // allow counter to settle | 1213 // allow counter to settle |
1214 settling = 3; | 1214 settling = 3; |
1215 | 1215 |
1216 // next step | 1216 // next step |
1217 n_measurement[HG] += 1; | 1217 n_measurement[HG] += 1; |
1218 } | 1218 } |
1219 break; | 1219 break; |
1220 | 1220 |
1221 case N_MEASUREMENT_ADJUST_FREQ_PLUS: | 1221 case N_MEASUREMENT_ADJUST_FREQ_PLUS: |
1222 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 1222 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
1223 // adjust DDS frequency to keep beatnote within the bandpass filter | 1223 // adjust DDS frequency to keep beatnote within the bandpass filter |
1224 | 1224 |
1225 if (settling-- > 0) | 1225 if (settling-- > 0) |
1226 break; | 1226 break; |
1227 | 1227 |
1228 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; | 1228 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; |
1229 ad9912_set_frequency_w(&ad9912, 1, fDDS2); | 1229 ad9912_set_frequency_w(&ad9912, 1, fDDS2); |
1230 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1230 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1231 | 1231 |
1232 double fDDS3 = ad9912.frequency[2] + 10000 - Ch2; | 1232 double fDDS3 = ad9912.frequency[2] + 10000 - Ch2; |
1233 df_DDS3 = df_DDS3 + 10000 - Ch2; | 1233 df_DDS3 = df_DDS3 + 10000 - Ch2; |
1234 ad9912_set_frequency_w(&ad9912, 2, fDDS3); | 1234 ad9912_set_frequency_w(&ad9912, 2, fDDS3); |
1235 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 1235 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
1236 | 1236 |
1238 settling = 3; | 1238 settling = 3; |
1239 | 1239 |
1240 // next step | 1240 // next step |
1241 n_measurement[HG] += 1; | 1241 n_measurement[HG] += 1; |
1242 break; | 1242 break; |
1243 | 1243 |
1244 case N_MEASUREMENT_FREP_PLUS: | 1244 case N_MEASUREMENT_FREP_PLUS: |
1245 // frep positive step | 1245 // frep positive step |
1246 | 1246 |
1247 if (settling-- > 0) | 1247 if (settling-- > 0) |
1248 break; | 1248 break; |
1249 | 1249 |
1250 if (t2 == 0.0) | 1250 if (t2 == 0.0) |
1251 t2 = utc; | 1251 t2 = utc; |
1252 | 1252 |
1253 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); | 1253 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); |
1254 f_beat_plus += Ch2 - f_beat_slope * (utc - t2); | 1254 f_beat_plus += Ch2 - f_beat_slope * (utc - t2); |
1255 nobs += 1; | 1255 nobs += 1; |
1256 | 1256 |
1257 if ((utc - t2) > integration_time[HG]) { | 1257 if ((utc - t2) > integration_time[HG]) { |
1258 f_rep_plus = f_rep_plus / nobs; | 1258 f_rep_plus = f_rep_plus / nobs; |
1259 f_beat_plus = f_beat_plus / nobs; | 1259 f_beat_plus = f_beat_plus / nobs; |
1260 nobs = 0; | 1260 nobs = 0; |
1261 | 1261 |
1262 // negative frequency step | 1262 // negative frequency step |
1263 double fDDS1 = f0_DDS[0] - delta_f_lock[HG]; | 1263 double fDDS1 = f0_DDS[0] - delta_f_lock[HG]; |
1264 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); | 1264 ad9912_ramp_frequency_w(&ad9912, 0, fDDS1, FREP_STEP_SIZE); |
1265 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1265 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1266 | 1266 |
1267 // adjust DDS3 to keep beatnote within the bandpass filter. prediction | 1267 // adjust DDS3 to keep beatnote within the bandpass filter. prediction |
1268 double fDDS3 = f0_DDS[2] - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; | 1268 double fDDS3 = f0_DDS[2] - Sign1 * Sign2 * N2/N1 * Ndiv * delta_f_lock[HG]; |
1269 df_DDS3 = fDDS3 - ad9912.frequency[2]; | 1269 df_DDS3 = fDDS3 - ad9912.frequency[2]; |
1270 ad9912_set_frequency_w(&ad9912, 2, fDDS3); | 1270 ad9912_set_frequency_w(&ad9912, 2, fDDS3); |
1271 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 1271 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
1272 | 1272 |
1273 // allow counter to settle | 1273 // allow counter to settle |
1274 settling = 3; | 1274 settling = 3; |
1275 | 1275 |
1276 // next step | 1276 // next step |
1277 n_measurement[HG] += 1; | 1277 n_measurement[HG] += 1; |
1278 } | 1278 } |
1279 break; | 1279 break; |
1280 | 1280 |
1281 case N_MEASUREMENT_FREP_MINUS: | 1281 case N_MEASUREMENT_FREP_MINUS: |
1282 // frep negative step | 1282 // frep negative step |
1283 | 1283 |
1284 if (settling-- > 0) | 1284 if (settling-- > 0) |
1285 break; | 1285 break; |
1286 | 1286 |
1287 if (t3 == 0.0) | 1287 if (t3 == 0.0) |
1288 t3 = utc; | 1288 t3 = utc; |
1289 | 1289 |
1290 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); | 1290 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); |
1291 f_beat_minus += Ch2 + f_beat_slope * (utc - t2); | 1291 f_beat_minus += Ch2 + f_beat_slope * (utc - t2); |
1298 | 1298 |
1299 // compute N2 | 1299 // compute N2 |
1300 double delta_f_rep_m = f_rep_minus - f_rep_plus; | 1300 double delta_f_rep_m = f_rep_minus - f_rep_plus; |
1301 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[HG] / N1; | 1301 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[HG] / N1; |
1302 double delta = delta_f_rep_m - delta_f_rep; | 1302 double delta = delta_f_rep_m - delta_f_rep; |
1303 | 1303 |
1304 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", | 1304 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", |
1305 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); | 1305 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); |
1306 | 1306 |
1307 double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; | 1307 double measured = -Sign2 * (df_DDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; |
1308 SetCtrlVal(CalcNPanel, CALCN_N, measured); | 1308 SetCtrlVal(CalcNPanel, CALCN_N, measured); |
1309 | 1309 |
1310 // back to nominal frequency | 1310 // back to nominal frequency |
1311 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); | 1311 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); |
1312 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); | 1312 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); |
1313 ad9912_set_frequency_w(&ad9912, 2, f0_DDS[2]); | 1313 ad9912_set_frequency_w(&ad9912, 2, f0_DDS[2]); |
1314 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1314 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1315 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1315 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1316 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 1316 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
1317 | 1317 |
1318 // done | 1318 // done |
1319 n_measurement[HG] = N_MEASUREMENT_NONE; | 1319 n_measurement[HG] = N_MEASUREMENT_NONE; |
1320 } | 1320 } |
1321 break; | 1321 break; |
1322 } | 1322 } |
1323 | 1323 |
1324 switch (n_measurement[SR]) { | 1324 switch (n_measurement[SR]) { |
1325 | 1325 |
1326 case N_MEASUREMENT_NONE: | 1326 case N_MEASUREMENT_NONE: |
1327 // not measuring N3 | 1327 // not measuring N3 |
1328 break; | 1328 break; |
1329 | 1329 |
1330 case N_MEASUREMENT_INIT: | 1330 case N_MEASUREMENT_INIT: |
1331 // init | 1331 // init |
1332 | 1332 |
1333 // set DDS1 to nominal frequency | 1333 // set DDS1 to nominal frequency |
1334 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); | 1334 ad9912_set_frequency_w(&ad9912, 0, f0_DDS[0]); |
1335 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1335 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1336 | 1336 |
1337 // record current DDS frequencies | 1337 // record current DDS frequencies |
1338 f0_DDS[1] = ad9912.frequency[1]; | 1338 f0_DDS[1] = ad9912.frequency[1]; |
1339 f0_DDS[3] = ad9912.frequency[3]; | 1339 f0_DDS[3] = ad9912.frequency[3]; |
1340 | 1340 |
1341 t1 = utc; | 1341 t1 = utc; |
1342 t2 = t3 = 0.0; | 1342 t2 = t3 = 0.0; |
1343 nobs = 0; | 1343 nobs = 0; |
1344 stat_zero(&stat_math1); | 1344 stat_zero(&stat_math1); |
1345 stat_zero(&stat_ch3); | 1345 stat_zero(&stat_ch3); |
1346 f_rep_plus = f_rep_minus = 0.0; | 1346 f_rep_plus = f_rep_minus = 0.0; |
1347 f_beat_plus = f_beat_minus = 0.0; | 1347 f_beat_plus = f_beat_minus = 0.0; |
1348 | 1348 |
1349 // next step | 1349 // next step |
1350 n_measurement[SR] += 1; | 1350 n_measurement[SR] += 1; |
1351 break; | 1351 break; |
1352 | 1352 |
1353 case N_MEASUREMENT_SLOPE: | 1353 case N_MEASUREMENT_SLOPE: |
1354 // slope measurement | 1354 // slope measurement |
1355 | 1355 |
1356 if (settling-- > 0) | 1356 if (settling-- > 0) |
1357 break; | 1357 break; |
1358 | 1358 |
1359 stat_accumulate(&stat_math1, Math1); | 1359 stat_accumulate(&stat_math1, Math1); |
1360 stat_accumulate(&stat_ch3, Ch3); | 1360 stat_accumulate(&stat_ch3, Ch3); |
1361 | 1361 |
1362 if (utc - t1 > slope_time[SR]) { | 1362 if (utc - t1 > slope_time[SR]) { |
1363 // slope measurement | 1363 // slope measurement |
1364 f_rep_slope = stat_math1.slope; | 1364 f_rep_slope = stat_math1.slope; |
1365 f_beat_slope = stat_ch3.slope; | 1365 f_beat_slope = stat_ch3.slope; |
1366 | 1366 |
1367 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); | 1367 logmsg("f_rep_slope=%e Hz/s", f_rep_slope); |
1368 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); | 1368 logmsg("f_beat_slope=%e Hz/s", f_rep_slope); |
1369 | 1369 |
1370 // frep positive step | 1370 // frep positive step |
1371 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[SR], FREP_STEP_SIZE); | 1371 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] + delta_f_lock[SR], FREP_STEP_SIZE); |
1372 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1372 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1373 | 1373 |
1374 // adjust DDS3 to keep beatnote within the bandpass filter | 1374 // adjust DDS3 to keep beatnote within the bandpass filter |
1375 double fDDS4 = f0_DDS[3] + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; | 1375 double fDDS4 = f0_DDS[3] + Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; |
1376 ad9912_set_frequency_w(&ad9912, 3, fDDS4); | 1376 ad9912_set_frequency_w(&ad9912, 3, fDDS4); |
1377 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); | 1377 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); |
1378 | 1378 |
1379 // allow counter to settle | 1379 // allow counter to settle |
1380 settling = 3; | 1380 settling = 3; |
1381 | 1381 |
1382 // next step | 1382 // next step |
1383 n_measurement[SR] += 1; | 1383 n_measurement[SR] += 1; |
1384 } | 1384 } |
1385 break; | 1385 break; |
1386 | 1386 |
1388 case N_MEASUREMENT_ADJUST_FREQ_MINUS: | 1388 case N_MEASUREMENT_ADJUST_FREQ_MINUS: |
1389 // adjust DDS frequency to keep beatnote within the bandpass filter | 1389 // adjust DDS frequency to keep beatnote within the bandpass filter |
1390 | 1390 |
1391 if (settling-- > 0) | 1391 if (settling-- > 0) |
1392 break; | 1392 break; |
1393 | 1393 |
1394 // adjust DDS frequency to keep 55 MHz tracker oscillator locked | 1394 // adjust DDS frequency to keep 55 MHz tracker oscillator locked |
1395 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; | 1395 double fDDS2 = ad9912.frequency[1] + 275000 - Ch4; |
1396 ad9912_set_frequency_w(&ad9912, 1, fDDS2); | 1396 ad9912_set_frequency_w(&ad9912, 1, fDDS2); |
1397 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1397 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1398 | 1398 |
1399 // allow counter to settle | 1399 // allow counter to settle |
1400 settling = 3; | 1400 settling = 3; |
1401 | 1401 |
1402 // next step | 1402 // next step |
1403 n_measurement[SR] += 1; | 1403 n_measurement[SR] += 1; |
1404 break; | 1404 break; |
1405 | 1405 |
1406 case N_MEASUREMENT_FREP_PLUS: | 1406 case N_MEASUREMENT_FREP_PLUS: |
1407 // frep positive step | 1407 // frep positive step |
1408 | 1408 |
1409 if (settling-- > 0) | 1409 if (settling-- > 0) |
1410 break; | 1410 break; |
1411 | 1411 |
1412 if (t2 == 0.0) | 1412 if (t2 == 0.0) |
1413 t2 = utc; | 1413 t2 = utc; |
1414 | 1414 |
1415 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); | 1415 f_rep_plus += Math1 + 250000000 - f_rep_slope * (utc - t2); |
1416 f_beat_plus += Ch3 - f_beat_slope * (utc - t2); | 1416 f_beat_plus += Ch3 - f_beat_slope * (utc - t2); |
1417 nobs += 1; | 1417 nobs += 1; |
1418 | 1418 |
1419 if (utc - t2 > integration_time[SR]) { | 1419 if (utc - t2 > integration_time[SR]) { |
1420 f_rep_plus = f_rep_plus / nobs; | 1420 f_rep_plus = f_rep_plus / nobs; |
1421 f_beat_plus = f_beat_plus / nobs; | 1421 f_beat_plus = f_beat_plus / nobs; |
1422 nobs = 0; | 1422 nobs = 0; |
1423 | 1423 |
1424 // frep negative step | 1424 // frep negative step |
1425 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[SR], FREP_STEP_SIZE); | 1425 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0] - delta_f_lock[SR], FREP_STEP_SIZE); |
1426 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1426 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1427 | 1427 |
1428 // adjust DDS3 to keep beatnote within the bandpass filter | 1428 // adjust DDS3 to keep beatnote within the bandpass filter |
1429 double fDDS4 = f0_DDS[3] - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; | 1429 double fDDS4 = f0_DDS[3] - Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; |
1430 ad9912_set_frequency_w(&ad9912, 3, fDDS4); | 1430 ad9912_set_frequency_w(&ad9912, 3, fDDS4); |
1431 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); | 1431 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); |
1432 | 1432 |
1433 // allow counter to settle | 1433 // allow counter to settle |
1434 settling = 3; | 1434 settling = 3; |
1435 | 1435 |
1436 // next step | 1436 // next step |
1437 n_measurement[SR] += 1; | 1437 n_measurement[SR] += 1; |
1438 } | 1438 } |
1439 break; | 1439 break; |
1440 | 1440 |
1441 case N_MEASUREMENT_FREP_MINUS: | 1441 case N_MEASUREMENT_FREP_MINUS: |
1442 // frep negative step | 1442 // frep negative step |
1443 | 1443 |
1444 if (settling-- > 0) | 1444 if (settling-- > 0) |
1445 break; | 1445 break; |
1446 | 1446 |
1447 if (t3 == 0.0) | 1447 if (t3 == 0.0) |
1448 t3 = utc; | 1448 t3 = utc; |
1449 | 1449 |
1450 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); | 1450 f_rep_minus += Math1 + 250000000 - f_rep_slope * (utc - t2); |
1451 f_beat_minus += Ch3 - f_beat_slope * (utc - t2); | 1451 f_beat_minus += Ch3 - f_beat_slope * (utc - t2); |
1452 nobs += 1; | 1452 nobs += 1; |
1453 | 1453 |
1454 if (utc - t3 > integration_time[SR]) { | 1454 if (utc - t3 > integration_time[SR]) { |
1455 f_rep_minus = f_rep_minus / nobs; | 1455 f_rep_minus = f_rep_minus / nobs; |
1456 f_beat_minus = f_beat_minus / nobs; | 1456 f_beat_minus = f_beat_minus / nobs; |
1457 nobs = 0; | 1457 nobs = 0; |
1458 | 1458 |
1459 // check delta frep | 1459 // check delta frep |
1460 double delta_f_rep_m = f_rep_minus - f_rep_plus; | 1460 double delta_f_rep_m = f_rep_minus - f_rep_plus; |
1461 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[SR] / N1; | 1461 double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock[SR] / N1; |
1462 double delta = delta_f_rep_m - delta_f_rep; | 1462 double delta = delta_f_rep_m - delta_f_rep; |
1463 | 1463 |
1464 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", | 1464 logmsg("delta frep: measured=%e expected=%e difference=%e rel=%e", |
1465 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); | 1465 delta_f_rep_m, delta_f_rep, delta, delta / delta_f_rep); |
1466 | 1466 |
1467 // compute N3 | 1467 // compute N3 |
1468 double delta_f_beat = f_beat_minus - f_beat_plus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; | 1468 double delta_f_beat = f_beat_minus - f_beat_plus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock[SR]; |
1469 double delta_f_beat_expected = delta_f_rep * N3; | 1469 double delta_f_beat_expected = delta_f_rep * N3; |
1470 | 1470 |
1471 logmsg("delta fbeat: measured=%e expected=%e difference=%e", | 1471 logmsg("delta fbeat: measured=%e expected=%e difference=%e", |
1472 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); | 1472 delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); |
1473 | 1473 |
1474 double measured = delta_f_beat / delta_f_rep; | 1474 double measured = delta_f_beat / delta_f_rep; |
1475 SetCtrlVal(CalcNPanel, CALCN_N, measured); | 1475 SetCtrlVal(CalcNPanel, CALCN_N, measured); |
1476 | 1476 |
1477 logmsg("measured N3=%.3f", measured); | 1477 logmsg("measured N3=%.3f", measured); |
1478 | 1478 |
1479 // back to nominal frep | 1479 // back to nominal frep |
1480 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); | 1480 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); |
1481 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); | 1481 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); |
1482 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]); | 1482 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]); |
1483 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1483 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1484 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1484 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1485 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); | 1485 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); |
1486 | 1486 |
1487 // done | 1487 // done |
1488 n_measurement[SR] = N_MEASUREMENT_NONE; | 1488 n_measurement[SR] = N_MEASUREMENT_NONE; |
1489 } | 1489 } |
1490 break; | 1490 break; |
1491 } | 1491 } |
1492 | 1492 |
1493 // beatnote sign determination | 1493 // beatnote sign determination |
1494 if ((beatsign.measure != NONE) && | 1494 if ((beatsign.measure != NONE) && |
1495 (utc > beatsign.t0 + 2.0)) { | 1495 (utc > beatsign.t0 + 2.0)) { |
1496 | 1496 |
1497 int f_beat_sign, f_rep_sign = 0; | 1497 int f_beat_sign, f_rep_sign = 0; |
1498 | 1498 |
1499 switch (beatsign.measure) { | 1499 switch (beatsign.measure) { |
1500 case LO: | 1500 case LO: |
1501 f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; | 1501 f_rep_sign = (Math1 > beatsign.f_rep_zero) ? -1 : 1; |
1502 Sign1 = f_rep_sign; | 1502 Sign1 = f_rep_sign; |
1503 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); | 1503 SetCtrlVal(MainPanel, PANEL_SIGN1, Sign1); |
1520 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS); | 1520 ad9912_set_frequency_w(&ad9912, 0, beatsign.f0_DDS); |
1521 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1521 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1522 | 1522 |
1523 // measurement done | 1523 // measurement done |
1524 beatsign.measure = NONE; | 1524 beatsign.measure = NONE; |
1525 | 1525 |
1526 // in the case of the optical beatnotes sign measurement | 1526 // in the case of the optical beatnotes sign measurement |
1527 // we induce fairly small steps in f_rep therefore it is | 1527 // we induce fairly small steps in f_rep therefore it is |
1528 // good to check that we get the sign of the comb locking | 1528 // good to check that we get the sign of the comb locking |
1529 // beatnote right in those cases | 1529 // beatnote right in those cases |
1530 if (f_rep_sign != Sign1) | 1530 if (f_rep_sign != Sign1) |
1531 logmessage(ERROR, "merasured f_rep_sign does not agree with previous determination!"); | 1531 logmessage(ERROR, "merasured f_rep_sign does not agree with previous determination!"); |
1532 } | 1532 } |
1533 | 1533 |
1534 // select dedrift reference | 1534 // select dedrift reference |
1535 double f = 0.0; | 1535 double f = 0.0; |
1536 switch (dedrift.reference) { | 1536 switch (dedrift.reference) { |
1537 case MICROWAVE: | 1537 case MICROWAVE: |
1538 f = Math2; | 1538 f = Math2; |
1542 break; | 1542 break; |
1543 } | 1543 } |
1544 | 1544 |
1545 // dedrift | 1545 // dedrift |
1546 dedrift_update(f); | 1546 dedrift_update(f); |
1547 | 1547 |
1548 // recenter | 1548 // recenter |
1549 recenter_update(); | 1549 recenter_update(); |
1550 | 1550 |
1551 struct tm *time = gmtime(&ev.time.tv_sec); | 1551 struct tm *time = gmtime(&ev.time.tv_sec); |
1552 // round to milliseconds | 1552 // round to milliseconds |
1559 char timestr[24]; | 1559 char timestr[24]; |
1560 int len = strftime(timestr, sizeof(timestr), "%d/%m/%Y %H:%M:%S", time); | 1560 int len = strftime(timestr, sizeof(timestr), "%d/%m/%Y %H:%M:%S", time); |
1561 snprintf(timestr + len, sizeof(timestr) - len, ".%03d", msec); | 1561 snprintf(timestr + len, sizeof(timestr) - len, ".%03d", msec); |
1562 // display local time | 1562 // display local time |
1563 SetCtrlVal(MainPanel, PANEL_TIME, timestr); | 1563 SetCtrlVal(MainPanel, PANEL_TIME, timestr); |
1564 | 1564 |
1565 // run id derived from current date in the form YYMMDD | 1565 // run id derived from current date in the form YYMMDD |
1566 char id[7]; | 1566 char id[7]; |
1567 strftime(id, sizeof(id), "%y%m%d", time); | 1567 strftime(id, sizeof(id), "%y%m%d", time); |
1568 | 1568 |
1569 // write datafiles | 1569 // write datafiles |
1570 for (struct datafile *d = datafiles; d->data; d++) | 1570 for (struct datafile *d = datafiles; d->data; d++) |
1571 datafile_append(d, id, timestr); | 1571 datafile_append(d, id, timestr); |
1572 | 1572 |
1573 // send Sr frequency (Math4) to Sr data logger | 1573 // send Sr frequency (Math4) to Sr data logger |
1574 sr_datalogger_send(&datalogger, utc, Math4); | 1574 sr_datalogger_send(&datalogger, utc, Math4); |
1575 | 1575 |
1576 // publish data through ZMQ | 1576 // publish data through ZMQ |
1577 int r = zmq_xpub(zmqsocket, "RAW", &ev, sizeof(ev)); | 1577 int r = zmq_xpub(zmqsocket, "RAW", &ev, sizeof(ev)); |
1578 if (r) | 1578 if (r) |
1579 logmessage(ERROR, "cannot send data through ZMQ socket: %s", zmq_strerror(r)); | 1579 logmessage(ERROR, "cannot send data through ZMQ socket: %s", zmq_strerror(r)); |
1580 } | 1580 } |
1581 break; | 1581 break; |
1582 } | 1582 } |
1583 } | 1583 } |
1584 | 1584 |
1585 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event, | 1585 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event, |
1610 break; | 1610 break; |
1611 } | 1611 } |
1612 return 0; | 1612 return 0; |
1613 } | 1613 } |
1614 | 1614 |
1615 int CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event, | 1615 int CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event, |
1616 void *callbackData, int eventData1, int eventData2) | 1616 void *callbackData, int eventData1, int eventData2) |
1617 { | 1617 { |
1618 switch (event) { | 1618 switch (event) { |
1619 case EVENT_COMMIT: | 1619 case EVENT_COMMIT: |
1620 double frequency; | 1620 double frequency; |
1640 break; | 1640 break; |
1641 } | 1641 } |
1642 return 0; | 1642 return 0; |
1643 } | 1643 } |
1644 | 1644 |
1645 int CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event, | 1645 int CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event, |
1646 void *callbackData, int eventData1, int eventData2) | 1646 void *callbackData, int eventData1, int eventData2) |
1647 { | 1647 { |
1648 switch (event) | 1648 switch (event) |
1649 { | 1649 { |
1650 case EVENT_COMMIT: | 1650 case EVENT_COMMIT: |
1673 int CVICALLBACK CB_ChangeMath (int panel, int control, int event, | 1673 int CVICALLBACK CB_ChangeMath (int panel, int control, int event, |
1674 void *callbackData, int eventData1, int eventData2) | 1674 void *callbackData, int eventData1, int eventData2) |
1675 { | 1675 { |
1676 int len; | 1676 int len; |
1677 char *string; | 1677 char *string; |
1678 | 1678 |
1679 switch (event) | 1679 switch (event) |
1680 { | 1680 { |
1681 case EVENT_COMMIT: | 1681 case EVENT_COMMIT: |
1682 GetCtrlAttribute(panel, control, ATTR_STRING_TEXT_LENGTH, &len); | 1682 GetCtrlAttribute(panel, control, ATTR_STRING_TEXT_LENGTH, &len); |
1683 string = (char *)malloc(sizeof(char) * (len + 1)); | 1683 string = (char *)malloc(sizeof(char) * (len + 1)); |
1749 break; | 1749 break; |
1750 case SR: | 1750 case SR: |
1751 N3 = round(measured); | 1751 N3 = round(measured); |
1752 SetCtrlVal(MainPanel, PANEL_N3, N3); | 1752 SetCtrlVal(MainPanel, PANEL_N3, N3); |
1753 break; | 1753 break; |
1754 } | 1754 } |
1755 break; | 1755 break; |
1756 } | 1756 } |
1757 return 0; | 1757 return 0; |
1758 } | 1758 } |
1759 | 1759 |
1760 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, | 1760 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event, |
1761 void *callbackData, int eventData1, int eventData2) | 1761 void *callbackData, int eventData1, int eventData2) |
1762 { | 1762 { |
1763 int visible; | 1763 int visible; |
1764 | 1764 |
1765 switch (event) { | 1765 switch (event) { |
1766 case EVENT_COMMIT: | 1766 case EVENT_COMMIT: |
1767 switch (control) { | 1767 switch (control) { |
1768 case PANEL_N1CALCULUS: | 1768 case PANEL_N1CALCULUS: |
1769 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); | 1769 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); |
1785 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time[HG]); | 1785 SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time[HG]); |
1786 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time[HG]); | 1786 SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time[HG]); |
1787 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[HG] / 1000.0); | 1787 SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, delta_f_lock[HG] / 1000.0); |
1788 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); | 1788 SetCtrlVal(CalcNPanel, CALCN_N, 0.0); |
1789 DisplayPanel(CalcNPanel); | 1789 DisplayPanel(CalcNPanel); |
1790 } | 1790 } |
1791 break; | 1791 break; |
1792 case PANEL_N3CALCULUS: | 1792 case PANEL_N3CALCULUS: |
1793 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); | 1793 GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); |
1794 if (! visible) { | 1794 if (! visible) { |
1795 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); | 1795 SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); |
1810 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, | 1810 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, |
1811 void *callbackData, int eventData1, int eventData2) | 1811 void *callbackData, int eventData1, int eventData2) |
1812 { | 1812 { |
1813 void *v; | 1813 void *v; |
1814 int measuring; | 1814 int measuring; |
1815 | 1815 |
1816 switch (event) { | 1816 switch (event) { |
1817 case EVENT_COMMIT: | 1817 case EVENT_COMMIT: |
1818 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); | 1818 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); |
1819 measuring = PTR_TO_INT(v); | 1819 measuring = PTR_TO_INT(v); |
1820 switch (measuring) { | 1820 switch (measuring) { |
1851 int CVICALLBACK CB_OnNStop (int panel, int control, int event, | 1851 int CVICALLBACK CB_OnNStop (int panel, int control, int event, |
1852 void *callbackData, int eventData1, int eventData2) | 1852 void *callbackData, int eventData1, int eventData2) |
1853 { | 1853 { |
1854 void *v; | 1854 void *v; |
1855 int measuring; | 1855 int measuring; |
1856 | 1856 |
1857 switch (event) { | 1857 switch (event) { |
1858 case EVENT_COMMIT: | 1858 case EVENT_COMMIT: |
1859 HidePanel(CalcNPanel); | 1859 HidePanel(CalcNPanel); |
1860 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); | 1860 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); |
1861 measuring = PTR_TO_INT(v); | 1861 measuring = PTR_TO_INT(v); |
1876 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); | 1876 ad9912_ramp_frequency_w(&ad9912, 0, f0_DDS[0], FREP_STEP_SIZE); |
1877 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); | 1877 ad9912_set_frequency_w(&ad9912, 1, f0_DDS[1]); |
1878 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]); | 1878 ad9912_set_frequency_w(&ad9912, 3, f0_DDS[3]); |
1879 break; | 1879 break; |
1880 } | 1880 } |
1881 | 1881 |
1882 // update DDS frequencies display | 1882 // update DDS frequencies display |
1883 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); | 1883 SetCtrlVal(MainPanel, PANEL_DDS1, ad9912.frequency[0]); |
1884 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); | 1884 SetCtrlVal(MainPanel, PANEL_DDS2, ad9912.frequency[1]); |
1885 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); | 1885 SetCtrlVal(MainPanel, PANEL_DDS3, ad9912.frequency[2]); |
1886 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); | 1886 SetCtrlVal(MainPanel, PANEL_DDS4, ad9912.frequency[3]); |
1887 | 1887 |
1888 break; | 1888 break; |
1889 } | 1889 } |
1890 return 0; | 1890 return 0; |
1891 } | 1891 } |
1892 | 1892 |
1893 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, | 1893 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, |
1894 void *callbackData, int eventData1, int eventData2) | 1894 void *callbackData, int eventData1, int eventData2) |
1895 { | 1895 { |
1896 double step = 0.0; | 1896 double step = 0.0; |
1897 switch (event) | 1897 switch (event) |
1898 { | 1898 { |
1926 break; | 1926 break; |
1927 } | 1927 } |
1928 return 0; | 1928 return 0; |
1929 } | 1929 } |
1930 | 1930 |
1931 int CVICALLBACK CB_AdjustDDSFreq (int panel, int control, int event, | 1931 int CVICALLBACK CB_AdjustDDSFreq (int panel, int control, int event, |
1932 void *callbackData, int eventData1, int eventData2) | 1932 void *callbackData, int eventData1, int eventData2) |
1933 { | 1933 { |
1934 double frequency; | 1934 double frequency; |
1935 switch (event) | 1935 switch (event) |
1936 { | 1936 { |
1956 break; | 1956 break; |
1957 } | 1957 } |
1958 return 0; | 1958 return 0; |
1959 } | 1959 } |
1960 | 1960 |
1961 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, | 1961 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, |
1962 void *callbackData, int eventData1, int eventData2) | 1962 void *callbackData, int eventData1, int eventData2) |
1963 { | 1963 { |
1964 switch (event) | 1964 switch (event) |
1965 { | 1965 { |
1966 case EVENT_COMMIT: | 1966 case EVENT_COMMIT: |
1971 break; | 1971 break; |
1972 } | 1972 } |
1973 return 0; | 1973 return 0; |
1974 } | 1974 } |
1975 | 1975 |
1976 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, | 1976 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, |
1977 void *callbackData, int eventData1, int eventData2) | 1977 void *callbackData, int eventData1, int eventData2) |
1978 { | 1978 { |
1979 int enable; | 1979 int enable; |
1980 switch (event) | 1980 switch (event) |
1981 { | 1981 { |
1982 case EVENT_COMMIT: | 1982 case EVENT_COMMIT: |
1983 GetCtrlVal(panel, control, &enable); | 1983 GetCtrlVal(panel, control, &enable); |
1984 enable ? dedrift_update_enable() : dedrift_update_disable(); | 1984 enable ? dedrift_update_enable() : dedrift_update_disable(); |
1985 break; | 1985 break; |
1986 } | 1986 } |
1987 return 0; | 1987 return 0; |
1988 } | 1988 } |
1989 | 1989 |
1990 int CVICALLBACK CB_OnResetSlope (int panel, int control, int event, | 1990 int CVICALLBACK CB_OnResetSlope (int panel, int control, int event, |
1991 void *callbackData, int eventData1, int eventData2) | 1991 void *callbackData, int eventData1, int eventData2) |
1992 { | 1992 { |
1993 switch (event) | 1993 switch (event) |
1994 { | 1994 { |
1995 case EVENT_COMMIT: | 1995 case EVENT_COMMIT: |
1996 dedrift.applied = 0.0; | 1996 dedrift.applied = 0.0; |
1997 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); | 1997 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); |
1998 ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied); | 1998 ad9956_set_w(&ad9956, dedrift.fDDS, dedrift.applied); |
1999 logmsg("dedrift: reset"); | 1999 logmsg("dedrift: reset"); |
2000 break; | 2000 break; |
2001 } | 2001 } |
2002 return 0; | 2002 return 0; |
2003 } | 2003 } |
2004 | 2004 |
2005 int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, | 2005 int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, |
2006 void *callbackData, int eventData1, int eventData2) | 2006 void *callbackData, int eventData1, int eventData2) |
2007 { | 2007 { |
2008 switch (event) | 2008 switch (event) |
2009 { | 2009 { |
2010 case EVENT_COMMIT: | 2010 case EVENT_COMMIT: |
2011 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval); | 2011 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval); |
2012 break; | 2012 break; |
2013 } | 2013 } |
2014 return 0; | 2014 return 0; |
2015 } | 2015 } |
2016 | 2016 |
2017 int CVICALLBACK CB_OnDedriftSettingsChange (int panel, int control, int event, | 2017 int CVICALLBACK CB_OnDedriftSettingsChange (int panel, int control, int event, |
2018 void *callbackData, int eventData1, int eventData2) | 2018 void *callbackData, int eventData1, int eventData2) |
2019 { | 2019 { |
2020 switch (event) | 2020 switch (event) |
2021 { | 2021 { |
2022 case EVENT_COMMIT: | 2022 case EVENT_COMMIT: |
2042 break; | 2042 break; |
2043 } | 2043 } |
2044 return 0; | 2044 return 0; |
2045 } | 2045 } |
2046 | 2046 |
2047 int CVICALLBACK CB_RecenterEnable (int panel, int control, int event, | 2047 int CVICALLBACK CB_RecenterEnable (int panel, int control, int event, |
2048 void *callbackData, int eventData1, int eventData2) | 2048 void *callbackData, int eventData1, int eventData2) |
2049 { | 2049 { |
2050 switch (event) | 2050 switch (event) |
2051 { | 2051 { |
2052 case EVENT_COMMIT: | 2052 case EVENT_COMMIT: |
2058 break; | 2058 break; |
2059 } | 2059 } |
2060 return 0; | 2060 return 0; |
2061 } | 2061 } |
2062 | 2062 |
2063 int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, | 2063 int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, |
2064 void *callbackData, int eventData1, int eventData2) | 2064 void *callbackData, int eventData1, int eventData2) |
2065 { | 2065 { |
2066 switch (event) | 2066 switch (event) |
2067 { | 2067 { |
2068 case EVENT_COMMIT: | 2068 case EVENT_COMMIT: |
2115 void *callbackData, int eventData1, int eventData2) | 2115 void *callbackData, int eventData1, int eventData2) |
2116 { | 2116 { |
2117 switch (event) | 2117 switch (event) |
2118 { | 2118 { |
2119 case EVENT_COMMIT: | 2119 case EVENT_COMMIT: |
2120 // stop slope measurement and reset slope | 2120 // stop slope measurement and reset slope |
2121 dedrift.enabled = FALSE; | 2121 dedrift.enabled = FALSE; |
2122 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); | 2122 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); |
2123 dedrift.applied = 0.0; | 2123 dedrift.applied = 0.0; |
2124 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); | 2124 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); |
2125 // reset DDS | 2125 // reset DDS |
2291 return 0; | 2291 return 0; |
2292 } | 2292 } |
2293 | 2293 |
2294 | 2294 |
2295 // | 2295 // |
2296 // N estimate | 2296 // N estimate |
2297 // | 2297 // |
2298 | 2298 |
2299 static void estimateN (void) | 2299 static void estimateN (void) |
2300 { | 2300 { |
2301 double nu, fbeat, frep, N; | 2301 double nu, fbeat, frep, N; |
2302 int sign; | 2302 int sign; |
2303 | 2303 |
2304 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, &nu); | 2304 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, &nu); |
2305 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, &frep); | 2305 GetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, &frep); |
2306 GetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, &fbeat); | 2306 GetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, &fbeat); |
2307 GetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, &sign); | 2307 GetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, &sign); |
2308 | 2308 |
2309 N = (nu * 1.0e12 - sign * fbeat) / frep; | 2309 N = (nu * 1.0e12 - sign * fbeat) / frep; |
2310 | 2310 |
2311 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, N); | 2311 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, N); |
2312 } | 2312 } |
2313 | 2313 |
2314 int CVICALLBACK cb_onEstimateN (int panel, int control, int event, | 2314 int CVICALLBACK cb_onEstimateN (int panel, int control, int event, |
2315 void *callbackData, int eventData1, int eventData2) | 2315 void *callbackData, int eventData1, int eventData2) |
2316 { | 2316 { |
2317 int visible; | 2317 int visible; |
2318 | 2318 |
2319 switch (event) | 2319 switch (event) |
2320 { | 2320 { |
2321 case EVENT_COMMIT: | 2321 case EVENT_COMMIT: |
2322 // reset N estimate | 2322 // reset N estimate |
2323 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0); | 2323 SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0); |
2334 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[2]); | 2334 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[2]); |
2335 // f_counter | 2335 // f_counter |
2336 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch2); | 2336 SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch2); |
2337 // f_beat | 2337 // f_beat |
2338 SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[2] - Ch2); | 2338 SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[2] - Ch2); |
2339 | 2339 |
2340 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg"); | 2340 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg"); |
2341 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG)); | 2341 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG)); |
2342 break; | 2342 break; |
2343 case PANEL_ESTIMATE_N3: | 2343 case PANEL_ESTIMATE_N3: |
2344 // expected frequency | 2344 // expected frequency |
2355 | 2355 |
2356 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr"); | 2356 SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr"); |
2357 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); | 2357 SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); |
2358 break; | 2358 break; |
2359 } | 2359 } |
2360 | 2360 |
2361 // display dialog | 2361 // display dialog |
2362 GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible); | 2362 GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible); |
2363 if (! visible) | 2363 if (! visible) |
2364 DisplayPanel(EstimateNPanel); | 2364 DisplayPanel(EstimateNPanel); |
2365 | 2365 |
2366 // compute | 2366 // compute |
2367 estimateN(); | 2367 estimateN(); |
2368 break; | 2368 break; |
2369 } | 2369 } |
2370 return 0; | 2370 return 0; |
2372 | 2372 |
2373 int CVICALLBACK cb_onEstimateNWaveleght (int panel, int control, int event, | 2373 int CVICALLBACK cb_onEstimateNWaveleght (int panel, int control, int event, |
2374 void *callbackData, int eventData1, int eventData2) | 2374 void *callbackData, int eventData1, int eventData2) |
2375 { | 2375 { |
2376 double wavelenght, frequency; | 2376 double wavelenght, frequency; |
2377 | 2377 |
2378 switch (event) | 2378 switch (event) |
2379 { | 2379 { |
2380 case EVENT_COMMIT: | 2380 case EVENT_COMMIT: |
2381 GetCtrlVal(panel, control, &wavelenght); | 2381 GetCtrlVal(panel, control, &wavelenght); |
2382 frequency = SPEED_OF_LIGHT / (wavelenght * 1.0e-9) / 1.0e12; | 2382 frequency = SPEED_OF_LIGHT / (wavelenght * 1.0e-9) / 1.0e12; |
2389 | 2389 |
2390 int CVICALLBACK cb_onEstimateNFrequency (int panel, int control, int event, | 2390 int CVICALLBACK cb_onEstimateNFrequency (int panel, int control, int event, |
2391 void *callbackData, int eventData1, int eventData2) | 2391 void *callbackData, int eventData1, int eventData2) |
2392 { | 2392 { |
2393 double wavelenght, frequency; | 2393 double wavelenght, frequency; |
2394 | 2394 |
2395 switch (event) | 2395 switch (event) |
2396 { | 2396 { |
2397 case EVENT_COMMIT: | 2397 case EVENT_COMMIT: |
2398 GetCtrlVal(panel, control, &frequency); | 2398 GetCtrlVal(panel, control, &frequency); |
2399 wavelenght = SPEED_OF_LIGHT / (frequency * 1.0e12) / 1.0e-9; | 2399 wavelenght = SPEED_OF_LIGHT / (frequency * 1.0e12) / 1.0e-9; |
2418 | 2418 |
2419 int CVICALLBACK cb_onEstimateNClose (int panel, int control, int event, | 2419 int CVICALLBACK cb_onEstimateNClose (int panel, int control, int event, |
2420 void *callbackData, int eventData1, int eventData2) | 2420 void *callbackData, int eventData1, int eventData2) |
2421 { | 2421 { |
2422 int visible; | 2422 int visible; |
2423 | 2423 |
2424 switch (event) | 2424 switch (event) |
2425 { | 2425 { |
2426 case EVENT_COMMIT: | 2426 case EVENT_COMMIT: |
2427 GetPanelAttribute(panel, ATTR_VISIBLE, &visible); | 2427 GetPanelAttribute(panel, ATTR_VISIBLE, &visible); |
2428 if (visible) | 2428 if (visible) |
2436 void *callbackData, int eventData1, int eventData2) | 2436 void *callbackData, int eventData1, int eventData2) |
2437 { | 2437 { |
2438 void *v; | 2438 void *v; |
2439 double n; | 2439 double n; |
2440 int estimate = 0; | 2440 int estimate = 0; |
2441 | 2441 |
2442 switch (event) | 2442 switch (event) |
2443 { | 2443 { |
2444 case EVENT_COMMIT: | 2444 case EVENT_COMMIT: |
2445 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); | 2445 GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); |
2446 estimate = PTR_TO_INT(v); | 2446 estimate = PTR_TO_INT(v); |
2459 HidePanel(panel); | 2459 HidePanel(panel); |
2460 break; | 2460 break; |
2461 } | 2461 } |
2462 return 0; | 2462 return 0; |
2463 } | 2463 } |
2464 |