00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TN
00019 #define TN
00020 namespace SPUC {
00021 #define MAX_STEP 4
00022 #define STEP_BITS 3
00023 #define MASK_HI 65535
00024 #define MASK_HIx 63535
00025 #define MASK_LO 65536
00026 #define MASK_LOd2 32768
00027 #define BITS_USED 16
00032 //
00036 class timing_nco
00037 {
00038 protected:
00039 signed long resid1;
00040 signed long acc;
00041 unsigned long fcw;
00042 unsigned long new_fcw;
00043 signed long phase1;
00044 signed long phase2;
00045 signed long new_phase;
00046 long sample2;
00047 public:
00048 inline timing_nco(void) {
00049 resid1 = 0;
00050 acc = MASK_LOd2;
00051 fcw = new_fcw = phase1 = phase2 = 0;
00052 sample2 = 1;}
00053 inline void set_frequency(unsigned long freq) { fcw = freq; }
00054 inline void reset_frequency(unsigned long freq) { new_fcw = fcw = freq; }
00055 inline double get_off1(void) { return((double)phase1/MASK_LO);}
00056 inline double get_off2(void) { return((double)phase2/MASK_LO);}
00057 inline long get_phase1(void) { return(-MAX_STEP+phase1);}
00058 inline long get_phase2(void) { return(-MAX_STEP+phase2);}
00059 long run(long loop_filter_out=0, int load=1);
00060 signed long residual_phase(signed long acc_value);
00061 };
00062 #endif
00063 }