summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-11-15 14:54:18 -0800
committerJosh Blum <josh@joshknows.com>2011-11-15 14:54:18 -0800
commit317bff29a5358c7bfc576359ab5a3b3fcf30ad10 (patch)
treef08b092049c9dc33786088c62d9baf689622ab66 /host
parentff2e730a0dc7f67241942143c120e02a838f932e (diff)
downloaduhd-317bff29a5358c7bfc576359ab5a3b3fcf30ad10.tar.gz
uhd-317bff29a5358c7bfc576359ab5a3b3fcf30ad10.tar.bz2
uhd-317bff29a5358c7bfc576359ab5a3b3fcf30ad10.zip
uhd: added freq options and common gain setter
Diffstat (limited to 'host')
-rw-r--r--host/lib/usrp/common/apply_corrections.cpp6
-rw-r--r--host/utils/usrp_cal_rx_iq_balance.cpp20
-rw-r--r--host/utils/usrp_cal_tx_dc_offset.cpp22
-rw-r--r--host/utils/usrp_cal_tx_iq_balance.cpp20
-rw-r--r--host/utils/usrp_cal_utils.hpp27
5 files changed, 64 insertions, 31 deletions
diff --git a/host/lib/usrp/common/apply_corrections.cpp b/host/lib/usrp/common/apply_corrections.cpp
index e3ec9baab..6aee00753 100644
--- a/host/lib/usrp/common/apply_corrections.cpp
+++ b/host/lib/usrp/common/apply_corrections.cpp
@@ -58,6 +58,7 @@ static std::complex<double> get_fe_dc_correction(
const std::string &key, const double lo_freq
){
const std::vector<fe_cal_t> &datas = fe_cal_cache[key];
+ if (datas.empty()) throw uhd::runtime_error("empty calibration table " + key);
//search for lo freq
size_t lo_index = 0;
@@ -84,6 +85,7 @@ static std::complex<double> get_fe_iq_correction(
const std::string &key, const double lo_freq
){
const std::vector<fe_cal_t> &datas = fe_cal_cache[key];
+ if (datas.empty()) throw uhd::runtime_error("empty calibration table " + key);
//search for lo freq
size_t lo_index = 0;
@@ -153,11 +155,11 @@ static void apply_fe_corrections(
}
- if (file_prefix.find("dc") != std::string::npos){
+ if (file_prefix.find("dc_cal") != std::string::npos){
sub_tree->access<std::complex<double> >(fe_path)
.set(get_fe_dc_correction(cal_data_path.string(), lo_freq));
}
- else if (file_prefix.find("iq") != std::string::npos){
+ else if (file_prefix.find("iq_cal") != std::string::npos){
sub_tree->access<std::complex<double> >(fe_path)
.set(get_fe_iq_correction(cal_data_path.string(), lo_freq));
}
diff --git a/host/utils/usrp_cal_rx_iq_balance.cpp b/host/utils/usrp_cal_rx_iq_balance.cpp
index 7b7fdaec9..7924323a5 100644
--- a/host/utils/usrp_cal_rx_iq_balance.cpp
+++ b/host/utils/usrp_cal_rx_iq_balance.cpp
@@ -115,7 +115,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_ampl, tx_offset, freq_step, tx_gain, rx_gain;
+ double rate, tx_wave_ampl, tx_offset;
+ double freq_start, freq_stop, freq_step;
size_t nsamps;
po::options_description desc("Allowed options");
@@ -126,8 +127,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("rate", po::value<double>(&rate)->default_value(12.5e6), "RX and TX sample rate in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("tx_offset", po::value<double>(&tx_offset)->default_value(.9344e6), "TX LO offset from the RX LO in Hz")
- ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB")
- ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB")
+ ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)")
+ ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)")
("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz")
("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture")
;
@@ -157,14 +158,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
+ //set optimum gain settings
+ set_optimum_gain(usrp);
+
//set the sample rates
usrp->set_rx_rate(rate);
usrp->set_tx_rate(rate);
- //set midrange rx gain, default 0 tx gain
- usrp->set_tx_gain(tx_gain);
- usrp->set_rx_gain(rx_gain);
-
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
@@ -179,8 +179,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//store the results here
std::vector<result_t> results;
- const uhd::meta_range_t freq_range = usrp->get_rx_freq_range();
- for (double rx_lo_i = freq_range.start()+50e6; rx_lo_i < freq_range.stop()-50e6; rx_lo_i += freq_step){
+ if (not vm.count("freq_start")) freq_start = usrp->get_rx_freq_range().start() + 50e6;
+ if (not vm.count("freq_stop")) freq_stop = usrp->get_rx_freq_range().stop() - 50e6;
+
+ for (double rx_lo_i = freq_start; rx_lo_i <= freq_stop; rx_lo_i += freq_step){
const double rx_lo = tune_rx_and_tx(usrp, rx_lo_i, tx_offset);
//frequency constants for this tune event
diff --git a/host/utils/usrp_cal_tx_dc_offset.cpp b/host/utils/usrp_cal_tx_dc_offset.cpp
index 2c75242c7..8615e231c 100644
--- a/host/utils/usrp_cal_tx_dc_offset.cpp
+++ b/host/utils/usrp_cal_tx_dc_offset.cpp
@@ -116,7 +116,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_freq, tx_wave_ampl, rx_offset, freq_step, tx_gain, rx_gain;
+ double rate, tx_wave_freq, tx_wave_ampl, rx_offset;
+ double freq_start, freq_stop, freq_step;
size_t nsamps;
po::options_description desc("Allowed options");
@@ -128,8 +129,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz")
- ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB")
- ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB")
+ ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)")
+ ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)")
("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz")
("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture")
;
@@ -159,14 +160,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
+ //set optimum gain settings
+ set_optimum_gain(usrp);
+
//set the sample rates
usrp->set_rx_rate(rate);
usrp->set_tx_rate(rate);
- //set midrange rx gain, default 0 tx gain
- usrp->set_tx_gain(tx_gain);
- usrp->set_rx_gain(rx_gain);
-
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
@@ -181,8 +181,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//store the results here
std::vector<result_t> results;
- const uhd::meta_range_t freq_range = usrp->get_tx_freq_range();
- for (double tx_lo_i = freq_range.start()+50e6; tx_lo_i < freq_range.stop()-50e6; tx_lo_i += freq_step){
+ if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6;
+ if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6;
+
+ for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){
const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset);
//frequency constants for this tune event
@@ -235,7 +237,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
dc_q_stop = best_dc_q + dc_q_step;
}
- if (lowest_offset < -90){ //most likely valid, keep result
+ if (lowest_offset < initial_dc_dbrms){ //most likely valid, keep result
result_t result;
result.freq = tx_lo;
result.real_corr = best_dc_i;
diff --git a/host/utils/usrp_cal_tx_iq_balance.cpp b/host/utils/usrp_cal_tx_iq_balance.cpp
index c7cda49c7..29b6f5ede 100644
--- a/host/utils/usrp_cal_tx_iq_balance.cpp
+++ b/host/utils/usrp_cal_tx_iq_balance.cpp
@@ -116,7 +116,8 @@ static void capture_samples(uhd::usrp::multi_usrp::sptr usrp, uhd::rx_streamer::
**********************************************************************/
int UHD_SAFE_MAIN(int argc, char *argv[]){
std::string args;
- double rate, tx_wave_freq, tx_wave_ampl, rx_offset, freq_step, tx_gain, rx_gain;
+ double rate, tx_wave_freq, tx_wave_ampl, rx_offset;
+ double freq_start, freq_stop, freq_step;
size_t nsamps;
po::options_description desc("Allowed options");
@@ -128,8 +129,8 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
("tx_wave_freq", po::value<double>(&tx_wave_freq)->default_value(507.123e3), "Transmit wave frequency in Hz")
("tx_wave_ampl", po::value<double>(&tx_wave_ampl)->default_value(0.7), "Transmit wave amplitude in counts")
("rx_offset", po::value<double>(&rx_offset)->default_value(.9344e6), "RX LO offset from the TX LO in Hz")
- ("tx_gain", po::value<double>(&tx_gain)->default_value(0), "TX gain in dB")
- ("rx_gain", po::value<double>(&rx_gain)->default_value(0), "RX gain in dB")
+ ("freq_start", po::value<double>(&freq_start), "Frequency start in Hz (do not specify for default)")
+ ("freq_stop", po::value<double>(&freq_stop), "Frequency stop in Hz (do not specify for default)")
("freq_step", po::value<double>(&freq_step)->default_value(default_freq_step), "Step size for LO sweep in Hz")
("nsamps", po::value<size_t>(&nsamps)->default_value(default_num_samps), "Samples per data capture")
;
@@ -159,14 +160,13 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_rx_antenna("CAL");
usrp->set_tx_antenna("CAL");
+ //set optimum gain settings
+ set_optimum_gain(usrp);
+
//set the sample rates
usrp->set_rx_rate(rate);
usrp->set_tx_rate(rate);
- //set midrange rx gain, default 0 tx gain
- usrp->set_tx_gain(tx_gain);
- usrp->set_rx_gain(rx_gain);
-
//create a receive streamer
uhd::stream_args_t stream_args("fc32"); //complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
@@ -181,8 +181,10 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
//store the results here
std::vector<result_t> results;
- const uhd::meta_range_t freq_range = usrp->get_tx_freq_range();
- for (double tx_lo_i = freq_range.start()+50e6; tx_lo_i < freq_range.stop()-50e6; tx_lo_i += freq_step){
+ if (not vm.count("freq_start")) freq_start = usrp->get_tx_freq_range().start() + 50e6;
+ if (not vm.count("freq_stop")) freq_stop = usrp->get_tx_freq_range().stop() - 50e6;
+
+ for (double tx_lo_i = freq_start; tx_lo_i <= freq_stop; tx_lo_i += freq_step){
const double tx_lo = tune_rx_and_tx(usrp, tx_lo_i, rx_offset);
//frequency constants for this tune event
diff --git a/host/utils/usrp_cal_utils.hpp b/host/utils/usrp_cal_utils.hpp
index c08d869ed..5378b0d69 100644
--- a/host/utils/usrp_cal_utils.hpp
+++ b/host/utils/usrp_cal_utils.hpp
@@ -39,10 +39,35 @@ static const size_t wave_table_len = 8192;
static const size_t num_search_steps = 5;
static const size_t num_search_iters = 7;
static const size_t skip_initial_samps = 20;
-static const double default_freq_step = 13.7e6;
+static const double default_freq_step = 7.3e6;
static const size_t default_num_samps = 10000;
/***********************************************************************
+ * Determine gain settings
+ **********************************************************************/
+static inline void set_optimum_gain(uhd::usrp::multi_usrp::sptr usrp){
+ uhd::property_tree::sptr tree = usrp->get_device()->get_tree();
+ const uhd::fs_path tx_fe_path = "/mboards/0/dboards/A/tx_frontends/0";
+ const std::string tx_name = tree->access<std::string>(tx_fe_path / "name").get();
+ if (tx_name.find("WBX") != std::string::npos or tx_name.find("SBX") != std::string::npos){
+ usrp->set_tx_gain(0);
+ }
+ else{
+ throw std::runtime_error("self-calibration is not supported for this hardware");
+ }
+
+ const uhd::fs_path rx_fe_path = "/mboards/0/dboards/A/tx_frontends/0";
+ const std::string rx_name = tree->access<std::string>(rx_fe_path / "name").get();
+ if (rx_name.find("WBX") != std::string::npos or rx_name.find("SBX") != std::string::npos){
+ usrp->set_rx_gain(25);
+ }
+ else{
+ throw std::runtime_error("self-calibration is not supported for this hardware");
+ }
+
+}
+
+/***********************************************************************
* Sinusoid wave table
**********************************************************************/
static inline std::vector<std::complex<float> > gen_table(void){