3 * Copyright 2001,2003,2004 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_4702.h"
28 static const double FIRST_IF = 36.00e6;
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 = 174e6;
33 static const double UHF_takeover = 470e6;
35 static int PLL_I2C_ADDR = 0x60;
38 control_byte_1 (bool prescaler, int reference_divisor)
41 //Note: Last two divider bits (bits 2 and 3 of this byte) determined later
45 switch (reference_divisor){
85 control_byte_2 (double target_freq)
89 if (target_freq < VHF_High_takeover) // VHF low
92 else if (target_freq < UHF_takeover){ // VHF high
94 if (target_freq < 390e6)
101 if (target_freq < 750e6)
111 microtune_4702::microtune_4702 (i2c_sptr i2c, int i2c_addr)
114 d_i2c_addr = i2c_addr;
115 d_reference_divider = 320;
119 microtune_4702::~microtune_4702 ()
125 * \brief select RF frequency to be tuned to output frequency.
126 * \p target_freq is the requested frequency in Hz, \p actual_freq
127 * is set to the actual frequency tuned. It takes about 100 ms
128 * for the PLL to settle.
130 * \returns true iff sucessful.
133 microtune_4702::set_RF_freq (double target_freq, double *p_actual_freq)
135 unsigned char buf[4];
137 double target_f_osc = target_freq + FIRST_IF;
139 double f_ref = 4e6 / d_reference_divider;
141 //int divisor = (int) ((target_f_osc + (f_ref * 4)) / (f_ref * 8));
143 long int divisor = (long int) (target_f_osc / f_ref);
144 double actual_freq = (f_ref * divisor) - FIRST_IF;
145 if (p_actual_freq != 0)
146 *p_actual_freq = actual_freq;
148 if ((divisor & ~0x1ffff) != 0) // >17 bit divisor
151 buf[0] = ((divisor & 0x07f00) >> 8) & 0xff; // DB1
152 buf[1] = divisor & 0xff; // DB2
153 buf[2] = control_byte_1 (d_prescaler, d_reference_divider);
154 buf[2] = (buf[2]|(((divisor & 0x18000) >> 10)) & 0xff);
155 buf[3] = control_byte_2 (target_freq);
157 printf ("%x\n", PLL_I2C_ADDR);
159 printf ("set_RF_freq: target: %g MHz actual: %g MHz %02x %02x %02x %02x\n",
160 target_freq/1e6, actual_freq/1e6, buf[0], buf[1], buf[2], buf[3]);
163 return d_i2c->write (d_i2c_addr, buf, sizeof (buf));
167 * \returns true iff PLL is locked
170 microtune_4702::pll_locked_p ()
177 * \returns the output frequency of the tuner in Hz.
180 microtune_4702::get_output_freq ()