⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_flexrf.py

📁 这是用python语言写的一个数字广播的信号处理工具包。利用它
💻 PY
📖 第 1 页 / 共 2 页
字号:
        if gain > maxgain:            pga_gain = gain-maxgain            assert pga_gain <= self._u.pga_max()            agc_gain = maxgain        else:            pga_gain = 0            agc_gain = gain        V_maxgain = .2        V_mingain = 1.2        V_fullscale = 3.3        dac_value = (agc_gain*(V_maxgain-V_mingain)/(maxgain-mingain) + V_mingain)*4096/V_fullscale        assert dac_value>=0 and dac_value<4096        return self._u.write_aux_dac(self._which, 0, int(dac_value)) and \               self._set_pga(int(pga_gain))# ----------------------------------------------------------------class _AD4360_common(object):    def __init__(self):        # R-Register Common Values        self.R_RSV = 0   # bits 23,22        self.BSC = 3   # bits 21,20 Div by 8 to be safe        self.TEST = 0  # bit 19        self.LDP = 1   # bit 18        self.ABP = 0   # bit 17,16   3ns        # N-Register Common Values        self.N_RSV = 0      # bit 7                # Control Register Common Values        self.PD = 0       # bits 21,20   Normal operation        self.PL = 0       # bits 13,12   11mA        self.MTLD = 1     # bit 11       enabled        self.CPG = 0      # bit 10       CP setting 1        self.CP3S = 0     # bit 9        Normal        self.PDP = 1      # bit 8        Positive        self.MUXOUT = 1   # bits 7:5     Digital Lock Detect        self.CR = 0       # bit 4        Normal        self.PC = 1       # bits 3,2     Core power 10mA    def _compute_regs(self, freq):        """        Determine values of R, control, and N registers, along with actual freq.                @param freq: target frequency in Hz        @type freq: float        @returns: (R, control, N, actual_freq)        @rtype: tuple(int, int, int, float)        """        #  Band-specific N-Register Values        phdet_freq = self._refclk_freq()/self.R_DIV        desired_n = round(freq*self.freq_mult/phdet_freq)        actual_freq = desired_n * phdet_freq        B = math.floor(desired_n/self._prescaler())        A = desired_n - self._prescaler()*B        self.B_DIV = int(B)    # bits 20:8        self.A_DIV = int(A)    # bit 6:2        #assert self.B_DIV >= self.A_DIV        if self.B_DIV < self.A_DIV:            return (0,0,0,0)        R = (self.R_RSV<<22) | (self.BSC<<20) | (self.TEST<<19) | (self.LDP<<18) \            | (self.ABP<<16) | (self.R_DIV<<2)                control = self._compute_control_reg()        N = (self.DIVSEL<<23) | (self.DIV2<<22) | (self.CPGAIN<<21) | (self.B_DIV<<8) | \            (self.N_RSV<<7) | (self.A_DIV<<2)        return (R,control,N,actual_freq/self.freq_mult)    def _compute_control_reg(self):        control = (self.P<<22) | (self.PD<<20) | (self.CP2<<17) | (self.CP1<<14) | (self.PL<<12) \                  | (self.MTLD<<11) | (self.CPG<<10) | (self.CP3S<<9) | (self.PDP<<8) | \                  (self.MUXOUT<<5) | (self.CR<<4) | (self.PC<<2)	return control        def _refclk_divisor(self):        """        Return value to stick in REFCLK_DIVISOR register        """        return 1        def _prescaler(self):        if self.P == 0:            return 8        elif self.P == 1:            return 16        else:            return 32#----------------------------------------------------------------------class _2400_common(_AD4360_common):    def __init__(self):        _AD4360_common.__init__(self)        # Band-specific R-Register Values        self.R_DIV = 16  # bits 15:2           # Band-specific C-Register values        self.P = 1        # bits 23,22   Div by 16/17        self.CP2 = 7      # bits 19:17        self.CP1 = 7      # bits 16:14        # Band specifc N-Register Values        self.DIVSEL = 0   # bit 23        self.DIV2 = 0     # bit 22        self.CPGAIN = 0   # bit 21        self.freq_mult = 1    def freq_range(self):           # FIXME        return (2300e6, 2700e6, 4e6)#----------------------------------------------------------------------class _1200_common(_AD4360_common):    def __init__(self):        _AD4360_common.__init__(self)        # Band-specific R-Register Values        self.R_DIV = 16  # bits 15:2  DIV by 16 for a 1 MHz phase detector freq           # Band-specific C-Register values        self.P = 1        # bits 23,22   Div by 16/17        self.CP2 = 7      # bits 19:17   1.25 mA        self.CP1 = 7      # bits 16:14   1.25 mA        # Band specifc N-Register Values        self.DIVSEL = 0   # bit 23        self.DIV2 = 1     # bit 22        self.CPGAIN = 0   # bit 21        self.freq_mult = 2    def freq_range(self):           # FIXME        return (1150e6, 1350e6, 4e6)#-------------------------------------------------------------------------class _1800_common(_AD4360_common):    def __init__(self):        _AD4360_common.__init__(self)        # Band-specific R-Register Values        self.R_DIV = 16  # bits 15:2  DIV by 16 for a 1 MHz phase detector freq           # Band-specific C-Register values        self.P = 1        # bits 23,22   Div by 16/17        self.CP2 = 7      # bits 19:17   1.25 mA        self.CP1 = 7      # bits 16:14   1.25 mA        # Band specifc N-Register Values        self.DIVSEL = 0   # bit 23        self.DIV2 = 0     # bit 22        self.freq_mult = 1        self.CPGAIN = 0   # bit 21    def freq_range(self):           # FIXME        return (1600e6, 2000e6, 4e6)#-------------------------------------------------------------------------class _900_common(_AD4360_common):    def __init__(self):        _AD4360_common.__init__(self)        # Band-specific R-Register Values        self.R_DIV = 16  # bits 15:2  DIV by 16 for a 1 MHz phase detector freq           # Band-specific C-Register values        self.P = 1        # bits 23,22   Div by 16/17        self.CP2 = 7      # bits 19:17   1.25 mA        self.CP1 = 7      # bits 16:14   1.25 mA        # Band specifc N-Register Values        self.DIVSEL = 0   # bit 23        self.DIV2 = 1     # bit 22        self.freq_mult = 2        self.CPGAIN = 0   # bit 21    def freq_range(self):           # FIXME        return (800e6, 1000e6, 4e6)#-------------------------------------------------------------------------class _400_common(_AD4360_common):    def __init__(self):        _AD4360_common.__init__(self)        # Band-specific R-Register Values        self.R_DIV = 16  # bits 15:2            # Band-specific C-Register values        self.P = 0        # bits 23,22   Div by 8/9        self.CP2 = 7      # bits 19:17   1.25 mA        self.CP1 = 7      # bits 16:14   1.25 mA        # Band specifc N-Register Values  These are different for TX/RX        self.DIVSEL = 0   # bit 23        if self._tx:            self.DIV2 = 1 # bit 22        else:            self.DIV2 = 0 # bit 22   # RX side has built-in DIV2 in AD8348        self.freq_mult = 2        self.CPGAIN = 0   # bit 21    def freq_range(self):                   #return (350e6, 465e6, 1e6)    # FIXME prototype        return (400e6, 500e6, 1e6)     # final version    #------------------------------------------------------------    class db_flexrf_2400_tx(_2400_common, flexrf_base_tx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_tx.__init__(self, usrp, which)        _2400_common.__init__(self)        class db_flexrf_2400_rx(_2400_common, flexrf_base_rx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0   # Powering it off kills the serial bus        flexrf_base_rx.__init__(self, usrp, which)        _2400_common.__init__(self)    def gain_range(self):        """        Return range of gain that can be set by this d'board.                @returns (min_gain, max_gain, step_size)        Where gains are expressed in decibels (your mileage may vary)        """        return (self._u.pga_min(), self._u.pga_max() + 70, 0.05)    def i_and_q_swapped(self):        return Trueclass db_flexrf_1200_tx(_1200_common, flexrf_base_tx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_tx.__init__(self, usrp, which)        _1200_common.__init__(self)        class db_flexrf_1200_rx(_1200_common, flexrf_base_rx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_rx.__init__(self, usrp, which)        _1200_common.__init__(self)    def gain_range(self):        """        Return range of gain that can be set by this d'board.                @returns (min_gain, max_gain, step_size)        Where gains are expressed in decibels (your mileage may vary)        """        return (self._u.pga_min(), self._u.pga_max() + 70, 0.05)    def i_and_q_swapped(self):        return Trueclass db_flexrf_1800_tx(_1800_common, flexrf_base_tx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_tx.__init__(self, usrp, which)        _1800_common.__init__(self)        class db_flexrf_1800_rx(_1800_common, flexrf_base_rx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_rx.__init__(self, usrp, which)        _1800_common.__init__(self)    def gain_range(self):        """        Return range of gain that can be set by this d'board.                @returns (min_gain, max_gain, step_size)        Where gains are expressed in decibels (your mileage may vary)        """        return (self._u.pga_min(), self._u.pga_max() + 70, 0.05)    def i_and_q_swapped(self):        return Trueclass db_flexrf_900_tx(_900_common, flexrf_base_tx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_tx.__init__(self, usrp, which)        _900_common.__init__(self)        class db_flexrf_900_rx(_900_common, flexrf_base_rx):    def __init__(self, usrp, which):        self.power_on = 0        self.power_off = 0    # powering it off kills the serial bus        flexrf_base_rx.__init__(self, usrp, which)        _900_common.__init__(self)    def gain_range(self):        """        Return range of gain that can be set by this d'board.                @returns (min_gain, max_gain, step_size)        Where gains are expressed in decibels (your mileage may vary)        """        return (self._u.pga_min(), self._u.pga_max() + 70, 0.05)    def i_and_q_swapped(self):        return Trueclass db_flexrf_400_tx(_400_common, flexrf_base_tx):    def __init__(self, usrp, which):        self.power_on = POWER_UP        self.power_off = 0        flexrf_base_tx.__init__(self, usrp, which)        _400_common.__init__(self)        class db_flexrf_400_rx(_400_common, flexrf_base_rx):    def __init__(self, usrp, which):        self.power_on = POWER_UP        self.power_off = 0        flexrf_base_rx.__init__(self, usrp, which)        _400_common.__init__(self)    def gain_range(self):        """        Return range of gain that can be set by this d'board.                @returns (min_gain, max_gain, step_size)        Where gains are expressed in decibels (your mileage may vary)        """        return (self._u.pga_min(), self._u.pga_max() + 45, 0.035)    def i_and_q_swapped(self):        return True    # hook these daughterboard classes into the auto-instantiation frameworkdb_instantiator.add(usrp_dbid.FLEX_2400_TX, lambda usrp, which : (db_flexrf_2400_tx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_2400_RX, lambda usrp, which : (db_flexrf_2400_rx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_1200_TX, lambda usrp, which : (db_flexrf_1200_tx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_1200_RX, lambda usrp, which : (db_flexrf_1200_rx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_1800_TX, lambda usrp, which : (db_flexrf_1800_tx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_1800_RX, lambda usrp, which : (db_flexrf_1800_rx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_900_TX,  lambda usrp, which : (db_flexrf_900_tx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_900_RX,  lambda usrp, which : (db_flexrf_900_rx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_400_TX,  lambda usrp, which : (db_flexrf_400_tx(usrp, which),))db_instantiator.add(usrp_dbid.FLEX_400_RX,  lambda usrp, which : (db_flexrf_400_rx(usrp, which),))

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -