3 * Copyright 2001,2003 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 version 2, 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.
23 #include "microtune_4937.h"
28 static const double first_IF = 43.75e6;
30 // The tuner internally has 3 bands: VHF Low, VHF High & UHF.
31 // These are the recommened boundaries
32 static const double VHF_High_takeover = 158e6;
33 static const double UHF_takeover = 464e6;
37 control_byte_1 (bool fast_tuning_p, int reference_divisor)
44 switch (reference_divisor){
58 control_byte_2 (double target_freq, bool shutdown_tx_PGA)
62 if (target_freq < VHF_High_takeover) // VHF low
64 else if (target_freq < UHF_takeover) // VHF high
75 microtune_4937::microtune_4937 (i2c_sptr i2c, int i2c_addr)
78 d_i2c_addr = i2c_addr;
79 d_reference_divider = 640;
80 d_fast_tuning_p = false;
83 microtune_4937::~microtune_4937 ()
89 * \brief select RF frequency to be tuned to output frequency.
90 * \p target_freq is the requested frequency in Hz, \p actual_freq
91 * is set to the actual frequency tuned. It takes about 100 ms
92 * for the PLL to settle.
94 * \returns true iff sucessful.
97 microtune_4937::set_RF_freq (double target_freq, double *p_actual_freq)
101 double target_f_osc = target_freq + first_IF;
103 double f_ref = 4e6 / d_reference_divider;
105 // f_osc = f_ref * 8 * divisor
106 // divisor = f_osc / (f_ref * 8)
108 int divisor = (int) ((target_f_osc + (f_ref * 4)) / (f_ref * 8));
109 double actual_freq = (f_ref * 8 * divisor) - first_IF;
110 if (p_actual_freq != 0)
111 *p_actual_freq = actual_freq;
113 if ((divisor & ~0x7fff) != 0) // 15 bit divisor
116 buf[0] = (divisor >> 8) & 0xff; // DB1
117 buf[1] = divisor & 0xff; // DB2
118 buf[2] = control_byte_1 (d_fast_tuning_p, d_reference_divider);
119 buf[3] = control_byte_2 (target_freq, true);
122 printf ("set_RF_freq: target: %g MHz actual: %g MHz %02x %02x %02x %02x\n",
123 target_freq/1e6, actual_freq/1e6, buf[0], buf[1], buf[2], buf[3]);
126 return d_i2c->write (d_i2c_addr, buf, 4);
130 * \returns true iff PLL is locked
133 microtune_4937::pll_locked_p ()
140 * \returns the output frequency of the tuner in Hz.
143 microtune_4937::get_output_freq ()
145 return 5.75e6; // 3x7702