3 // Copyright 2008,2009 Free Software Foundation, Inc.
5 // This file is part of GNU Radio
7 // GNU Radio is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either asversion 3, or (at your option)
12 // GNU Radio is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with GNU Radio; see the file COPYING. If not, write to
19 // the Free Software Foundation, Inc., 51 Franklin Street,
20 // Boston, MA 02110-1301, USA.
26 #include <usrp/db_dtt754.h>
27 #include <db_base_impl.h>
32 int RS = 0; // 0 = 166.66kHz reference
33 int ATP = 7; // Disable internal AGC
34 return (0x80 | ATP<<3 | RS);
40 int STBY = 0; // powered on
41 int XTO = 1; // turn off xtal out, which we don't have
42 int ATC = 0; // not clear exactly, possibly speeds up or slows down AGC, which we are not using
44 int c = 0xc2 | ATC<<5 | STBY<<4 | XTO;
49 bandswitch_byte(float freq, float bw)
64 else if(freq < 141e6) {
68 else if(freq < 166e6) {
72 else if(freq < 182e6) {
76 else if(freq < 286e6) {
80 else if(freq < 386e6) {
84 else if(freq < 446e6) {
88 else if(freq < 466e6) {
92 else if(freq < 506e6) {
96 else if(freq < 761e6) {
100 else if(freq < 846e6) {
104 else { // limit is ~905 MHz
108 return (CP<<6 | P5 << 4 | BS);
111 db_dtt754::db_dtt754(usrp_basic_sptr _usrp, int which)
112 : db_base(_usrp, which)
115 * Control custom DTT75403-based daughterboard.
117 * @param usrp: instance of usrp.source_c
118 * @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
122 // FIXME: DTT754 and DTT768 can probably inherit from a DTT class
134 d_f_ref = 166.6666e3;
137 set_gain((gain_min() + gain_max()) / 2.0);
139 bypass_adc_buffers(false);
142 db_dtt754::~db_dtt754()
147 db_dtt754::gain_min()
153 db_dtt754::gain_max()
159 db_dtt754::gain_db_per_step()
165 db_dtt754::set_gain(float gain)
167 assert(gain>=0 && gain<=115);
169 float rfgain, ifgain, pgagain;
193 return true; // can't fail with the assert in place
197 db_dtt754::freq_min()
203 db_dtt754::freq_max()
209 db_dtt754::set_freq(double target_freq)
212 * @returns (ok, actual_baseband_freq) where:
213 * ok is True or False and indicates success or failure,
214 * actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
217 freq_result_t ret = {false, 0.0};
219 if(target_freq < freq_min() || target_freq > freq_max()) {
223 double target_lo_freq = target_freq + d_IF; // High side mixing
225 int divisor = (int)(0.5+(target_lo_freq / d_f_ref));
226 double actual_lo_freq = d_f_ref*divisor;
228 if((divisor & ~0x7fff) != 0) { // must be 15-bits or less
232 // build i2c command string
233 std::vector<int> buf(5);
234 buf[0] = (divisor >> 8) & 0xff; // DB1
235 buf[1] = divisor & 0xff; // DB2
236 buf[2] = control_byte_1();
237 buf[3] = bandswitch_byte(actual_lo_freq, d_bw);
238 buf[4] = control_byte_2();
240 bool ok = usrp()->write_i2c(d_i2c_addr, int_seq_to_str (buf));
242 d_freq = actual_lo_freq - d_IF;
245 ret.baseband_freq = actual_lo_freq;
252 db_dtt754::is_quadrature()
255 * Return True if this board requires both I & Q analog channels.
257 * This bit of info is useful when setting up the USRP Rx mux register.
264 db_dtt754::spectrum_inverted()
267 * The 43.75 MHz version is inverted
274 db_dtt754::set_bw(float bw)
277 * Choose the SAW filter bandwidth, either 7MHz or 8MHz)
283 return true; // FIXME: propagate set_freq result
287 db_dtt754::_set_rfagc(float gain)
289 assert(gain <= 60 && gain >= 0);
290 // FIXME this has a 0.5V step between gain = 60 and gain = 59.
291 // Why are there two cases instead of a single linear case?
297 voltage = gain/60.0 * 2.25 + 1.25;
300 int dacword = (int)(4096*voltage/1.22/3.3); // 1.22 = opamp gain
302 assert(dacword>=0 && dacword<4096);
303 usrp()->write_aux_dac(d_which, 1, dacword);
307 db_dtt754::_set_ifagc(float gain)
309 assert(gain <= 35 && gain >= 0);
310 float voltage = gain/35.0 * 2.1 + 1.4;
311 int dacword = (int)(4096*voltage/1.22/3.3); // 1.22 = opamp gain
313 assert(dacword>=0 && dacword<4096);
314 usrp()->write_aux_dac(d_which, 0, dacword);
318 db_dtt754::_set_pga(float pga_gain)
320 assert(pga_gain >=0 && pga_gain <=20);
322 usrp()->set_pga (0, pga_gain);
325 usrp()->set_pga (2, pga_gain);