2 // Copyright 2008 Free Software Foundation, Inc.
4 // This file is part of GNU Radio
6 // GNU Radio is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either asversion 3, or (at your option)
11 // GNU Radio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with GNU Radio; see the file COPYING. If not, write to
18 // the Free Software Foundation, Inc., 51 Franklin Street,
19 // Boston, MA 02110-1301, USA.
22 #include <db_base_impl.h>
24 /*****************************************************************************/
27 control_byte_1(bool fast_tuning_p, int reference_divisor)
34 if(reference_divisor == 512) {
37 else if(reference_divisor == 640) {
40 else if(reference_divisor == 1024) {
51 control_byte_2(double target_freq, bool shutdown_tx_PGA)
54 if(target_freq < 158e6) { // VHF low
57 else if(target_freq < 464e6) { // VHF high
72 /*****************************************************************************/
75 db_tv_rx::db_tv_rx(usrp_basic_sptr usrp, int which,
76 double first_IF, double second_IF)
77 : db_base(usrp, which)
79 // Handler for Tv Rx daughterboards.
81 // @param usrp: instance of usrp.source_c
82 // @param which: which side: 0, 1 corresponding to RX_A or RX_B respectively
91 d_first_IF = first_IF;
92 d_second_IF = second_IF;
93 d_reference_divisor = 640;
94 d_fast_tuning = false;
95 d_inverted = false; // FIXME get rid of this
97 set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
99 bypass_adc_buffers(false);
102 db_tv_rx::~db_tv_rx()
108 db_tv_rx::_set_rfagc(float gain)
112 assert(gain <= 60 && gain >= 0);
113 // FIXME this has a 0.5V step between gain = 60 and gain = 59.
114 // Why are there two cases instead of a single linear case?
119 voltage = gain/60.0 * 2.25 + 1.25;
121 int dacword = int(4096*voltage/1.22/3.3); // 1.22 = opamp gain
123 assert(dacword>=0 && dacword<4096);
124 usrp()->write_aux_dac(d_which, 1, dacword);
128 db_tv_rx::_set_ifagc(float gain)
132 assert(gain <= 35 && gain >= 0);
133 voltage = gain/35.0 * 2.1 + 1.4;
134 int dacword = int(4096*voltage/1.22/3.3); // 1.22 = opamp gain
136 assert(dacword>=0 && dacword<4096);
137 usrp()->write_aux_dac(d_which, 0, dacword);
141 db_tv_rx::_set_pga(float pga_gain)
143 assert(pga_gain >=0 && pga_gain <=20);
145 usrp()->set_pga(0, pga_gain);
148 usrp()->set_pga (2, pga_gain);
165 db_tv_rx::set_freq(double target_freq)
167 // Set the frequency.
169 // @param freq: target RF frequency in Hz
170 // @type freq: double
172 // @returns (ok, actual_baseband_freq) where:
173 // ok is True or False and indicates success or failure,
174 // actual_baseband_freq is RF frequency that corresponds to DC in the IF.
176 freq_result_t args = {false, 0};
178 double fmin = freq_min();
179 double fmax = freq_max();
180 if((target_freq < fmin) || (target_freq > fmax)) {
184 double target_lo_freq = target_freq + d_first_IF; // High side mixing
185 double f_ref = 4.0e6 / (double)(d_reference_divisor); // frequency steps
187 int divisor = int((target_lo_freq + (f_ref * 4)) / (f_ref * 8));
188 double actual_lo_freq = (f_ref * 8 * divisor);
189 double actual_freq = actual_lo_freq - d_first_IF;
191 if((divisor & ~0x7fff) != 0) { // must be 15-bits or less
195 // build i2c command string
196 std::vector<int> buf(4);
197 buf[0] = (divisor >> 8) & 0xff; // DB1
198 buf[1] = divisor & 0xff; // DB2
199 buf[2] = control_byte_1(d_fast_tuning, d_reference_divisor);
200 buf[3] = control_byte_2(actual_freq, true);
202 args.ok = usrp()->write_i2c(d_i2c_addr, int_seq_to_str (buf));
203 args.baseband_freq = actual_freq - d_second_IF;
220 db_tv_rx::gain_db_per_step()
226 db_tv_rx::set_gain(float gain)
230 // @param gain: gain in decibels
231 // @returns True/False
233 float rfgain, ifgain, pgagain;
235 assert(gain>=0 && gain<=115);
263 db_tv_rx::is_quadrature()
265 // Return True if this board requires both I & Q analog channels.
270 db_tv_rx::spectrum_inverted()
272 // The 43.75 MHz version is inverted