diff options
| author | michael-west <michael.west@ettus.com> | 2021-02-01 12:49:21 -0800 | 
|---|---|---|
| committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-02-04 13:48:46 -0600 | 
| commit | fbb0b0998992306375d179fb4fd0d25385689112 (patch) | |
| tree | 0697ed79de857dc0b67c719c5f76115266c0d9d6 /host/lib | |
| parent | c5d7e88a9ec0c2c720993977a67cfb6263ec8d20 (diff) | |
| download | uhd-fbb0b0998992306375d179fb4fd0d25385689112.tar.gz uhd-fbb0b0998992306375d179fb4fd0d25385689112.tar.bz2 uhd-fbb0b0998992306375d179fb4fd0d25385689112.zip | |
ADF535x: Change freq_resolution to mod2
The freq_resolution parameter to the set_frequency() method was
confusing.  Changing it to the mod2 value clarifies the intention and
makes the math to reduce the FRAC2 and MOD2 values much easier to read
and maintain.
Signed-off-by: michael-west <michael.west@ettus.com>
Diffstat (limited to 'host/lib')
| -rw-r--r-- | host/lib/include/uhdlib/usrp/common/adf535x.hpp | 46 | ||||
| -rw-r--r-- | host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp | 8 | 
2 files changed, 28 insertions, 26 deletions
| diff --git a/host/lib/include/uhdlib/usrp/common/adf535x.hpp b/host/lib/include/uhdlib/usrp/common/adf535x.hpp index 61dd88451..20255ad00 100644 --- a/host/lib/include/uhdlib/usrp/common/adf535x.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf535x.hpp @@ -68,7 +68,7 @@ public:      virtual void set_muxout_mode(const muxout_t mode) = 0;      virtual double set_frequency(const double target_freq, -        const double freq_resolution, +        const uint32_t mod2 = 2,          const bool flush = false) = 0;      virtual double set_charge_pump_current( @@ -227,10 +227,10 @@ public:      }      double set_frequency(const double target_freq, -        const double freq_resolution, +        const uint32_t mod2 = 2,          const bool flush = false) override      { -        return _set_frequency(target_freq, freq_resolution, flush); +        return _set_frequency(target_freq, mod2, flush);      }      double set_charge_pump_current(const double current, const bool flush) override @@ -340,7 +340,7 @@ public:  protected:      uint8_t _set_vco_band_div(double); -    double _set_frequency(double, double, bool); +    double _set_frequency(double, uint32_t, bool);      uhd::meta_range_t _get_charge_pump_current_range();      void _commit(); @@ -367,13 +367,13 @@ inline uint8_t adf535x_impl<adf5355_regs_t>::_set_vco_band_div(double pfd_freq)  template <>  inline double adf535x_impl<adf5355_regs_t>::_set_frequency( -    double target_freq, double freq_resolution, bool flush) +    double target_freq, uint32_t mod2, bool flush)  {      if (target_freq > ADF535X_MAX_OUT_FREQ or target_freq < ADF535X_MIN_OUT_FREQ) {          throw uhd::runtime_error("requested frequency out of range.");      } -    if ((uint32_t)freq_resolution == 0) { -        throw uhd::runtime_error("requested resolution cannot be less than 1."); +    if (mod2 < 2 or mod2 > ADF5355_MAX_MOD2) { +        throw uhd::runtime_error("requested mod2 out of range.");      }      /* Calculate target VCOout frequency */ @@ -422,12 +422,13 @@ inline double adf535x_impl<adf5355_regs_t>::_set_frequency(      const auto FRAC1     = static_cast<uint32_t>(floor((N - INT) * ADF535X_MOD1));      const double residue = (N - INT) * ADF535X_MOD1 - FRAC1; -    const double gcd = double( -        uhd::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution))); -    const auto MOD2 = static_cast<uint16_t>( -        std::min(floor(_pfd_freq / gcd), static_cast<double>(ADF5355_MAX_MOD2))); -    const auto FRAC2 = static_cast<uint16_t>( -        std::min(ceil(residue * MOD2), static_cast<double>(ADF5355_MAX_FRAC2))); +    // The data sheet recommends reducing FRAC2 and MOD2 to the lowest possible values +    const auto frac2 = static_cast<uint16_t>( +        std::min(ceil(residue * mod2), static_cast<double>(ADF5355_MAX_FRAC2))); +    const auto gcd =  +        uhd::math::gcd(static_cast<int>(frac2), static_cast<int>(mod2)); +    const auto FRAC2 = frac2 == 0 ? 0 : frac2 / gcd; +    const auto MOD2 = frac2 == 0 ? 2 : mod2 / gcd;      const double coerced_vco_freq =          _pfd_freq * (_fb_after_divider ? rf_divider : 1) @@ -510,13 +511,13 @@ inline uint8_t adf535x_impl<adf5356_regs_t>::_set_vco_band_div(double pfd_freq)  template <>  inline double adf535x_impl<adf5356_regs_t>::_set_frequency( -    double target_freq, double freq_resolution, bool flush) +    double target_freq, uint32_t mod2, bool flush)  {      if (target_freq > ADF535X_MAX_OUT_FREQ or target_freq < ADF535X_MIN_OUT_FREQ) {          throw uhd::runtime_error("requested frequency out of range.");      } -    if ((uint32_t)freq_resolution == 0) { -        throw uhd::runtime_error("requested resolution cannot be less than 1."); +    if (mod2 < 2 or mod2 > ADF5355_MAX_MOD2) { +        throw uhd::runtime_error("requested mod2 out of range.");      }      /* Calculate target VCOout frequency */ @@ -565,12 +566,13 @@ inline double adf535x_impl<adf5356_regs_t>::_set_frequency(      const auto FRAC1     = static_cast<uint32_t>(floor((N - INT) * ADF535X_MOD1));      const double residue = (N - INT) * ADF535X_MOD1 - FRAC1; -    const double gcd = double( -        uhd::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution))); -    const auto MOD2 = static_cast<uint32_t>( -        std::min(floor(_pfd_freq / gcd), static_cast<double>(ADF5356_MAX_MOD2))); -    const auto FRAC2 = static_cast<uint32_t>( -        std::min(round(residue * MOD2), static_cast<double>(ADF5356_MAX_FRAC2))); +    // The data sheet recommends reducing FRAC2 and MOD2 to the lowest possible values +    const auto frac2 = static_cast<uint16_t>( +        std::min(ceil(residue * mod2), static_cast<double>(ADF5356_MAX_FRAC2))); +    const auto gcd = +        uhd::math::gcd(static_cast<int>(frac2), static_cast<int>(mod2)); +    const auto FRAC2 = frac2 == 0 ? 0 : frac2 / gcd; +    const auto MOD2 = frac2 == 0 ? 2 : mod2 / gcd;      const double coerced_vco_freq =          _pfd_freq * (_fb_after_divider ? rf_divider : 1) diff --git a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp index 315861cd9..c337af2f9 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp @@ -33,6 +33,7 @@ inline uint32_t bool2bin(bool x)  const double TWINRX_REV_AB_PFD_FREQ = 6.25e6;  const double TWINRX_REV_C_PFD_FREQ  = 12.5e6;  const double TWINRX_SPI_CLOCK_FREQ  = 3e6; +const uint32_t TWINRX_LO1_MOD2      = 2;  } // namespace  class twinrx_ctrl_impl : public twinrx_ctrl @@ -137,7 +138,7 @@ public:              _lo1_iface[i]->set_reference_freq(                  _db_iface->get_clock_rate(dboard_iface::UNIT_TX));              _lo1_iface[i]->set_muxout_mode(adf535x_iface::MUXOUT_DLD); -            _lo1_iface[i]->set_frequency(3e9, _lo1_pfd_freq / 2); +            _lo1_iface[i]->set_frequency(3e9, TWINRX_LO1_MOD2);              // LO2              _lo2_iface[i] = @@ -562,17 +563,16 @@ public:      double set_lo1_synth_freq(channel_t ch, double freq, bool commit = true)      {          boost::lock_guard<boost::mutex> lock(_mutex); -        static const double RESOLUTION = _lo1_pfd_freq / 2;          double coerced_freq = 0.0;          if (ch == CH1 or ch == BOTH) {              coerced_freq = -                _lo1_iface[size_t(CH1)]->set_frequency(freq, RESOLUTION, false); +                _lo1_iface[size_t(CH1)]->set_frequency(freq, TWINRX_LO1_MOD2, false);              _lo1_freq[size_t(CH1)] = tune_freq_t(freq);          }          if (ch == CH2 or ch == BOTH) {              coerced_freq = -                _lo1_iface[size_t(CH2)]->set_frequency(freq, RESOLUTION, false); +                _lo1_iface[size_t(CH2)]->set_frequency(freq, TWINRX_LO1_MOD2, false);              _lo1_freq[size_t(CH2)] = tune_freq_t(freq);          } | 
