root / host / lib / usrp / dboard / db_sbx_version3.cpp @ 09de3c07
History | View | Annotate | Download (7.21 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2011-2012 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
|
| 19 |
#include "adf4350_regs.hpp" |
| 20 |
#include "db_sbx_common.hpp" |
| 21 |
|
| 22 |
|
| 23 |
using namespace uhd; |
| 24 |
using namespace uhd::usrp; |
| 25 |
using namespace boost::assign; |
| 26 |
|
| 27 |
/***********************************************************************
|
| 28 |
* Structors
|
| 29 |
**********************************************************************/
|
| 30 |
sbx_xcvr::sbx_version3::sbx_version3(sbx_xcvr *_self_sbx_xcvr) {
|
| 31 |
//register the handle to our base SBX class
|
| 32 |
self_base = _self_sbx_xcvr; |
| 33 |
} |
| 34 |
|
| 35 |
sbx_xcvr::sbx_version3::~sbx_version3(void){
|
| 36 |
/* NOP */
|
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
/***********************************************************************
|
| 41 |
* Tuning
|
| 42 |
**********************************************************************/
|
| 43 |
double sbx_xcvr::sbx_version3::set_lo_freq(dboard_iface::unit_t unit, double target_freq) { |
| 44 |
UHD_LOGV(often) << boost::format( |
| 45 |
"SBX tune: target frequency %f Mhz"
|
| 46 |
) % (target_freq/1e6) << std::endl;
|
| 47 |
|
| 48 |
//clip the input
|
| 49 |
target_freq = sbx_freq_range.clip(target_freq); |
| 50 |
|
| 51 |
//map prescaler setting to mininmum integer divider (N) values (pg.18 prescaler)
|
| 52 |
static const uhd::dict<int, int> prescaler_to_min_int_div = map_list_of |
| 53 |
(0,23) //adf4350_regs_t::PRESCALER_4_5 |
| 54 |
(1,75) //adf4350_regs_t::PRESCALER_8_9 |
| 55 |
; |
| 56 |
|
| 57 |
//map rf divider select output dividers to enums
|
| 58 |
static const uhd::dict<int, adf4350_regs_t::rf_divider_select_t> rfdivsel_to_enum = map_list_of |
| 59 |
(1, adf4350_regs_t::RF_DIVIDER_SELECT_DIV1)
|
| 60 |
(2, adf4350_regs_t::RF_DIVIDER_SELECT_DIV2)
|
| 61 |
(4, adf4350_regs_t::RF_DIVIDER_SELECT_DIV4)
|
| 62 |
(8, adf4350_regs_t::RF_DIVIDER_SELECT_DIV8)
|
| 63 |
(16, adf4350_regs_t::RF_DIVIDER_SELECT_DIV16)
|
| 64 |
; |
| 65 |
|
| 66 |
double actual_freq, pfd_freq;
|
| 67 |
double ref_freq = self_base->get_iface()->get_clock_rate(unit);
|
| 68 |
int R=0, BS=0, N=0, FRAC=0, MOD=0; |
| 69 |
int RFdiv = 1; |
| 70 |
adf4350_regs_t::reference_divide_by_2_t T = adf4350_regs_t::REFERENCE_DIVIDE_BY_2_DISABLED; |
| 71 |
adf4350_regs_t::reference_doubler_t D = adf4350_regs_t::REFERENCE_DOUBLER_DISABLED; |
| 72 |
|
| 73 |
//Reference doubler for 50% duty cycle
|
| 74 |
// if ref_freq < 12.5MHz enable regs.reference_divide_by_2
|
| 75 |
if(ref_freq <= 12.5e6) D = adf4350_regs_t::REFERENCE_DOUBLER_ENABLED; |
| 76 |
|
| 77 |
//increase RF divider until acceptable VCO frequency
|
| 78 |
double vco_freq = target_freq;
|
| 79 |
while (vco_freq < 2.2e9) { |
| 80 |
vco_freq *= 2;
|
| 81 |
RFdiv *= 2;
|
| 82 |
} |
| 83 |
|
| 84 |
//use 8/9 prescaler for vco_freq > 3 GHz (pg.18 prescaler)
|
| 85 |
adf4350_regs_t::prescaler_t prescaler = target_freq > 3e9 ? adf4350_regs_t::PRESCALER_8_9 : adf4350_regs_t::PRESCALER_4_5;
|
| 86 |
|
| 87 |
/*
|
| 88 |
* The goal here is to loop though possible R dividers,
|
| 89 |
* band select clock dividers, N (int) dividers, and FRAC
|
| 90 |
* (frac) dividers.
|
| 91 |
*
|
| 92 |
* Calculate the N and F dividers for each set of values.
|
| 93 |
* The loop exits when it meets all of the constraints.
|
| 94 |
* The resulting loop values are loaded into the registers.
|
| 95 |
*
|
| 96 |
* from pg.21
|
| 97 |
*
|
| 98 |
* f_pfd = f_ref*(1+D)/(R*(1+T))
|
| 99 |
* f_vco = (N + (FRAC/MOD))*f_pfd
|
| 100 |
* N = f_vco/f_pfd - FRAC/MOD = f_vco*((R*(T+1))/(f_ref*(1+D))) - FRAC/MOD
|
| 101 |
* f_rf = f_vco/RFdiv)
|
| 102 |
* f_actual = f_rf/2
|
| 103 |
*/
|
| 104 |
for(R = 1; R <= 1023; R+=1){ |
| 105 |
//PFD input frequency = f_ref/R ... ignoring Reference doubler/divide-by-2 (D & T)
|
| 106 |
pfd_freq = ref_freq*(1+D)/(R*(1+T)); |
| 107 |
|
| 108 |
//keep the PFD frequency at or below 25MHz (Loop Filter Bandwidth)
|
| 109 |
if (pfd_freq > 25e6) continue; |
| 110 |
|
| 111 |
//ignore fractional part of tuning
|
| 112 |
N = int(std::floor(target_freq/pfd_freq));
|
| 113 |
|
| 114 |
//keep N > minimum int divider requirement
|
| 115 |
if (N < prescaler_to_min_int_div[prescaler]) continue; |
| 116 |
|
| 117 |
for(BS=1; BS <= 255; BS+=1){ |
| 118 |
//keep the band select frequency at or below 100KHz
|
| 119 |
//constraint on band select clock
|
| 120 |
if (pfd_freq/BS > 100e3) continue; |
| 121 |
goto done_loop;
|
| 122 |
} |
| 123 |
} done_loop:
|
| 124 |
|
| 125 |
//Fractional-N calculation
|
| 126 |
MOD = 4095; //max fractional accuracy |
| 127 |
FRAC = int((target_freq/pfd_freq - N)*MOD);
|
| 128 |
|
| 129 |
//Reference divide-by-2 for 50% duty cycle
|
| 130 |
// if R even, move one divide by 2 to to regs.reference_divide_by_2
|
| 131 |
if(R % 2 == 0){ |
| 132 |
T = adf4350_regs_t::REFERENCE_DIVIDE_BY_2_ENABLED; |
| 133 |
R /= 2;
|
| 134 |
} |
| 135 |
|
| 136 |
//actual frequency calculation
|
| 137 |
actual_freq = double((N + (double(FRAC)/double(MOD)))*ref_freq*(1+int(D))/(R*(1+int(T)))); |
| 138 |
|
| 139 |
UHD_LOGV(often) |
| 140 |
<< boost::format("SBX Intermediates: ref=%0.2f, outdiv=%f, fbdiv=%f") % (ref_freq*(1+int(D))/(R*(1+int(T)))) % double(RFdiv*2) % double(N + double(FRAC)/double(MOD)) << std::endl |
| 141 |
<< boost::format("SBX tune: R=%d, BS=%d, N=%d, FRAC=%d, MOD=%d, T=%d, D=%d, RFdiv=%d"
|
| 142 |
) % R % BS % N % FRAC % MOD % T % D % RFdiv << std::endl |
| 143 |
<< boost::format("SBX Frequencies (MHz): REQ=%0.2f, ACT=%0.2f, VCO=%0.2f, PFD=%0.2f, BAND=%0.2f"
|
| 144 |
) % (target_freq/1e6) % (actual_freq/1e6) % (vco_freq/1e6) % (pfd_freq/1e6) % (pfd_freq/BS/1e6) << std::endl; |
| 145 |
|
| 146 |
//load the register values
|
| 147 |
adf4350_regs_t regs; |
| 148 |
|
| 149 |
if ((unit == dboard_iface::UNIT_TX) and (actual_freq == sbx_tx_lo_2dbm.clip(actual_freq))) |
| 150 |
regs.output_power = adf4350_regs_t::OUTPUT_POWER_2DBM; |
| 151 |
else
|
| 152 |
regs.output_power = adf4350_regs_t::OUTPUT_POWER_5DBM; |
| 153 |
|
| 154 |
regs.frac_12_bit = FRAC; |
| 155 |
regs.int_16_bit = N; |
| 156 |
regs.mod_12_bit = MOD; |
| 157 |
regs.clock_divider_12_bit = std::max(1, int(std::ceil(400e-6*pfd_freq/MOD))); |
| 158 |
regs.feedback_select = adf4350_regs_t::FEEDBACK_SELECT_DIVIDED; |
| 159 |
regs.clock_div_mode = adf4350_regs_t::CLOCK_DIV_MODE_RESYNC_ENABLE; |
| 160 |
regs.prescaler = prescaler; |
| 161 |
regs.r_counter_10_bit = R; |
| 162 |
regs.reference_divide_by_2 = T; |
| 163 |
regs.reference_doubler = D; |
| 164 |
regs.band_select_clock_div = BS; |
| 165 |
UHD_ASSERT_THROW(rfdivsel_to_enum.has_key(RFdiv)); |
| 166 |
regs.rf_divider_select = rfdivsel_to_enum[RFdiv]; |
| 167 |
|
| 168 |
//reset the N and R counter
|
| 169 |
regs.counter_reset = adf4350_regs_t::COUNTER_RESET_ENABLED; |
| 170 |
self_base->get_iface()->write_spi(unit, spi_config_t::EDGE_RISE, regs.get_reg(2), 32); |
| 171 |
regs.counter_reset = adf4350_regs_t::COUNTER_RESET_DISABLED; |
| 172 |
|
| 173 |
//write the registers
|
| 174 |
//correct power-up sequence to write registers (5, 4, 3, 2, 1, 0)
|
| 175 |
int addr;
|
| 176 |
|
| 177 |
for(addr=5; addr>=0; addr--){ |
| 178 |
UHD_LOGV(often) << boost::format( |
| 179 |
"SBX SPI Reg (0x%02x): 0x%08x"
|
| 180 |
) % addr % regs.get_reg(addr) << std::endl; |
| 181 |
self_base->get_iface()->write_spi( |
| 182 |
unit, spi_config_t::EDGE_RISE, |
| 183 |
regs.get_reg(addr), 32
|
| 184 |
); |
| 185 |
} |
| 186 |
|
| 187 |
//return the actual frequency
|
| 188 |
UHD_LOGV(often) << boost::format( |
| 189 |
"SBX tune: actual frequency %f Mhz"
|
| 190 |
) % (actual_freq/1e6) << std::endl;
|
| 191 |
return actual_freq;
|
| 192 |
} |
| 193 |
|