txvga_gain = gain

        V_maxgain = 1.4
        V_mingain = 0.1
        V_fullscale = 3.3
        dac_value = ((txvga_gain-mingain)*(V_maxgain-V_mingain)/(maxgain-mingain) + V_mingain)*4096/V_fullscale
        assert dac_value>=0 and dac_value<4096
        print "DAC value %d" % (dac_value,)
        return self._u.write_aux_dac(self._which, 1, int(dac_value))

class db_wbx_lo_rx(_lo_common, wbx_base_rx):
    def __init__(self, usrp, which):
        wbx_base_rx.__init__(self, usrp, which)
        _lo_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.05)

#------------------------------------------------------------    
# hook these daughterboard classes into the auto-instantiation framework
db_instantiator.add(usrp_dbid.WBX_LO_TX, lambda usrp, which : (db_wbx_lo_tx(usrp, which),))
db_instantiator.add(usrp_dbid.WBX_LO_RX, lambda usrp, which : (db_wbx_lo_rx(usrp, which),))


            if(adc_val == 0):
                if vco <= 0:
                    return (False, 0)
                else:
                    vco = vco - 1
            elif(adc_val == 7):
                if(vco >= 7):
                    return (False, 0)
                else:
                    vco = vco + 1
            self._set_osc(vco)
        if adc_val == 1 or adc_val == 2:
            self._set_cp(1)
        elif adc_val == 3 or adc_val == 4:
            self._set_cp(2)
        else:
            self._set_cp(3)
                    
        return (True, self.n * self._refclk_freq() / self.r)

    def is_quadrature(self):
        """
        Return True if this board requires both I & Q analog channels.

        This bit of info is useful when setting up the USRP Rx mux register.
        """
        return True

# hook this daughterboard class into the auto-instantiation framework
db_instantiator.add(usrp_dbid.DBS_RX, lambda usrp, which : (db_dbs_rx(usrp, which),))

def _no_db_instantiator(usrp, which):
    if hasattr(usrp, "tx_freq"):  # is this a tx or rx daughterboard?
        return _basic_tx_instantiator(usrp, which)
    else:
        return _basic_rx_instantiator(usrp, which)


def _invalid_instantiator(usrp, which):
    if hasattr(usrp, "tx_freq"):  # is this a tx or rx daughterboard?
        sys.stderr.write(
            '\n\aWarning: Treating daughterboard with invalid EEPROM contents as if it were a "Basic Tx."\n'
        )
        sys.stderr.write("Warning: This is almost certainly wrong...  Use appropriate burn-*-eeprom utility.\n\n")
        return _basic_tx_instantiator(usrp, which)
    else:
        sys.stderr.write(
            '\n\aWarning: Treating daughterboard with invalid EEPROM contents as if it were a "Basic Rx."\n'
        )
        sys.stderr.write("Warning: This is almost certainly wrong...  Use appropriate burn-*-eeprom utility.\n\n")
        return _basic_rx_instantiator(usrp, which)


db_instantiator.add(-1, _no_db_instantiator)  # no daughterboard
db_instantiator.add(-2, _invalid_instantiator)  # invalid eeprom contents
db_instantiator.add(usrp_dbid.BASIC_TX, _basic_tx_instantiator)
db_instantiator.add(usrp_dbid.BASIC_RX, _basic_rx_instantiator)
db_instantiator.add(usrp_dbid.LF_TX, _lf_tx_instantiator)
db_instantiator.add(usrp_dbid.LF_RX, _lf_rx_instantiator)

class db_flexrf_400_rx_mimo_b(db_flexrf_400_rx):
    def __init__(self, usrp, which):
        db_flexrf_400_rx.__init__(self, usrp, which)
        self.R_DIV = 16

    def _refclk_divisor(self):
        """
        Return value to stick in REFCLK_DIVISOR register
        """
        return 1


# hook these daughterboard classes into the auto-instantiation framework
db_instantiator.add(usrp_dbid.FLEX_2400_TX_MIMO_A, lambda usrp, which: (db_flexrf_2400_tx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_2400_RX_MIMO_A, lambda usrp, which: (db_flexrf_2400_rx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1800_TX_MIMO_A, lambda usrp, which: (db_flexrf_1800_tx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1800_RX_MIMO_A, lambda usrp, which: (db_flexrf_1800_rx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1200_TX_MIMO_A, lambda usrp, which: (db_flexrf_1200_tx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1200_RX_MIMO_A, lambda usrp, which: (db_flexrf_1200_rx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_900_TX_MIMO_A, lambda usrp, which: (db_flexrf_900_tx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_900_RX_MIMO_A, lambda usrp, which: (db_flexrf_900_rx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_400_TX_MIMO_A, lambda usrp, which: (db_flexrf_400_tx_mimo_a(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_400_RX_MIMO_A, lambda usrp, which: (db_flexrf_400_rx_mimo_a(usrp, which),))

db_instantiator.add(usrp_dbid.FLEX_2400_TX_MIMO_B, lambda usrp, which: (db_flexrf_2400_tx_mimo_b(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_2400_RX_MIMO_B, lambda usrp, which: (db_flexrf_2400_rx_mimo_b(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1800_TX_MIMO_B, lambda usrp, which: (db_flexrf_1800_tx_mimo_b(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1800_RX_MIMO_B, lambda usrp, which: (db_flexrf_1800_rx_mimo_b(usrp, which),))
db_instantiator.add(usrp_dbid.FLEX_1200_TX_MIMO_B, lambda usrp, which: (db_flexrf_1200_tx_mimo_b(usrp, which),))
    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 framework

db_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),))
        return (ok, actual_freq - self._second_IF)

    def is_quadrature(self):
        """
        Return True if this board requires both I & Q analog channels.

        This bit of info is useful when setting up the USRP Rx mux register.
        """
        return False

    def spectrum_inverted(self):
        """
        The 43.75 MHz version is inverted
        """
        return self._inverted

# hook this daughterboard class into the auto-instantiation framework

# With MT4937DI5-3x7702 with second downconversion
db_instantiator.add(usrp_dbid.TV_RX,
                    lambda usrp, which : (db_tv_rx(usrp, which, 43.75e6, 5.75e6),))

# With MT4937DI5-3x8680, and 3x8769 without second downconversion
db_instantiator.add(usrp_dbid.TV_RX_REV_2,
                    lambda usrp, which : (db_tv_rx(usrp, which, 44e6, 20e6),))

# With MT4937DI5-3x7901 without second downconversion, basically the same as tvrx2
db_instantiator.add(usrp_dbid.TV_RX_REV_3,
                    lambda usrp, which : (db_tv_rx(usrp, which, 44e6, 20e6),))
        buf[2] = control_byte_4()
        buf[3] = control_byte_5(target_freq)
        buf[4] = control_byte_6()
        buf[5] = control_byte_7()

        ok = self._u.write_i2c(self._i2c_addr, int_seq_to_str (buf))

        self.freq = actual_lo_freq - self._IF
        
        return (ok, actual_lo_freq)

    def is_quadrature(self):
        """
        Return True if this board requires both I & Q analog channels.

        This bit of info is useful when setting up the USRP Rx mux register.
        """
        return False

    def spectrum_inverted(self):
        """
        The 43.75 MHz version is inverted
        """
        return self._inverted

# hook this daughterboard class into the auto-instantiation framework

# With DTT76803
db_instantiator.add(usrp_dbid.DTT768,
                    lambda usrp, which : (db_dtt768(usrp, which),))