aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Meserve <mark.meserve@ni.com>2017-02-03 16:25:34 -0600
committerMartin Braun <martin.braun@ettus.com>2017-02-20 17:39:02 -0800
commit454307a8845a3bc697531df5fd2e245233ed5218 (patch)
tree61d74e982add5d0d276b7807485a70937b5be0f2
parentf3f9d95476e870c85ca1b0dfa9cee7a951800f87 (diff)
downloaduhd-454307a8845a3bc697531df5fd2e245233ed5218.tar.gz
uhd-454307a8845a3bc697531df5fd2e245233ed5218.tar.bz2
uhd-454307a8845a3bc697531df5fd2e245233ed5218.zip
Revise calculation of ADF5355 FRAC2 register
Corrected residue formula Fixed cast to uint16_t that was behaving differently in msvc14 32-bit vs 64-bit
-rw-r--r--host/lib/usrp/common/adf5355.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/host/lib/usrp/common/adf5355.cpp b/host/lib/usrp/common/adf5355.cpp
index e3fd66bc2..80c300d47 100644
--- a/host/lib/usrp/common/adf5355.cpp
+++ b/host/lib/usrp/common/adf5355.cpp
@@ -48,6 +48,7 @@ static const double ADF5355_PHASE_RESYNC_TIME = 400e-6;
static const uint32_t ADF5355_MOD1 = 16777216;
static const uint32_t ADF5355_MAX_MOD2 = 16384;
+static const uint32_t ADF5355_MAX_FRAC2 = 16384;
//static const uint16_t ADF5355_MIN_INT_PRESCALER_89 = 75;
class adf5355_impl : public adf5355_iface
@@ -261,15 +262,11 @@ public:
double N = prescaler_input_freq / _pfd_freq;
uint16_t INT = static_cast<uint16_t>(floor(N));
uint32_t FRAC1 = static_cast<uint32_t>(floor((N - INT) * ADF5355_MOD1));
- double residue = ADF5355_MOD1 * (N - (INT + FRAC1 / ADF5355_MOD1));
+ double residue = (N - INT) * ADF5355_MOD1 - FRAC1;
double gcd = boost::math::gcd(static_cast<int>(_pfd_freq), static_cast<int>(freq_resolution));
- uint16_t MOD2 = static_cast<uint16_t>(floor(_pfd_freq / gcd));
-
- if (MOD2 > ADF5355_MAX_MOD2) {
- MOD2 = ADF5355_MAX_MOD2;
- }
- uint16_t FRAC2 = ceil(residue * MOD2);
+ uint16_t MOD2 = static_cast<uint16_t>(std::min(floor(_pfd_freq / gcd), static_cast<double>(ADF5355_MAX_MOD2)));
+ uint16_t FRAC2 = static_cast<uint16_t>(std::min(ceil(residue * MOD2), static_cast<double>(ADF5355_MAX_FRAC2)));
double coerced_vco_freq = _pfd_freq * (
todbl(INT) + (