summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-10-07 12:37:42 -0700
committerJosh Blum <josh@joshknows.com>2010-10-07 12:37:42 -0700
commit4c3b5212b1b91b30b44af72365448ea6af66c408 (patch)
tree3d964fc4175cbf320a2957da0c27428b437e323b /host
parentd6e6d8bffc1663fe82ba57e4dcf1ecbcec59c53e (diff)
downloaduhd-4c3b5212b1b91b30b44af72365448ea6af66c408.tar.gz
uhd-4c3b5212b1b91b30b44af72365448ea6af66c408.tar.bz2
uhd-4c3b5212b1b91b30b44af72365448ea6af66c408.zip
tvrx: converted floats to doubles to avoid msvc warnings
Diffstat (limited to 'host')
-rw-r--r--host/lib/usrp/dboard/db_tvrx.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp
index 41c52fbf5..33507acaa 100644
--- a/host/lib/usrp/dboard/db_tvrx.cpp
+++ b/host/lib/usrp/dboard/db_tvrx.cpp
@@ -66,25 +66,25 @@ static const uhd::dict<std::string, freq_range_t> tvrx_freq_ranges = map_list_of
("UHF" , freq_range_t(454e6, 860e6))
;
-static const boost::array<float, 17> vhflo_gains_db =
+static const boost::array<double, 17> vhflo_gains_db =
{{-6.00000, -6.00000, -6.00000, -4.00000, 0.00000,
5.00000, 10.00000, 17.40000, 26.30000, 36.00000,
43.00000, 48.00000, 49.50000, 50.10000, 50.30000,
50.30000, 50.30000}};
-
-static const boost::array<float, 17> vhfhi_gains_db =
+
+static const boost::array<double, 17> vhfhi_gains_db =
{{13.3000, -13.3000, -13.3000, -1.0000, 7.7000,
11.0000, 14.7000, 19.3000, 26.1000, 36.0000,
42.7000, 46.0000, 47.0000, 47.8000, 48.2000,
48.2000, 48.2000}};
-
-static const boost::array<float, 17> uhf_gains_db =
+
+static const boost::array<double, 17> uhf_gains_db =
{{-8.0000, -8.0000, -7.0000, 4.0000, 10.2000,
14.5000, 17.5000, 20.0000, 24.5000, 30.8000,
37.0000, 39.8000, 40.7000, 41.6000, 42.6000,
43.2000, 43.8000}};
-
-static const boost::array<float, 17> tvrx_if_gains_db =
+
+static const boost::array<double, 17> tvrx_if_gains_db =
{{-1.50000, -1.50000, -1.50000, -1.00000, 0.20000,
2.10000, 4.30000, 6.40000, 9.00000, 12.00000,
14.80000, 18.20000, 26.10000, 32.50000, 32.50000,
@@ -96,32 +96,32 @@ static const boost::array<float, 17> tvrx_if_gains_db =
//need dang near as many coefficients as to just map it like this and interp.
//these numbers are culled from the 4937DI5 datasheet and are probably totally inaccurate
//but if it's better than the old linear fit i'm happy
-static const uhd::dict<std::string, boost::array<float, 17> > tvrx_rf_gains_db = map_list_of
+static const uhd::dict<std::string, boost::array<double, 17> > tvrx_rf_gains_db = map_list_of
("VHFLO", vhflo_gains_db)
("VHFHI", vhfhi_gains_db)
("UHF" , uhf_gains_db)
;
//sample voltages for the above points
-static const boost::array<float, 17> tvrx_gains_volts =
+static const boost::array<double, 17> tvrx_gains_volts =
{{0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0}};
static uhd::dict<std::string, gain_range_t> get_tvrx_gain_ranges(void) {
- float rfmax = 0.0, rfmin = FLT_MAX;
+ double rfmax = 0.0, rfmin = FLT_MAX;
BOOST_FOREACH(const std::string range, tvrx_rf_gains_db.keys()) {
- float my_max = tvrx_rf_gains_db[range].back(); //we're assuming it's monotonic
- float my_min = tvrx_rf_gains_db[range].front(); //if it's not this is wrong wrong wrong
+ double my_max = tvrx_rf_gains_db[range].back(); //we're assuming it's monotonic
+ double my_min = tvrx_rf_gains_db[range].front(); //if it's not this is wrong wrong wrong
if(my_max > rfmax) rfmax = my_max;
if(my_min < rfmin) rfmin = my_min;
}
-
- float ifmin = tvrx_if_gains_db.front();
- float ifmax = tvrx_if_gains_db.back();
-
+
+ double ifmin = tvrx_if_gains_db.front();
+ double ifmax = tvrx_if_gains_db.back();
+
return map_list_of
- ("RF", gain_range_t(rfmin, rfmax, (rfmax-rfmin)/4096.0))
- ("IF", gain_range_t(ifmin, ifmax, (ifmax-ifmin)/4096.0))
- ;
+ ("RF", gain_range_t(float(rfmin), float(rfmax), float((rfmax-rfmin)/4096.0)))
+ ("IF", gain_range_t(float(ifmin), float(ifmax), float((ifmax-ifmin)/4096.0)))
+ ;
}
static const double opamp_gain = 1.22; //onboard DAC opamp gain
@@ -136,7 +136,7 @@ class tvrx : public rx_dboard_base{
public:
tvrx(ctor_args_t args);
~tvrx(void);
-
+
void rx_get(const wax::obj &key, wax::obj &val);
void rx_set(const wax::obj &key, const wax::obj &val);
@@ -198,11 +198,11 @@ tvrx::tvrx(ctor_args_t args) : rx_dboard_base(args){
}
//send initial register settings if necessary
-
+
//set default freq
_lo_freq = tvrx_freq_range.min + tvrx_if_freq; //init _lo_freq to a sane default
set_freq(tvrx_freq_range.min);
-
+
//set default gains
BOOST_FOREACH(const std::string &name, get_tvrx_gain_ranges().keys()){
set_gain(get_tvrx_gain_ranges()[name].min, name);
@@ -238,33 +238,33 @@ static std::string get_band(double freq) {
* \return a voltage to feed the TVRX analog gain
*/
-static float gain_interp(float gain, boost::array<float, 17> db_vector, boost::array<float, 17> volts_vector) {
- float volts;
- gain = std::clip<float>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
-
+static double gain_interp(double gain, boost::array<double, 17> db_vector, boost::array<double, 17> volts_vector) {
+ double volts;
+ gain = std::clip<double>(gain, db_vector.front(), db_vector.back()); //let's not get carried away here
+
boost::uint8_t gain_step = 0;
//find which bin we're in
for(size_t i = 0; i < db_vector.size()-1; i++) {
if(gain >= db_vector[i] && gain <= db_vector[i+1]) gain_step = i;
}
-
+
//find the current slope for linear interpolation
- float slope = (volts_vector[gain_step + 1] - volts_vector[gain_step])
+ double slope = (volts_vector[gain_step + 1] - volts_vector[gain_step])
/ (db_vector[gain_step + 1] - db_vector[gain_step]);
-
+
//the problem here is that for gains approaching the maximum, the voltage slope becomes infinite
//i.e., a small change in gain requires an infinite change in voltage
//to cope, we limit the slope
-
- if(slope == std::numeric_limits<float>::infinity())
+
+ if(slope == std::numeric_limits<double>::infinity())
return volts_vector[gain_step];
//use the volts per dB slope to find the final interpolated voltage
volts = volts_vector[gain_step] + (slope * (gain - db_vector[gain_step]));
-
+
if(tvrx_debug)
std::cout << "Gain interp: gain: " << gain << ", gain_step: " << int(gain_step) << ", slope: " << slope << ", volts: " << volts << std::endl;
-
+
return volts;
}
@@ -283,17 +283,17 @@ static float rf_gain_to_voltage(float gain, double lo_freq){
std::string band = get_band(lo_freq + tvrx_if_freq);
//this is the voltage at the TVRX gain input
- float gain_volts = gain_interp(gain, tvrx_rf_gains_db[band], tvrx_gains_volts);
+ double gain_volts = gain_interp(gain, tvrx_rf_gains_db[band], tvrx_gains_volts);
//this is the voltage at the USRP DAC output
- float dac_volts = gain_volts / opamp_gain;
-
- dac_volts = std::clip<float>(dac_volts, 0.0, 3.3);
+ double dac_volts = gain_volts / opamp_gain;
+
+ dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
if (tvrx_debug) std::cerr << boost::format(
"tvrx RF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
- return dac_volts;
+ return float(dac_volts);
}
/*!
@@ -306,17 +306,17 @@ static float rf_gain_to_voltage(float gain, double lo_freq){
static float if_gain_to_voltage(float gain){
//clip the input
gain = std::clip<float>(gain, get_tvrx_gain_ranges()["IF"].min, get_tvrx_gain_ranges()["IF"].max);
-
- float gain_volts = gain_interp(gain, tvrx_if_gains_db, tvrx_gains_volts);
- float dac_volts = gain_volts / opamp_gain;
-
- dac_volts = std::clip<float>(dac_volts, 0.0, 3.3);
+
+ double gain_volts = gain_interp(gain, tvrx_if_gains_db, tvrx_gains_volts);
+ double dac_volts = gain_volts / opamp_gain;
+
+ dac_volts = std::clip<double>(dac_volts, 0.0, 3.3);
if (tvrx_debug) std::cerr << boost::format(
"tvrx IF AGC gain: %f dB, dac_volts: %f V"
) % gain % dac_volts << std::endl;
- return dac_volts;
+ return float(dac_volts);
}
void tvrx::set_gain(float gain, const std::string &name){
@@ -337,27 +337,27 @@ void tvrx::set_gain(float gain, const std::string &name){
*/
void tvrx::set_freq(double freq) {
- freq = std::clip<float>(freq, tvrx_freq_range.min, tvrx_freq_range.max);
+ freq = std::clip<double>(freq, tvrx_freq_range.min, tvrx_freq_range.max);
std::string prev_band = get_band(_lo_freq - tvrx_if_freq);
std::string new_band = get_band(freq);
-
+
double target_lo_freq = freq + tvrx_if_freq; //the desired LO freq for high-side mixing
double f_ref = reference_freq / double(reference_divider); //your tuning step size
-
+
int divisor = int((target_lo_freq + (f_ref * 4.0)) / (f_ref * 8)); //the divisor we'll use
double actual_lo_freq = (f_ref * 8 * divisor); //the LO freq we'll actually get
-
+
if((divisor & ~0x7fff)) UHD_THROW_INVALID_CODE_PATH();
-
+
//now we update the registers
_tuner_4937di5_regs.db1 = (divisor >> 8) & 0xff;
_tuner_4937di5_regs.db2 = divisor & 0xff;
-
+
if(new_band == "VHFLO") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_VHFLO;
else if(new_band == "VHFHI") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_VHFHI;
else if(new_band == "UHF") _tuner_4937di5_regs.bandsel = tuner_4937di5_regs_t::BANDSEL_UHF;
else UHD_THROW_INVALID_CODE_PATH();
-
+
_tuner_4937di5_regs.power = tuner_4937di5_regs_t::POWER_OFF;
update_regs();
@@ -365,10 +365,10 @@ void tvrx::set_freq(double freq) {
//we do this because the gains are different for different band settings
//not FAR off, but we do this to be consistent
if(prev_band != new_band) set_gain(_gains["RF"], "RF");
-
- if(tvrx_debug)
+
+ if(tvrx_debug)
std::cout << boost::format("set_freq: target LO: %f f_ref: %f divisor: %i actual LO: %f") % target_lo_freq % f_ref % divisor % actual_lo_freq << std::endl;
-
+
_lo_freq = actual_lo_freq; //for rx props
}
@@ -422,7 +422,7 @@ void tvrx::rx_get(const wax::obj &key_, wax::obj &val){
return;
case SUBDEV_PROP_FREQ:
- /*
+ /*
* so here we have to do some magic. because the TVRX uses a relatively high IF,
* we have to watch the sample rate to see if the IF will be aliased
* or if it will fall within Nyquist.