comparison FXAnalyse.c @ 44:2e37910b28bc

Simplify logic and reindent
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 09 Oct 2012 14:36:10 +0200
parents 39a0f396d778
children 6503feae1809
comparison
equal deleted inserted replaced
43:39a0f396d778 44:2e37910b28bc
530 double DeltaCh4=0.0; 530 double DeltaCh4=0.0;
531 531
532 switch (event) 532 switch (event)
533 { 533 {
534 case EVENT_TIMER_TICK: 534 case EVENT_TIMER_TICK:
535 switch(Acquiring) 535
536 if (! Acquiring)
537 break;
538
539 GetFileInfo(LogFileName, &LogFileSize);
540
541 if (LogFileSize > OldLogFilePtr+2*FXLINELENGTH-2) { // if a complete newline has been written
542
543 SuspendTimerCallbacks();
544
545 // Open Log file and get to the beginning of newly completed line
546 LogFile = OpenFile(LogFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
547 OldLogFilePtr += FXLINELENGTH;
548 SetFilePtr(LogFile, OldLogFilePtr, 0);
549
550 // return the last complete string from the log file and scan it for date and time information
551
552 // first, the time tag, and store it in various formats
553 ReadFile(LogFile, TimeTag, 17);
554
555 CopyBytes(Date,0,TimeTag,4,2);
556 CopyBytes(Date,3,TimeTag,2,2);
557 CopyBytes(Date,8,TimeTag,0,2);
558 CopyBytes(Time,0,TimeTag,7,2);
559 CopyBytes(Time,3,TimeTag,9,2);
560 CopyBytes(Time,6,TimeTag,11,6);
561 SetCtrlVal(MainPanel, PANEL_DATE, Date);
562 SetCtrlVal(MainPanel, PANEL_TIME, Time);
563
564 CopyBytes(Year,2,TimeTag,0,2); // first 2 bytes of year string remains "20"
565 CopyBytes(ShortYear,0,TimeTag,0,2);
566 CopyBytes(Month,0,TimeTag,2,2);
567 CopyBytes(Day,0,TimeTag,4,2);
568 CopyBytes(Hour,0,TimeTag,7,2);
569 CopyBytes(Min,0,TimeTag,9,2);
570 CopyBytes(Sec,0,TimeTag,11,6);
571 Fmt(&LocalTime.tm_year, "%d<%s", Year);
572 Fmt(&LocalTime.tm_mon, "%d<%s", Month);
573 Fmt(&LocalTime.tm_mday, "%d<%s", Day);
574 Fmt(&LocalTime.tm_hour, "%d<%s", Hour);
575 Fmt(&LocalTime.tm_min, "%d<%s", Min);
576 Fmt(&LocalTime.tm_sec, "%d<%s", "00"); // special case to handle non integer number of UTC seconds
577 LocalTime.tm_hour += 0;
578 LocalTime.tm_min -= 0;
579 LocalTime.tm_sec -= 0;
580 LocalTime.tm_mon -= 1; // january is month 0 for tm struct
581 LocalTime.tm_year -= 1900; // year is number of years since 1900 for tm struct
582 LocalTime.tm_isdst = -1; // daylight saving flag MUST be set to -1 (unallocated is bugging and +1 is making 1 hour error in summer)
583 utcTime = mktime (&LocalTime);
584 utc = (double) utcTime + strtod(Sec,NULL);
585 mjd=utc/86400.; //nb de jours depuis l'origine d'UTC (01/01/1900 à 00h00 GMT)
586 mjd+=15020; //date MJD de la date origine d'UTC
587 SetCtrlVal(MainPanel, PANEL_UTC, utc);
588 SetCtrlVal(MainPanel, PANEL_MJD, mjd);
589
590 // scan the line for counters's channels information
591
592 ReadLine(LogFile, LineBuffer, FXLINELENGTH+9);
593 CloseFile(LogFile);
594
595 Scan(LineBuffer, "%f%f%f%f", &Ch1, &Ch2, &Ch3, &Ch4);
596 Ch1 = 1000*Ch1;
597 Ch2 = 1000*Ch2;
598 Ch3 = 1000*Ch3;
599 Ch4 = 1000*Ch4;
600
601 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1);
602 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2);
603 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3);
604 SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4);
605 SetCtrlVal(MainPanel, PANEL_SIGN1, Signe1);
606 SetCtrlVal(MainPanel, PANEL_SIGN2, Signe2);
607 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3);
608 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2);
609 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2);
610 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
611 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring);
612 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling);
613 // Treat data
614
615 Math1 = mupEval(MathParser1);
616 SetCtrlVal(MainPanel,PANEL_MATH1, Math1);
617
618 Math2 = mupEval(MathParser2);
619 SetCtrlVal(MainPanel,PANEL_MATH2, Math2);
620
621 Math3 = mupEval(MathParser3);
622 SetCtrlVal(MainPanel,PANEL_MATH3, Math3);
623
624 Math4 = mupEval(MathParser4);
625 SetCtrlVal(MainPanel,PANEL_MATH4, Math4);
626
627 Math5 = mupEval(MathParser5);
628 SetCtrlVal(MainPanel,PANEL_MATH5, Math5);
629
630 // Plot Data and calculus if required
631
632 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1PLOT, &BoxChecked);
633 if (BoxChecked) {
634 Plot_AddFrequency(&PlotCh1, Ch1);
635 }
636 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1ALLAN, &BoxChecked);
637 if (BoxChecked) {
638 Allan_AddFrequency(&AllanCh1, Ch1);
639 }
640
641 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2PLOT, &BoxChecked);
642 if (BoxChecked) {
643 Plot_AddFrequency(&PlotCh2, Ch2);
644 }
645 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2ALLAN, &BoxChecked);
646 if (BoxChecked) {
647 Allan_AddFrequency(&AllanCh2, Ch2);
648 }
649
650 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3PLOT, &BoxChecked);
651 if (BoxChecked) {
652 Plot_AddFrequency(&PlotCh3, Ch3);
653 }
654 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3ALLAN, &BoxChecked);
655 if (BoxChecked) {
656 Allan_AddFrequency(&AllanCh3, Ch3);
657 }
658
659 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4PLOT, &BoxChecked);
660 if (BoxChecked) {
661 Plot_AddFrequency(&PlotCh4, Ch4);
662 }
663 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4ALLAN, &BoxChecked);
664 if (BoxChecked) {
665 Allan_AddFrequency(&AllanCh4, Ch4);
666 }
667
668 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1PLOT, &BoxChecked);
669 if (BoxChecked) {
670 Plot_AddFrequency(&PlotMath1, Math1);
671 }
672 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1ALLAN, &BoxChecked);
673 if (BoxChecked) {
674 Allan_AddFrequency(&AllanMath1, Math1);
675 }
676
677 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2PLOT, &BoxChecked);
678 if (BoxChecked) {
679 Plot_AddFrequency(&PlotMath2, Math2);
680 }
681 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2ALLAN, &BoxChecked);
682 if (BoxChecked) {
683 Allan_AddFrequency(&AllanMath2, Math2);
684 }
685
686 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3PLOT, &BoxChecked);
687 if (BoxChecked) {
688 Plot_AddFrequency(&PlotMath3, Math3);
689 }
690 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3ALLAN, &BoxChecked);
691 if (BoxChecked) {
692 Allan_AddFrequency(&AllanMath3, Math3);
693 }
694
695 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4PLOT, &BoxChecked);
696 if (BoxChecked) {
697 Plot_AddFrequency(&PlotMath4, Math4);
698 }
699 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4ALLAN, &BoxChecked);
700 if (BoxChecked) {
701 Allan_AddFrequency(&AllanMath4, Math4);
702 }
703
704 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5PLOT, &BoxChecked);
705 if (BoxChecked) {
706 Plot_AddFrequency(&PlotMath5, Math5);
707 }
708 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked);
709 if (BoxChecked) {
710 Allan_AddFrequency(&AllanMath5, Math5);
711 }
712
713 // Calcul de N
714
715 switch (Measuring_1) {
716
717 case N_MEASUREMENT_NONE:
718 // not measuring
719 break;
720
721 case N_MEASUREMENT_INIT:
722 // initialization step
723
724 // set DDS1 to nominal frequency
725 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
726 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
727
728 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit);
729 t2_1 = t3_1 = 0.0;
730 t1_1 = utc;
731 Frequ_slope_1 = Math1;
732 Moy_slope_1 = Frequ_slope_1;
733 Ch4_slope = Ch4;
734 Moy_Ch4slope_1 = Ch4_slope;
735 N_slope_1 = 1;
736
737 // next step
738 Measuring_1 += 1;
739 break;
740
741 case N_MEASUREMENT_SLOPE:
742 // slope measurement
743
744 N_slope_1 = N_slope_1 + 1;
745 Frequ_slope_1 = Math1;
746 Ch4_slope = Ch4;
747 Moy_slope_1 = ((N_slope_1-1)*Moy_slope_1 + Frequ_slope_1)/N_slope_1;
748 Moy_Ch4slope_1 = ((N_slope_1-1)*Moy_Ch4slope_1 + Ch4_slope)/N_slope_1;
749 Slope_slope_1 = (Slope_slope_1*(N_slope_1-2) + 6*(Frequ_slope_1-Moy_slope_1)/N_slope_1)/(N_slope_1+1);
750 Slope_Ch4slope_1 = (Slope_Ch4slope_1*(N_slope_1-2) + 6*(Ch4_slope-Moy_Ch4slope_1)/N_slope_1)/(N_slope_1+1);
751
752 if ((utc - t1_1) > SlopeTime1) {
753 Slope_1 = Slope_slope_1;
754 Ch4Slope = Slope_Ch4slope_1;
755 SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1);
756
757 N_slope_1 = 0;
758 Frequ_slope_1 = 0.0;
759 Moy_slope_1 = 0.0;
760 Slope_slope_1 = 0.0;
761 Ch4_slope = 0.0;
762 Moy_Ch4slope_1 = 0.0;
763 Slope_Ch4slope_1 = 0.0;
764
765 // frep positive step
766 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv);
767 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_1*1000));
768 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_1*1000));
769
770 // allow counter to settle
771 settling = 3;
772
773 // next step
774 Measuring_1 += 1;
775 }
776 break;
777
778 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
779 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
780 // adjust DDS frequency to keep beatnote within the bandpass filter
781
782 if (settling > 0) {
783 settling--;
784 break;
785 }
786
787 double fDDS2;
788 GetCtrlVal(MainPanel, PANEL_DDS2, &fDDS2);
789 fDDS2 += 275000 - Ch4;
790 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2);
791 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2);
792
793 // allow counter to settle
794 settling = 3;
795
796 // next step
797 Measuring_1 += 1;
798 break;
799
800 case N_MEASUREMENT_FREP_PLUS:
801 // frep positive step
802
803 if (settling > 0) {
804 settling--;
805 break;
806 }
807
808 if (t2_1 == 0.0)
809 t2_1 = utc;
810
811 Frepplus_1 = Frepplus_1 + Math1 - Slope_1 * (utc - t2_1);
812 Ch4Plus = Ch4Plus + Ch4 - Ch4Slope * (utc - t2_1);
813 n_1 += 1;
814
815 if ((utc - t2_1) > DeltaT_1) {
816 Frepplus_1 = Frepplus_1 / n_1;
817 Ch4Plus = Ch4Plus / n_1;
818 n_1 = 0;
819
820 // frep negative step
821 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, (FrequDDS1+DeltakHz_1*1000),(FrequDDS1-DeltakHz_1*1000), Step1/Ndiv);
822 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_1*1000));
823 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1-DeltakHz_1*1000));
824
825 // allow counter to settle
826 settling = 3;
827
828 // next step
829 Measuring_1 += 1;
830 }
831 break;
832
833 case N_MEASUREMENT_FREP_MINUS:
834 // frep negative step
835
836 if (settling > 0) {
837 settling--;
838 break;
839 }
840
841 if (t3_1 == 0.0)
842 t3_1 = utc;
843
844 Frepminus_1 = Frepminus_1 + Math1 - Slope_1 * (utc - t3_1);
845 Ch4Minus = Ch4Minus + Ch4 - Ch4Slope * (utc - t3_1);
846 n_1 += 1;
847
848 if ((utc - t3_1) > DeltaT_1) {
849 Frepminus_1 = Frepminus_1 / n_1;
850 Ch4Minus = Ch4Minus / n_1;
851 n_1 = 0;
852
853 // compute N1
854 N_1 = Signe1 * (2*Ndiv * DeltakHz_1 * 1000)/(Frepminus_1 - Frepplus_1 - Slope_1 * (t3_1 - t2_1));
855 SetCtrlVal(CalcN1Panel, CALCN1_N, N_1);
856
857 t1_1 = 0.0;
858 t2_1 = 0.0;
859 t3_1 = 0.0;
860 Frepminus_1 = 0.0;
861 Frepplus_1 = 0.0;
862
863 // back to nominal frep
864 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912, 1, FrequDDS1-DeltakHz_1*1000,FrequDDS1, Step1/Ndiv );
865 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
866 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
867 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);
868 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
869
870 // done
871 Measuring_1 = N_MEASUREMENT_NONE;
872 }
873 break;
874 }
875
876 if (Measuring_2==TRUE)
536 { 877 {
537 case TRUE: 878 if (Step1_2==FALSE) {
538 879 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
539 GetFileInfo(LogFileName, &LogFileSize) ; 880 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
540 881
541 if (LogFileSize > OldLogFilePtr+2*FXLINELENGTH-2) { // if a complete newline has been written 882 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit);
542 883 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
543 SuspendTimerCallbacks() ; 884 t1_2=utc;
544 885 Frequ_slope_2=Math1;
545 // Open Log file and get to the beginning of newly completed line 886 Beat_slope_2=Ch2;
546 LogFile = OpenFile(LogFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII) ; 887 Moy_slope_2= Frequ_slope_2;
547 OldLogFilePtr += FXLINELENGTH; 888 Moy_Beatslope_2= Beat_slope_2;
548 SetFilePtr(LogFile, OldLogFilePtr, 0) ; 889 N_slope_2=1;
549 890 Step1_2=TRUE;
550 // return the last complete string from the log file and scan it for date and time information 891 Nu1=(250000000+Math1)*N1;
551 892 }
552 // first, the time tag, and store it in various formats 893 else {
553 ReadFile(LogFile, TimeTag, 17); 894 if(Step2_2==FALSE){
554 895 N_slope_2=N_slope_2+1;
555 CopyBytes(Date,0,TimeTag,4,2); 896 Frequ_slope_2=Math1;
556 CopyBytes(Date,3,TimeTag,2,2); 897 Beat_slope_2=Ch2;
557 CopyBytes(Date,8,TimeTag,0,2); 898 Moy_slope_2=((N_slope_2-1)*Moy_slope_2 + Frequ_slope_2)/N_slope_2;
558 CopyBytes(Time,0,TimeTag,7,2); 899 Moy_Beatslope_2=((N_slope_2-1)*Moy_Beatslope_2 + Beat_slope_2)/N_slope_2;
559 CopyBytes(Time,3,TimeTag,9,2); 900 Slope_slope_2 = (Slope_slope_2*(N_slope_2-2) + 6*(Frequ_slope_2-Moy_slope_2)/N_slope_2)/(N_slope_2+1);
560 CopyBytes(Time,6,TimeTag,11,6); 901 Slope_Beatslope_2 = (Slope_Beatslope_2*(N_slope_2-2) + 6*(Beat_slope_2-Moy_Beatslope_2)/N_slope_2)/(N_slope_2+1);
561 SetCtrlVal(MainPanel, PANEL_DATE, Date) ; 902 if (utc-t1_2>SlopeTime2) {
562 SetCtrlVal(MainPanel, PANEL_TIME, Time) ; 903 Slope_2 = Slope_slope_2;
563 904 Beatslope_2 = Slope_Beatslope_2;
564 CopyBytes(Year,2,TimeTag,0,2); // first 2 bytes of year string remains "20" 905 Step2_2=TRUE;
565 CopyBytes(ShortYear,0,TimeTag,0,2); 906 N_slope_2=0;
566 CopyBytes(Month,0,TimeTag,2,2); 907 Frequ_slope_2=0.0;
567 CopyBytes(Day,0,TimeTag,4,2); 908 Moy_slope_2=0.0;
568 CopyBytes(Hour,0,TimeTag,7,2); 909 Slope_slope_2 =0.0;
569 CopyBytes(Min,0,TimeTag,9,2); 910 Moy_Beatslope_2=0.0;
570 CopyBytes(Sec,0,TimeTag,11,6); 911 Slope_Beatslope_2 =0.0;
571 Fmt(&LocalTime.tm_year, "%d<%s", Year); 912 Beat_slope_2=0.0;
572 Fmt(&LocalTime.tm_mon, "%d<%s", Month); 913
573 Fmt(&LocalTime.tm_mday, "%d<%s", Day); 914 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_2*1000), Step2/Ndiv );
574 Fmt(&LocalTime.tm_hour, "%d<%s", Hour); 915 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_2*1000));
575 Fmt(&LocalTime.tm_min, "%d<%s", Min); 916 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_2*1000));
576 Fmt(&LocalTime.tm_sec, "%d<%s", "00"); // special case to handle non integer number of UTC seconds 917 Delay(0.1);
577 LocalTime.tm_hour += 0; 918 DeltaDDS3 = -DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2);
578 LocalTime.tm_min -= 0; 919 SetCtrlVal(MainPanel, PANEL_DDS3, (FrequencyDDS3Init+DeltaDDS3));
579 LocalTime.tm_sec -= 0; 920 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3,(FrequencyDDS3Init+DeltaDDS3));
580 LocalTime.tm_mon -= 1 ; // january is month 0 for tm struct 921
581 LocalTime.tm_year -= 1900 ; // year is number of years since 1900 for tm struct
582 LocalTime.tm_isdst = -1; // daylight saving flag MUST be set to -1 (unallocated is bugging and +1 is making 1 hour error in summer)
583 utcTime = mktime (&LocalTime);
584 utc = (double) utcTime + strtod(Sec,NULL) ;
585 mjd=utc/86400.; //nb de jours depuis l'origine d'UTC (01/01/1900 à 00h00 GMT)
586 mjd+=15020; //date MJD de la date origine d'UTC
587 SetCtrlVal(MainPanel, PANEL_UTC, utc);
588 SetCtrlVal(MainPanel, PANEL_MJD, mjd);
589
590 // scan the line for counters's channels information
591
592 ReadLine(LogFile, LineBuffer, FXLINELENGTH+9) ;
593 CloseFile(LogFile);
594
595 Scan(LineBuffer, "%f%f%f%f", &Ch1, &Ch2, &Ch3, &Ch4) ;
596 Ch1 = 1000*Ch1;
597 Ch2 = 1000*Ch2;
598 Ch3 = 1000*Ch3;
599 Ch4 = 1000*Ch4;
600
601 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1) ;
602 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2) ;
603 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3) ;
604 SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4) ;
605 SetCtrlVal(MainPanel, PANEL_SIGN1, Signe1);
606 SetCtrlVal(MainPanel, PANEL_SIGN2, Signe2);
607 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3);
608 SetCtrlVal(CalcN2Panel, CALCN2_N, N_2);
609 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2);
610 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
611 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring);
612 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling);
613 // Treat data
614
615 Math1 = mupEval(MathParser1) ;
616 SetCtrlVal(MainPanel,PANEL_MATH1, Math1) ;
617
618 Math2 = mupEval(MathParser2) ;
619 SetCtrlVal(MainPanel,PANEL_MATH2, Math2) ;
620
621 Math3 = mupEval(MathParser3) ;
622 SetCtrlVal(MainPanel,PANEL_MATH3, Math3) ;
623
624 Math4 = mupEval(MathParser4) ;
625 SetCtrlVal(MainPanel,PANEL_MATH4, Math4) ;
626
627 Math5 = mupEval(MathParser5) ;
628 SetCtrlVal(MainPanel,PANEL_MATH5, Math5) ;
629
630 // Plot Data and calculus if required
631
632 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1PLOT, &BoxChecked) ;
633 if (BoxChecked) {
634 Plot_AddFrequency(&PlotCh1, Ch1) ;
635 } 922 }
636 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1ALLAN, &BoxChecked) ; 923 }
637 if (BoxChecked) { 924 else {
638 Allan_AddFrequency(&AllanCh1, Ch1) ; 925 if (DDSBesChanged1==FALSE){
639 }
640
641 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2PLOT, &BoxChecked) ;
642 if (BoxChecked) {
643 Plot_AddFrequency(&PlotCh2, Ch2) ;
644 }
645 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2ALLAN, &BoxChecked) ;
646 if (BoxChecked) {
647 Allan_AddFrequency(&AllanCh2, Ch2) ;
648 }
649
650 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3PLOT, &BoxChecked) ;
651 if (BoxChecked) {
652 Plot_AddFrequency(&PlotCh3, Ch3) ;
653 }
654 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3ALLAN, &BoxChecked) ;
655 if (BoxChecked) {
656 Allan_AddFrequency(&AllanCh3, Ch3) ;
657 }
658
659 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4PLOT, &BoxChecked) ;
660 if (BoxChecked) {
661 Plot_AddFrequency(&PlotCh4, Ch4) ;
662 }
663 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4ALLAN, &BoxChecked) ;
664 if (BoxChecked) {
665 Allan_AddFrequency(&AllanCh4, Ch4) ;
666 }
667
668 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1PLOT, &BoxChecked) ;
669 if (BoxChecked) {
670 Plot_AddFrequency(&PlotMath1, Math1) ;
671 }
672 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1ALLAN, &BoxChecked) ;
673 if (BoxChecked) {
674 Allan_AddFrequency(&AllanMath1, Math1) ;
675 }
676
677 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2PLOT, &BoxChecked) ;
678 if (BoxChecked) {
679 Plot_AddFrequency(&PlotMath2, Math2) ;
680 }
681 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2ALLAN, &BoxChecked) ;
682 if (BoxChecked) {
683 Allan_AddFrequency(&AllanMath2, Math2) ;
684 }
685
686 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3PLOT, &BoxChecked) ;
687 if (BoxChecked) {
688 Plot_AddFrequency(&PlotMath3, Math3) ;
689 }
690 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3ALLAN, &BoxChecked) ;
691 if (BoxChecked) {
692 Allan_AddFrequency(&AllanMath3, Math3) ;
693 }
694
695 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4PLOT, &BoxChecked) ;
696 if (BoxChecked) {
697 Plot_AddFrequency(&PlotMath4, Math4) ;
698 }
699 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4ALLAN, &BoxChecked) ;
700 if (BoxChecked) {
701 Allan_AddFrequency(&AllanMath4, Math4) ;
702 }
703
704 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5PLOT, &BoxChecked) ;
705 if (BoxChecked) {
706 Plot_AddFrequency(&PlotMath5, Math5) ;
707 }
708 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked) ;
709 if (BoxChecked) {
710 Allan_AddFrequency(&AllanMath5, Math5) ;
711 }
712
713 // Calcul de N
714
715 switch (Measuring_1) {
716
717 case N_MEASUREMENT_NONE:
718 // not measuring
719 break;
720
721 case N_MEASUREMENT_INIT:
722 // initialization step
723 926
724 // set DDS1 to nominal frequency 927 if (nDDSChange<3)
725 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); 928 { nDDSChange=nDDSChange+1;}
726 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); 929
930 else
931 {
932 nDDSChange=0;
727 933
728 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit); 934 double DeltaFrep275 = 275000-Ch4;
729 t2_1 = t3_1 = 0.0; 935 double DeltaFrep10 = 10000-Ch2;
730 t1_1 = utc; 936 DeltaDDS3 = DeltaDDS3 + DeltaFrep10;
731 Frequ_slope_1 = Math1; 937 FrequencyDDSBes = FrequencyDDSBesInit + DeltaFrep275;
732 Moy_slope_1 = Frequ_slope_1; 938 FrequencyDDS3 = FrequencyDDS3Init + DeltaDDS3;
733 Ch4_slope = Ch4;
734 Moy_Ch4slope_1 = Ch4_slope;
735 N_slope_1 = 1;
736
737 // next step
738 Measuring_1 += 1;
739 break;
740
741 case N_MEASUREMENT_SLOPE:
742 // slope measurement
743
744 N_slope_1 = N_slope_1 + 1;
745 Frequ_slope_1 = Math1;
746 Ch4_slope = Ch4;
747 Moy_slope_1 = ((N_slope_1-1)*Moy_slope_1 + Frequ_slope_1)/N_slope_1;
748 Moy_Ch4slope_1 = ((N_slope_1-1)*Moy_Ch4slope_1 + Ch4_slope)/N_slope_1;
749 Slope_slope_1 = (Slope_slope_1*(N_slope_1-2) + 6*(Frequ_slope_1-Moy_slope_1)/N_slope_1)/(N_slope_1+1);
750 Slope_Ch4slope_1 = (Slope_Ch4slope_1*(N_slope_1-2) + 6*(Ch4_slope-Moy_Ch4slope_1)/N_slope_1)/(N_slope_1+1);
751
752 if ((utc - t1_1) > SlopeTime1) {
753 Slope_1 = Slope_slope_1;
754 Ch4Slope = Slope_Ch4slope_1;
755 SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1);
756 939
757 N_slope_1 = 0; 940 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes);
758 Frequ_slope_1 = 0.0; 941 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
759 Moy_slope_1 = 0.0; 942
760 Slope_slope_1 = 0.0; 943 Delay(0.1);
761 Ch4_slope = 0.0; 944 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3);
762 Moy_Ch4slope_1 = 0.0; 945 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
763 Slope_Ch4slope_1 = 0.0; 946
764 947 DDSBesChanged1=TRUE;
765 // frep positive step 948 t2_2=utc;
766 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv); 949
767 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_1*1000));
768 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_1*1000));
769
770 // allow counter to settle
771 settling = 3;
772
773 // next step
774 Measuring_1 += 1;
775 }
776 break;
777
778 case N_MEASUREMENT_ADJUST_FREQ_PLUS:
779 case N_MEASUREMENT_ADJUST_FREQ_MINUS:
780 // adjust DDS frequency to keep beatnote within the bandpass filter
781
782 if (settling > 0) {
783 settling--;
784 break;
785 } 950 }
786 951
787 double fDDS2; 952 }
788 GetCtrlVal(MainPanel, PANEL_DDS2, &fDDS2); 953 else{
789 fDDS2 += 275000 - Ch4;
790 SetCtrlVal(MainPanel, PANEL_DDS2, fDDS2);
791 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, fDDS2);
792 954
793 // allow counter to settle 955 if(Step3_2==FALSE){
794 settling = 3; 956 if (nstabilization<3)
795 957 {nstabilization= nstabilization+1;}
796 // next step 958 else
797 Measuring_1 += 1; 959 {
798 break; 960 if (utc-t2_2<DeltaT_2) {
799 961 Frepplus_2=Frepplus_2 +Math1+250000000-Slope_2*(utc-t2_2);
800 case N_MEASUREMENT_FREP_PLUS: 962 Delta10K_Plus= Delta10K_Plus + 10000 - (Ch2 -Beatslope_2*(utc-t2_2));
801 // frep positive step 963 n_2=n_2+1;
802 964 }
803 if (settling > 0) { 965 else
804 settling--; 966 {
805 break; 967 Frepplus_2=Frepplus_2/n_2;
968 Delta10K_Plus=Delta10K_Plus/n_2;
969 n_2=0;
970 Step3_2=TRUE;
971 nstabilization=0;
972 DDS4xAD9912_FrequencyRampe ( &DDS4xAD9912,1, (FrequDDS1+DeltakHz_2*1000),(FrequDDS1-DeltakHz_2*1000), Step2/Ndiv );
973 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_2*1000));
974 DDS4xAD9912_SetFrequency (&DDS4xAD9912,1, (FrequDDS1-DeltakHz_2*1000) );
975
976 Delay(0.1);
977 DeltaDDS3 = (FrequencyDDS3Init+DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1)) - FrequencyDDS3;
978 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3+DeltaDDS3);
979 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3, FrequencyDDS3+DeltaDDS3 );
980
981 }
982 }
806 } 983 }
807 984
808 if (t2_1 == 0.0)
809 t2_1 = utc;
810
811 Frepplus_1 = Frepplus_1 + Math1 - Slope_1 * (utc - t2_1);
812 Ch4Plus = Ch4Plus + Ch4 - Ch4Slope * (utc - t2_1);
813 n_1 += 1;
814
815 if ((utc - t2_1) > DeltaT_1) {
816 Frepplus_1 = Frepplus_1 / n_1;
817 Ch4Plus = Ch4Plus / n_1;
818 n_1 = 0;
819
820 // frep negative step
821 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, (FrequDDS1+DeltakHz_1*1000),(FrequDDS1-DeltakHz_1*1000), Step1/Ndiv);
822 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_1*1000));
823 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1-DeltakHz_1*1000));
824
825 // allow counter to settle
826 settling = 3;
827
828 // next step
829 Measuring_1 += 1;
830 }
831 break;
832
833 case N_MEASUREMENT_FREP_MINUS:
834 // frep negative step
835
836 if (settling > 0) {
837 settling--;
838 break;
839 }
840
841 if (t3_1 == 0.0)
842 t3_1 = utc;
843
844 Frepminus_1 = Frepminus_1 + Math1 - Slope_1 * (utc - t3_1);
845 Ch4Minus = Ch4Minus + Ch4 - Ch4Slope * (utc - t3_1);
846 n_1 += 1;
847
848 if ((utc - t3_1) > DeltaT_1) {
849 Frepminus_1 = Frepminus_1 / n_1;
850 Ch4Minus = Ch4Minus / n_1;
851 n_1 = 0;
852
853 // compute N1
854 N_1 = Signe1 * (2*Ndiv * DeltakHz_1 * 1000)/(Frepminus_1 - Frepplus_1 - Slope_1 * (t3_1 - t2_1));
855 SetCtrlVal(CalcN1Panel, CALCN1_N, N_1);
856
857 t1_1 = 0.0;
858 t2_1 = 0.0;
859 t3_1 = 0.0;
860 Frepminus_1 = 0.0;
861 Frepplus_1 = 0.0;
862
863 // back to nominal frep
864 DDS4xAD9912_FrequencyRampe(&DDS4xAD9912, 1, FrequDDS1-DeltakHz_1*1000,FrequDDS1, Step1/Ndiv );
865 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
866 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
867 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);
868 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
869
870 // done
871 Measuring_1 = N_MEASUREMENT_NONE;
872 }
873 break;
874 }
875
876 if (Measuring_2==TRUE)
877 {
878 if (Step1_2==FALSE) {
879 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
880 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
881
882 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit) ;
883 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init) ;
884 t1_2=utc;
885 Frequ_slope_2=Math1;
886 Beat_slope_2=Ch2;
887 Moy_slope_2= Frequ_slope_2;
888 Moy_Beatslope_2= Beat_slope_2;
889 N_slope_2=1;
890 Step1_2=TRUE ;
891 Nu1=(250000000+Math1)*N1;
892 }
893 else { 985 else {
894 if(Step2_2==FALSE){ 986 if (DDSBesChanged2==FALSE){
895 N_slope_2=N_slope_2+1; 987
896 Frequ_slope_2=Math1; 988 if (nDDSChange<3) {
897 Beat_slope_2=Ch2; 989 nDDSChange=nDDSChange+1;
898 Moy_slope_2=((N_slope_2-1)*Moy_slope_2 + Frequ_slope_2)/N_slope_2; 990 }
899 Moy_Beatslope_2=((N_slope_2-1)*Moy_Beatslope_2 + Beat_slope_2)/N_slope_2; 991 else
900 Slope_slope_2 = (Slope_slope_2*(N_slope_2-2) + 6*(Frequ_slope_2-Moy_slope_2)/N_slope_2)/(N_slope_2+1) ; 992 {
901 Slope_Beatslope_2 = (Slope_Beatslope_2*(N_slope_2-2) + 6*(Beat_slope_2-Moy_Beatslope_2)/N_slope_2)/(N_slope_2+1) ; 993 nDDSChange=0;
902 if (utc-t1_2>SlopeTime2) { 994
903 Slope_2 = Slope_slope_2; 995 double DeltaFrep275=275000-Ch4;
904 Beatslope_2 = Slope_Beatslope_2; 996 double DeltaFrep10=10000-Ch2;
905 Step2_2=TRUE ; 997 DeltaDDS3 = DeltaDDS3+(DeltaFrep10);
906 N_slope_2=0; 998 FrequencyDDSBes=FrequencyDDSBes+(DeltaFrep275);
907 Frequ_slope_2=0.0; 999 FrequencyDDS3=FrequencyDDS3+DeltaDDS3;
908 Moy_slope_2=0.0; 1000 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
909 Slope_slope_2 =0.0; 1001 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes);
910 Moy_Beatslope_2=0.0;
911 Slope_Beatslope_2 =0.0;
912 Beat_slope_2=0.0;
913 1002
914 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_2*1000), Step2/Ndiv ) ;
915 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_2*1000)) ;
916 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_2*1000));
917 Delay(0.1); 1003 Delay(0.1);
918 DeltaDDS3 = -DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2); 1004 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3);
919 SetCtrlVal(MainPanel, PANEL_DDS3, (FrequencyDDS3Init+DeltaDDS3)) ; 1005 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
920 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3,(FrequencyDDS3Init+DeltaDDS3)) ;
921 1006
922 } 1007 DDSBesChanged2=TRUE;
1008 t3_2=utc;
923 } 1009 }
924 else {
925 if (DDSBesChanged1==FALSE){
926
927 if (nDDSChange<3)
928 { nDDSChange=nDDSChange+1;}
929
930 else
931 {
932 nDDSChange=0;
933
934 double DeltaFrep275 = 275000-Ch4;
935 double DeltaFrep10 = 10000-Ch2;
936 DeltaDDS3 = DeltaDDS3 + DeltaFrep10;
937 FrequencyDDSBes = FrequencyDDSBesInit + DeltaFrep275;
938 FrequencyDDS3 = FrequencyDDS3Init + DeltaDDS3;
939
940 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ;
941 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
942
943 Delay(0.1);
944 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3) ;
945 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
946
947 DDSBesChanged1=TRUE;
948 t2_2=utc;
949
950 }
951
952 }
953 else{
954
955 if(Step3_2==FALSE){
956 if (nstabilization<3)
957 {nstabilization= nstabilization+1;}
958 else
959 {
960 if (utc-t2_2<DeltaT_2) {
961 Frepplus_2=Frepplus_2 +Math1+250000000-Slope_2*(utc-t2_2);
962 Delta10K_Plus= Delta10K_Plus + 10000 - (Ch2 -Beatslope_2*(utc-t2_2));
963 n_2=n_2+1;
964 }
965 else{
966 Frepplus_2=Frepplus_2/n_2;
967 Delta10K_Plus=Delta10K_Plus/n_2;
968 n_2=0;
969 Step3_2=TRUE ;
970 nstabilization=0;
971 DDS4xAD9912_FrequencyRampe ( &DDS4xAD9912,1, (FrequDDS1+DeltakHz_2*1000),(FrequDDS1-DeltakHz_2*1000), Step2/Ndiv ) ;
972 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_2*1000)) ;
973 DDS4xAD9912_SetFrequency (&DDS4xAD9912,1, (FrequDDS1-DeltakHz_2*1000) ) ;
974
975 Delay(0.1);
976 DeltaDDS3 = (FrequencyDDS3Init+DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1)) - FrequencyDDS3;
977 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3+DeltaDDS3) ;
978 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3, FrequencyDDS3+DeltaDDS3 ) ;
979
980 }
981 }
982 }
983
984 else {
985 if (DDSBesChanged2==FALSE){
986
987 if (nDDSChange<3)
988 { nDDSChange=nDDSChange+1;}
989
990 else
991 {
992 nDDSChange=0;
993
994
995 double DeltaFrep275=275000-Ch4;
996 double DeltaFrep10=10000-Ch2;
997 DeltaDDS3 = DeltaDDS3+(DeltaFrep10) ;
998 FrequencyDDSBes=FrequencyDDSBes+(DeltaFrep275) ;
999 FrequencyDDS3=FrequencyDDS3+DeltaDDS3 ;
1000 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
1001 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes);
1002
1003 Delay(0.1);
1004 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3) ;
1005 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
1006
1007 DDSBesChanged2=TRUE;
1008 t3_2=utc;
1009
1010
1011 }
1012 }
1013
1014 else{
1015 if (nstabilization<3)
1016 { nstabilization=nstabilization+1;}
1017 else
1018 {
1019 if (utc-t3_2<DeltaT_2) {
1020 Frepminus_2=Frepminus_2 +Math1+250000000-Slope_2*(utc-t3_2);
1021 Delta10K_Minus= Delta10K_Minus +10000 - ( Ch2 -Beatslope_2*(utc-t3_2));
1022 n_2=n_2+1;
1023 }
1024 else{
1025 Frepminus_2=Frepminus_2/(n_2);
1026 Delta10K_Minus= Delta10K_Minus/n_2;
1027 N_2 = (Signe2)*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2));
1028 n_2=0;
1029 Frepminus_2=0.0;
1030 Frepplus_2=0.0;
1031 Delta10K_Minus=0.0;
1032 Delta10K_Plus=0.0;
1033 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_2*1000,FrequDDS1, Step2/Ndiv ) ;
1034 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
1035 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1);
1036
1037 Delay(0.1);
1038
1039 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
1040 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit ) ;
1041
1042 Delay(0.1);
1043
1044 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2)) ;
1045 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2) ) ;
1046
1047 Measuring_2=FALSE ;
1048 Step1_2=FALSE ;
1049 Step2_2=FALSE ;
1050 Step3_2=FALSE ;
1051 t1_2=0.0;
1052 t2_2=0.0;
1053 t3_2=0.0;
1054 DDSBesChanged1=FALSE;
1055 DDSBesChanged2=FALSE;
1056 FrequencyDDSBes=0.0;
1057 nstabilization=0;
1058
1059 }
1060 }
1061 }
1062 }
1063 }
1064 }
1065 }
1066 }
1067
1068 switch (Measuring_3) {
1069
1070 case N_MEASUREMENT_STEP_0:
1071 // not measuring N3
1072 break;
1073
1074 case N_MEASUREMENT_STEP_1: // init
1075
1076 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1077 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1078 settling = 3;
1079
1080 t1_3 = utc;
1081 N_slope_3 = 0;
1082 // record current DDS3 frequency
1083 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
1084
1085 // step 1 done
1086 Measuring_3 = N_MEASUREMENT_STEP_2;
1087 break;
1088
1089 case N_MEASUREMENT_STEP_2: // slope measurement
1090
1091 if (settling > 0) {
1092 settling--;
1093 break;
1094 }
1095
1096 N_slope_3++;
1097 Frequ_slope_3 = Ch2;
1098 Moy_slope_3 = ((N_slope_3-1)*Moy_slope_3 + Frequ_slope_3)/N_slope_3;
1099 Slope_slope_3 = (Slope_slope_3*(N_slope_3-2) + 6*(Frequ_slope_3-Moy_slope_3)/N_slope_3)/(N_slope_3+1) ;
1100
1101 if (utc - t1_3 > SlopeTime3) {
1102 // slope measurement
1103 Slope_3 = Slope_slope_3;
1104
1105 t2_3 = utc;
1106 N_slope_3 = 0;
1107 Frequ_slope_3 = 0.0;
1108 Moy_slope_3 = 0.0;
1109 Slope_slope_3 = 0.0;
1110
1111 // step 2 done
1112 Measuring_3 = N_MEASUREMENT_STEP_3;
1113
1114 // frep positive step
1115 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
1116 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000);
1117 // compensate with DDS3 to keep measured beatnote in counter box range
1118 double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3 * 1000;
1119 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1120 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1121 // allow counter to settle
1122 settling = 3;
1123 }
1124 break;
1125
1126 case N_MEASUREMENT_STEP_3: // frep positive step
1127
1128 if (settling > 0) {
1129 settling--;
1130 break;
1131 }
1132
1133 n_3++;
1134 Frepplus_3 += Ch2 - Slope_3 * (utc - t2_3);
1135
1136 if (utc - t2_3 > DeltaT_3) {
1137 // positive step measurement
1138 Frepplus_3 = Frepplus_3 / n_3;
1139
1140 n_3 = 0;
1141 t3_3 = utc;
1142
1143 // step 3 done
1144 Measuring_3 = N_MEASUREMENT_STEP_4;
1145
1146 // frep negative step
1147 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000);
1148 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000);
1149 // compensate with DDS3 to keep measured beatnote in counter box range
1150 double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3 * 1000;
1151 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1152 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1153 // allow counter to settle
1154 settling = 3;
1155 }
1156 break;
1157
1158
1159 case N_MEASUREMENT_STEP_4: // frep negative step
1160
1161 if (settling > 0) {
1162 settling--;
1163 break;
1164 }
1165
1166 n_3++;
1167 Frepminus_3 += Ch2 - Slope_3 * (utc - t3_3);
1168
1169 if (utc - t3_3 > DeltaT_3) {
1170 // positive step measurement
1171 Frepminus_3 = Frepminus_3 / n_3;
1172
1173 // compute N3
1174 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000));
1175 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3);
1176
1177 t1_3=0.0;
1178 t2_3=0.0;
1179 t3_3=0.0;
1180 n_3 = 0;
1181 Frepminus_3 = 0.0;
1182 Frepplus_3 = 0.0;
1183
1184 // step 4 done
1185 Measuring_3 = N_MEASUREMENT_STEP_0;
1186
1187 // back to nominal frep
1188 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1189 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1190 // back to initial DDS3 frequency
1191 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init);
1192 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
1193 }
1194 break;
1195 }
1196
1197 // Calcul du signe de fb
1198
1199 if (Getsign1 == TRUE) {
1200 if (utc > tbegin1+2) {
1201 if (Math1 > Frepbefore1)
1202 Signe1 = -1.0;
1203 else
1204 Signe1 = +1.0;
1205 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1) ;
1206 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1);
1207 Getsign1 = FALSE;
1208 }
1209 }
1210 if (Getsign2 == TRUE) {
1211 if (utc > tbegin2+2){
1212 if (Math1 > Frepbefore2) {
1213 if (Ch2 > Ch2before)
1214 Signe2 = +1.0;
1215 else
1216 Signe2 = -1.0;
1217 } else {
1218 if (Ch2 > Ch2before)
1219 Signe2 = -1.0;
1220 else
1221 Signe2 = +1.0;
1222 }
1223 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2) ;
1224 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2);
1225 Getsign2 = FALSE;
1226 }
1227 }
1228 if (Getsign3 == TRUE) {
1229 if (utc > tbegin3+2){
1230 if (Ch3 > Frepbefore3)
1231 Signe3 = -1.0;
1232 else
1233 Signe3 = +1.0;
1234 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3) ;
1235 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3);
1236 Getsign3 = FALSE;
1237 }
1238 }
1239
1240 // slope cancelling
1241 if (SlopeMeasuring == TRUE)
1242 {
1243 double currentFreq = 0.0;
1244
1245 // select reference
1246 switch (slopeReference) {
1247 case SLOPE_REFERENCE_MICROWAVE:
1248 currentFreq = Math2;
1249 break;
1250 case SLOPE_REFERENCE_HG_CAVITY:
1251 currentFreq = Ch2 * 1542.2 / 1062.5;
1252 break;
1253 }
1254
1255 if (utc-SlopeMeasuringTimeBegin > TimetoSlope)
1256 {
1257 Nratio = Nratio + 1;
1258
1259 if (Nratio >= 1) {
1260 MoyMath2 = MoyMath2 + Moy_Math2slope;
1261 }
1262
1263 if (invertSlopeSign) {
1264 SlopeMath2 = SlopeMath2 - Slope_Math2slope;
1265 } else {
1266 SlopeMath2 = SlopeMath2 + Slope_Math2slope;
1267 }
1268
1269 N_Math2slope = 0.0;
1270 Math2_slope = 0.0;
1271 Moy_Math2slope = 0.0;
1272 Slope_Math2slope = 0.0;
1273
1274 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE)
1275 {
1276 CenterFrequencyCh2 = MoyMath2;
1277 CenterFrequencyCh2ToDetermine = FALSE;
1278 }
1279
1280 OnSlopeCancelling = TRUE;
1281
1282 if (Nratio == ratio)
1283 {
1284 if (FrequCorrec == TRUE)
1285 {
1286 SlopeCorrection = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope;
1287 SlopeMath2 = SlopeMath2 + SlopeCorrection;
1288 }
1289 Nratio = 0;
1290 MoyMath2 = 0.0;
1291 }
1292
1293 FoxFrequ = DDSFox_ReadFreq(&DDS1xAD9956);
1294 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
1295 DDSFox_Set(&DDS1xAD9956, FoxFrequ, SlopeMath2);
1296
1297 nstabilisationSlopeMeasuring = 0;
1298 SlopeMeasuringTimeBegin = utc;
1299
1300 }
1301 else
1302 {
1303 if (nstabilisationSlopeMeasuring < 5)
1304 {
1305 nstabilisationSlopeMeasuring = nstabilisationSlopeMeasuring + 1;
1306 Math2_slope = currentFreq;
1307 }
1308 else
1309 {
1310 if ((currentFreq-Math2_slope) < limitotakoff && (currentFreq-Math2_slope) > -limitotakoff)
1311 {
1312 N_Math2slope = N_Math2slope + 1;
1313 Math2_slope = currentFreq;
1314 Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope;
1315 Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1) ;
1316 } 1010 }
1317 else 1011 else
1318 { 1012 {
1319 if (AutoStopSlopeCancellingIfDelock) { 1013 if (nstabilization<3) {
1320 // stop slope cancelling if the comb is not locked 1014 nstabilization=nstabilization+1;
1321 1015 }
1322 double frequency = DEDRIFT_DDS_FREQUENCY; 1016 else
1323 if (KeepFrequ) 1017 {
1324 frequency = DDSFox_ReadFreq(&DDS1xAD9956); 1018 if (utc-t3_2<DeltaT_2) {
1019 Frepminus_2=Frepminus_2 +Math1+250000000-Slope_2*(utc-t3_2);
1020 Delta10K_Minus= Delta10K_Minus +10000 - ( Ch2 -Beatslope_2*(utc-t3_2));
1021 n_2=n_2+1;
1022 }
1023 else
1024 {
1025 Frepminus_2=Frepminus_2/(n_2);
1026 Delta10K_Minus= Delta10K_Minus/n_2;
1027 N_2 = (Signe2)*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2));
1028 n_2=0;
1029 Frepminus_2=0.0;
1030 Frepplus_2=0.0;
1031 Delta10K_Minus=0.0;
1032 Delta10K_Plus=0.0;
1033 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_2*1000,FrequDDS1, Step2/Ndiv );
1034 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1);
1035 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1);
1325 1036
1326 if (! KeepSlope) { 1037 Delay(0.1);
1327 SlopeMath2 = 0.0; 1038
1328 OnSlopeCancelling = FALSE; 1039 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit);
1040 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit );
1041
1042 Delay(0.1);
1043
1044 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2));
1045 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2) );
1046
1047 Measuring_2=FALSE;
1048 Step1_2=FALSE;
1049 Step2_2=FALSE;
1050 Step3_2=FALSE;
1051 t1_2=0.0;
1052 t2_2=0.0;
1053 t3_2=0.0;
1054 DDSBesChanged1=FALSE;
1055 DDSBesChanged2=FALSE;
1056 FrequencyDDSBes=0.0;
1057 nstabilization=0;
1058
1329 } 1059 }
1330
1331 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
1332 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2);
1333
1334 SlopeMeasuring = FALSE;
1335 N_Math2slope = 0.0;
1336 Math2_slope = 0.0;
1337 MoyMath2 = 0.0;
1338 Moy_Math2slope = 0.0;
1339 Slope_Math2slope = 0.0;
1340 CenterFrequencyCh2 = 0.0;
1341 CenterFrequencyCh2ToDetermine = TRUE;
1342 Nratio = -1;
1343 nstabilisationSlopeMeasuring = 0;
1344
1345 SetCtrlVal(MainPanel, PANEL_STARTCANCEL, 0);
1346 } 1060 }
1347 } 1061 }
1348 } 1062 }
1349 } 1063 }
1350 } 1064 }
1351 1065 }
1352 // re-centering 1066 }
1353 if (KeepCentering) 1067
1068 switch (Measuring_3) {
1069
1070 case N_MEASUREMENT_STEP_0:
1071 // not measuring N3
1072 break;
1073
1074 case N_MEASUREMENT_STEP_1:
1075 // init
1076
1077 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1078 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1079 settling = 3;
1080
1081 t1_3 = utc;
1082 N_slope_3 = 0;
1083 // record current DDS3 frequency
1084 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
1085
1086 // step 1 done
1087 Measuring_3 = N_MEASUREMENT_STEP_2;
1088 break;
1089
1090 case N_MEASUREMENT_STEP_2:
1091 // slope measurement
1092
1093 if (settling > 0) {
1094 settling--;
1095 break;
1096 }
1097
1098 N_slope_3++;
1099 Frequ_slope_3 = Ch2;
1100 Moy_slope_3 = ((N_slope_3-1)*Moy_slope_3 + Frequ_slope_3)/N_slope_3;
1101 Slope_slope_3 = (Slope_slope_3*(N_slope_3-2) + 6*(Frequ_slope_3-Moy_slope_3)/N_slope_3)/(N_slope_3+1);
1102
1103 if (utc - t1_3 > SlopeTime3) {
1104 // slope measurement
1105 Slope_3 = Slope_slope_3;
1106
1107 t2_3 = utc;
1108 N_slope_3 = 0;
1109 Frequ_slope_3 = 0.0;
1110 Moy_slope_3 = 0.0;
1111 Slope_slope_3 = 0.0;
1112
1113 // step 2 done
1114 Measuring_3 = N_MEASUREMENT_STEP_3;
1115
1116 // frep positive step
1117 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
1118 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000);
1119 // compensate with DDS3 to keep measured beatnote in counter box range
1120 double fDDS3 = FrequencyDDS3Init + N3/N1 * Ndiv * DeltakHz_3 * 1000;
1121 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1122 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1123 // allow counter to settle
1124 settling = 3;
1125 }
1126 break;
1127
1128 case N_MEASUREMENT_STEP_3:
1129 // frep positive step
1130
1131 if (settling > 0) {
1132 settling--;
1133 break;
1134 }
1135
1136 n_3++;
1137 Frepplus_3 += Ch2 - Slope_3 * (utc - t2_3);
1138
1139 if (utc - t2_3 > DeltaT_3) {
1140 // positive step measurement
1141 Frepplus_3 = Frepplus_3 / n_3;
1142
1143 n_3 = 0;
1144 t3_3 = utc;
1145
1146 // step 3 done
1147 Measuring_3 = N_MEASUREMENT_STEP_4;
1148
1149 // frep negative step
1150 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000);
1151 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000);
1152 // compensate with DDS3 to keep measured beatnote in counter box range
1153 double fDDS3 = FrequencyDDS3Init - N3/N1 * Ndiv * DeltakHz_3 * 1000;
1154 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1155 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1156 // allow counter to settle
1157 settling = 3;
1158 }
1159 break;
1160
1161
1162 case N_MEASUREMENT_STEP_4:
1163 // frep negative step
1164
1165 if (settling > 0) {
1166 settling--;
1167 break;
1168 }
1169
1170 n_3++;
1171 Frepminus_3 += Ch2 - Slope_3 * (utc - t3_3);
1172
1173 if (utc - t3_3 > DeltaT_3) {
1174 // positive step measurement
1175 Frepminus_3 = Frepminus_3 / n_3;
1176
1177 // compute N3
1178 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000));
1179 SetCtrlVal(CalcN3Panel, CALCN3_N, N_3);
1180
1181 t1_3=0.0;
1182 t2_3=0.0;
1183 t3_3=0.0;
1184 n_3 = 0;
1185 Frepminus_3 = 0.0;
1186 Frepplus_3 = 0.0;
1187
1188 // step 4 done
1189 Measuring_3 = N_MEASUREMENT_STEP_0;
1190
1191 // back to nominal frep
1192 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1193 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1194 // back to initial DDS3 frequency
1195 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init);
1196 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
1197 }
1198 break;
1199 }
1200
1201 // Calcul du signe de fb
1202
1203 if (Getsign1 == TRUE) {
1204 if (utc > tbegin1+2) {
1205 if (Math1 > Frepbefore1)
1206 Signe1 = -1.0;
1207 else
1208 Signe1 = +1.0;
1209 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1);
1210 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1);
1211 Getsign1 = FALSE;
1212 }
1213 }
1214 if (Getsign2 == TRUE) {
1215 if (utc > tbegin2+2){
1216 if (Math1 > Frepbefore2) {
1217 if (Ch2 > Ch2before)
1218 Signe2 = +1.0;
1219 else
1220 Signe2 = -1.0;
1221 } else {
1222 if (Ch2 > Ch2before)
1223 Signe2 = -1.0;
1224 else
1225 Signe2 = +1.0;
1226 }
1227 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2);
1228 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2);
1229 Getsign2 = FALSE;
1230 }
1231 }
1232 if (Getsign3 == TRUE) {
1233 if (utc > tbegin3+2){
1234 if (Ch3 > Frepbefore3)
1235 Signe3 = -1.0;
1236 else
1237 Signe3 = +1.0;
1238 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3);
1239 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3);
1240 Getsign3 = FALSE;
1241 }
1242 }
1243
1244 // slope cancelling
1245 if (SlopeMeasuring == TRUE)
1246 {
1247 double currentFreq = 0.0;
1248
1249 // select reference
1250 switch (slopeReference) {
1251 case SLOPE_REFERENCE_MICROWAVE:
1252 currentFreq = Math2;
1253 break;
1254 case SLOPE_REFERENCE_HG_CAVITY:
1255 currentFreq = Ch2 * 1542.2 / 1062.5;
1256 break;
1257 }
1258
1259 if (utc-SlopeMeasuringTimeBegin > TimetoSlope)
1260 {
1261 Nratio = Nratio + 1;
1262
1263 if (Nratio >= 1) {
1264 MoyMath2 = MoyMath2 + Moy_Math2slope;
1265 }
1266
1267 if (invertSlopeSign) {
1268 SlopeMath2 = SlopeMath2 - Slope_Math2slope;
1269 } else {
1270 SlopeMath2 = SlopeMath2 + Slope_Math2slope;
1271 }
1272
1273 N_Math2slope = 0.0;
1274 Math2_slope = 0.0;
1275 Moy_Math2slope = 0.0;
1276 Slope_Math2slope = 0.0;
1277
1278 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE)
1354 { 1279 {
1355 1280 CenterFrequencyCh2 = MoyMath2;
1356 DeltaCh4=275000-Ch4; 1281 CenterFrequencyCh2ToDetermine = FALSE;
1357 DeltaCh2=10000-Ch2; 1282 }
1358 1283
1359 if (utc- CenteringTimeBegin275K > Timetorecenter275K && CenteringTimeBegin275K>10) 1284 OnSlopeCancelling = TRUE;
1285
1286 if (Nratio == ratio)
1287 {
1288 if (FrequCorrec == TRUE)
1360 { 1289 {
1361 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyToChange) ; 1290 SlopeCorrection = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope;
1362 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyToChange+DeltaCh4) ; 1291 SlopeMath2 = SlopeMath2 + SlopeCorrection;
1363 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyToChange+DeltaCh4);
1364 CenteringTimeBegin275K=utc;
1365
1366
1367 } 1292 }
1368 1293 Nratio = 0;
1369 if (utc- CenteringTimeBegin10K > Timetorecenter10K && CenteringTimeBegin10K>10) 1294 MoyMath2 = 0.0;
1295 }
1296
1297 FoxFrequ = DDSFox_ReadFreq(&DDS1xAD9956);
1298 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
1299 DDSFox_Set(&DDS1xAD9956, FoxFrequ, SlopeMath2);
1300
1301 nstabilisationSlopeMeasuring = 0;
1302 SlopeMeasuringTimeBegin = utc;
1303
1304 }
1305 else
1306 {
1307 if (nstabilisationSlopeMeasuring < 5)
1308 {
1309 nstabilisationSlopeMeasuring = nstabilisationSlopeMeasuring + 1;
1310 Math2_slope = currentFreq;
1311 }
1312 else
1313 {
1314 if ((currentFreq-Math2_slope) < limitotakoff && (currentFreq-Math2_slope) > -limitotakoff)
1370 { 1315 {
1371 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyToChange) ; 1316 N_Math2slope = N_Math2slope + 1;
1372 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyToChange+DeltaCh2) ; 1317 Math2_slope = currentFreq;
1373 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyToChange+DeltaCh2); 1318 Moy_Math2slope = ((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope;
1374 CenteringTimeBegin10K=utc; 1319 Slope_Math2slope = (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1);
1375
1376
1377 } 1320 }
1378 1321 else
1379 1322 {
1323 if (AutoStopSlopeCancellingIfDelock) {
1324 // stop slope cancelling if the comb is not locked
1325
1326 double frequency = DEDRIFT_DDS_FREQUENCY;
1327 if (KeepFrequ)
1328 frequency = DDSFox_ReadFreq(&DDS1xAD9956);
1329
1330 if (! KeepSlope) {
1331 SlopeMath2 = 0.0;
1332 OnSlopeCancelling = FALSE;
1333 }
1334
1335 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
1336 DDSFox_Set(&DDS1xAD9956, frequency, SlopeMath2);
1337
1338 SlopeMeasuring = FALSE;
1339 N_Math2slope = 0.0;
1340 Math2_slope = 0.0;
1341 MoyMath2 = 0.0;
1342 Moy_Math2slope = 0.0;
1343 Slope_Math2slope = 0.0;
1344 CenterFrequencyCh2 = 0.0;
1345 CenterFrequencyCh2ToDetermine = TRUE;
1346 Nratio = -1;
1347 nstabilisationSlopeMeasuring = 0;
1348
1349 SetCtrlVal(MainPanel, PANEL_STARTCANCEL, 0);
1350 }
1351 }
1380 } 1352 }
1381 1353 }
1382 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, &BoxChecked) ; // AutoSave OL 1354 }
1383 if (BoxChecked) { 1355
1384 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before 1356 // re-centering
1385 } 1357 if (KeepCentering)
1386 1358 {
1387 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked) ; // Save OL (Math2)
1388 if (BoxChecked) {
1389 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1390 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1391 WriteLine(FileOpt, ReportString, -1) ;
1392 CloseFile(FileOpt) ;
1393 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; // a local backup for debugging
1394 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1395 WriteLine(FileOpt, ReportString, -1) ;
1396 CloseFile(FileOpt) ;
1397 }
1398
1399 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, &BoxChecked) ; // AutoSave Hg (Math3)
1400 if (BoxChecked) {
1401 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1402 }
1403
1404 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked) ; // Save Hg
1405
1406 if (BoxChecked) {
1407 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1408 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1409 WriteLine(FileHg, ReportString, -1) ;
1410 CloseFile(FileHg) ;
1411 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1412 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1413 WriteLine(FileHg, ReportString, -1) ;
1414 CloseFile(FileHg) ;
1415 }
1416
1417 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked) ; // Save ExtraMath (Math5)
1418 if (BoxChecked) {
1419 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1420 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5);
1421 WriteLine(FileExtraMath, ReportString, -1) ;
1422 CloseFile(FileExtraMath) ;
1423 }
1424
1425 // Special case to handle change of day at next second
1426 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) {
1427 Acquiring = FALSE ;
1428 do {
1429 Delay(5.1);
1430 CurrentFileName(LogFileName) ;
1431 } while (!GetFileInfo(LogFileName, &OldLogFilePtr));
1432 Acquiring = TRUE ;
1433 OldLogFilePtr = 2;
1434 }
1435
1436 ResumeTimerCallbacks() ;
1437
1438 } ;
1439 1359
1440 break; 1360 DeltaCh4=275000-Ch4;
1441 case FALSE: 1361 DeltaCh2=10000-Ch2;
1442 break; 1362
1443 } 1363 if (utc- CenteringTimeBegin275K > Timetorecenter275K && CenteringTimeBegin275K>10)
1444 break; 1364 {
1445 } 1365 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyToChange);
1446 return 0; 1366 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyToChange+DeltaCh4);
1447 } 1367 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyToChange+DeltaCh4);
1448 1368 CenteringTimeBegin275K=utc;
1449 1369 }
1370
1371 if (utc- CenteringTimeBegin10K > Timetorecenter10K && CenteringTimeBegin10K>10)
1372 {
1373 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyToChange);
1374 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyToChange+DeltaCh2);
1375 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyToChange+DeltaCh2);
1376 CenteringTimeBegin10K=utc;
1377 }
1378 }
1379
1380 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, &BoxChecked); // AutoSave OL
1381 if (BoxChecked) {
1382 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, TRUE); // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1383 }
1384
1385 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked); // Save OL (Math2)
1386 if (BoxChecked) {
1387 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
1388 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1389 WriteLine(FileOpt, ReportString, -1);
1390 CloseFile(FileOpt);
1391 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII); // a local backup for debugging
1392 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1393 WriteLine(FileOpt, ReportString, -1);
1394 CloseFile(FileOpt);
1395 }
1396
1397 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, &BoxChecked); // AutoSave Hg (Math3)
1398 if (BoxChecked) {
1399 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, TRUE); // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1400 }
1401
1402 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked); // Save Hg
1403
1404 if (BoxChecked) {
1405 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
1406 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1407 WriteLine(FileHg, ReportString, -1);
1408 CloseFile(FileHg);
1409 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
1410 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1411 WriteLine(FileHg, ReportString, -1);
1412 CloseFile(FileHg);
1413 }
1414
1415 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked); // Save ExtraMath (Math5)
1416 if (BoxChecked) {
1417 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII);
1418 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5);
1419 WriteLine(FileExtraMath, ReportString, -1);
1420 CloseFile(FileExtraMath);
1421 }
1422
1423 // Special case to handle change of day at next second
1424 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) {
1425 Acquiring = FALSE;
1426 do {
1427 Delay(5.1);
1428 CurrentFileName(LogFileName);
1429 } while (!GetFileInfo(LogFileName, &OldLogFilePtr));
1430 Acquiring = TRUE;
1431 OldLogFilePtr = 2;
1432 }
1433
1434 ResumeTimerCallbacks();
1435
1436 }
1437 break;
1438 }
1439 return 0;
1440 }
1450 1441
1451 1442
1452 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event, 1443 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event,
1453 void *callbackData, int eventData1, int eventData2) 1444 void *callbackData, int eventData1, int eventData2)
1454 { 1445 {