2 // Copyright 2008,2009 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.
25 #include <usrp/db_tv_rx.h>
26 #include <db_base_impl.h>
28 /*****************************************************************************/
31 control_byte_1(bool fast_tuning_p, int reference_divisor)
38 if(reference_divisor == 512) {
41 else if(reference_divisor == 640) {
44 else if(reference_divisor == 1024) {
55 control_byte_2(double target_freq, bool shutdown_tx_PGA)
58 if(target_freq < 158e6) { // VHF low
61 else if(target_freq < 464e6) { // VHF high
76 /*****************************************************************************/
79 db_tv_rx::db_tv_rx(usrp_basic_sptr usrp, int which,
80 double first_IF, double second_IF)
81 : db_base(usrp, which)
83 // Handler for Tv Rx daughterboards.
85 // @param usrp: instance of usrp.source_c
86 // @param which: which side: 0, 1 corresponding to RX_A or RX_B respectively
95 d_first_IF = first_IF;
96 d_second_IF = second_IF;
97 d_reference_divisor = 640;
98 d_fast_tuning = false;
99 d_inverted = false; // FIXME get rid of this
101 set_gain((gain_min() + gain_max()) / 2.0); // initialize gain
103 bypass_adc_buffers(false);
106 db_tv_rx::~db_tv_rx()
112 db_tv_rx::_set_rfagc(float gain)
116 assert(gain <= 60 && gain >= 0);
117 // FIXME this has a 0.5V step between gain = 60 and gain = 59.
118 // Why are there two cases instead of a single linear case?
123 voltage = gain/60.0 * 2.25 + 1.25;
125 int dacword = int(4096*voltage/1.22/3.3); // 1.22 = opamp gain
127 assert(dacword>=0 && dacword<4096);
128 usrp()->write_aux_dac(d_which, 1, dacword);
132 db_tv_rx::_set_ifagc(float gain)
136 assert(gain <= 35 && gain >= 0);
137 voltage = gain/35.0 * 2.1 + 1.4;
138 int dacword = int(4096*voltage/1.22/3.3); // 1.22 = opamp gain
140 assert(dacword>=0 && dacword<4096);
141 usrp()->write_aux_dac(d_which, 0, dacword);
145 db_tv_rx::_set_pga(float pga_gain)
147 assert(pga_gain >=0 && pga_gain <=20);
149 usrp()->set_pga(0, pga_gain);
152 usrp()->set_pga (2, pga_gain);
169 db_tv_rx::set_freq(double target_freq)
171 // Set the frequency.
173 // @param freq: target RF frequency in Hz
174 // @type freq: double
176 // @returns (ok, actual_baseband_freq) where:
177 // ok is True or False and indicates success or failure,
178 // actual_baseband_freq is RF frequency that corresponds to DC in the IF.
180 freq_result_t args = {false, 0};
182 double fmin = freq_min();
183 double fmax = freq_max();
184 if((target_freq < fmin) || (target_freq > fmax)) {
188 double target_lo_freq = target_freq + d_first_IF; // High side mixing
189 double f_ref = 4.0e6 / (double)(d_reference_divisor); // frequency steps
191 int divisor = int((target_lo_freq + (f_ref * 4)) / (f_ref * 8));
192 double actual_lo_freq = (f_ref * 8 * divisor);
193 double actual_freq = actual_lo_freq - d_first_IF;
195 if((divisor & ~0x7fff) != 0) { // must be 15-bits or less
199 // build i2c command string
200 std::vector<int> buf(4);
201 buf[0] = (divisor >> 8) & 0xff; // DB1
202 buf[1] = divisor & 0xff; // DB2
203 buf[2] = control_byte_1(d_fast_tuning, d_reference_divisor);
204 buf[3] = control_byte_2(actual_freq, true);
206 args.ok = usrp()->write_i2c(d_i2c_addr, int_seq_to_str (buf));
207 args.baseband_freq = actual_freq - d_second_IF;
224 db_tv_rx::gain_db_per_step()
230 db_tv_rx::set_gain(float gain)
234 // @param gain: gain in decibels
235 // @returns True/False
237 float rfgain, ifgain, pgagain;
239 assert(gain>=0 && gain<=115);
267 db_tv_rx::is_quadrature()
269 // Return True if this board requires both I & Q analog channels.
274 db_tv_rx::spectrum_inverted()
276 // The 43.75 MHz version is inverted