3 // Copyright 2008 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.
22 #include <db_dtt754.h>
23 #include <db_base_impl.h>
28 int RS = 0; // 0 = 166.66kHz reference
29 int ATP = 7; // Disable internal AGC
30 return (0x80 | ATP<<3 | RS);
36 int STBY = 0; // powered on
37 int XTO = 1; // turn off xtal out, which we don't have
38 int ATC = 0; // not clear exactly, possibly speeds up or slows down AGC, which we are not using
40 int c = 0xc2 | ATC<<5 | STBY<<4 | XTO;
45 bandswitch_byte(float freq, float bw)
60 else if(freq < 141e6) {
64 else if(freq < 166e6) {
68 else if(freq < 182e6) {
72 else if(freq < 286e6) {
76 else if(freq < 386e6) {
80 else if(freq < 446e6) {
84 else if(freq < 466e6) {
88 else if(freq < 506e6) {
92 else if(freq < 761e6) {
96 else if(freq < 846e6) {
100 else { // limit is ~905 MHz
104 return (CP<<6 | P5 << 4 | BS);
107 db_dtt754::db_dtt754(usrp_basic_sptr _usrp, int which)
108 : db_base(_usrp, which)
111 * Control custom DTT75403-based daughterboard.
113 * @param usrp: instance of usrp.source_c
114 * @param which: which side: 0 or 1 corresponding to RX_A or RX_B respectively
118 // FIXME: DTT754 and DTT768 can probably inherit from a DTT class
130 d_f_ref = 166.6666e3;
133 set_gain((gain_min() + gain_max()) / 2.0);
135 bypass_adc_buffers(false);
138 db_dtt754::~db_dtt754()
143 db_dtt754::gain_min()
149 db_dtt754::gain_max()
155 db_dtt754::gain_db_per_step()
161 db_dtt754::set_gain(float gain)
163 assert(gain>=0 && gain<=115);
165 float rfgain, ifgain, pgagain;
189 return true; // can't fail with the assert in place
193 db_dtt754::freq_min()
199 db_dtt754::freq_max()
205 db_dtt754::set_freq(double target_freq)
208 * @returns (ok, actual_baseband_freq) where:
209 * ok is True or False and indicates success or failure,
210 * actual_baseband_freq is the RF frequency that corresponds to DC in the IF.
213 freq_result_t ret = {false, 0.0};
215 if(target_freq < freq_min() || target_freq > freq_max()) {
219 double target_lo_freq = target_freq + d_IF; // High side mixing
221 int divisor = (int)(0.5+(target_lo_freq / d_f_ref));
222 double actual_lo_freq = d_f_ref*divisor;
224 if((divisor & ~0x7fff) != 0) { // must be 15-bits or less
228 // build i2c command string
229 std::vector<int> buf(5);
230 buf[0] = (divisor >> 8) & 0xff; // DB1
231 buf[1] = divisor & 0xff; // DB2
232 buf[2] = control_byte_1();
233 buf[3] = bandswitch_byte(actual_lo_freq, d_bw);
234 buf[4] = control_byte_2();
236 bool ok = usrp()->write_i2c(d_i2c_addr, int_seq_to_str (buf));
238 d_freq = actual_lo_freq - d_IF;
241 ret.baseband_freq = actual_lo_freq;
248 db_dtt754::is_quadrature()
251 * Return True if this board requires both I & Q analog channels.
253 * This bit of info is useful when setting up the USRP Rx mux register.
260 db_dtt754::spectrum_inverted()
263 * The 43.75 MHz version is inverted
270 db_dtt754::set_bw(float bw)
273 * Choose the SAW filter bandwidth, either 7MHz or 8MHz)
279 return true; // FIXME: propagate set_freq result
283 db_dtt754::_set_rfagc(float gain)
285 assert(gain <= 60 && gain >= 0);
286 // FIXME this has a 0.5V step between gain = 60 and gain = 59.
287 // Why are there two cases instead of a single linear case?
293 voltage = gain/60.0 * 2.25 + 1.25;
296 int dacword = (int)(4096*voltage/1.22/3.3); // 1.22 = opamp gain
298 assert(dacword>=0 && dacword<4096);
299 usrp()->write_aux_dac(d_which, 1, dacword);
303 db_dtt754::_set_ifagc(float gain)
305 assert(gain <= 35 && gain >= 0);
306 float voltage = gain/35.0 * 2.1 + 1.4;
307 int dacword = (int)(4096*voltage/1.22/3.3); // 1.22 = opamp gain
309 assert(dacword>=0 && dacword<4096);
310 usrp()->write_aux_dac(d_which, 0, dacword);
314 db_dtt754::_set_pga(float pga_gain)
316 assert(pga_gain >=0 && pga_gain <=20);
318 usrp()->set_pga (0, pga_gain);
321 usrp()->set_pga (2, pga_gain);