From 4974774f823d33b28411386f720c6a40311d0897 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 25 Aug 2015 17:56:03 -0700 Subject: [PATCH] Simplify PLL math when correcting for PPM. --- firmware/application/clock_manager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firmware/application/clock_manager.cpp b/firmware/application/clock_manager.cpp index 09404806..fdd41b01 100644 --- a/firmware/application/clock_manager.cpp +++ b/firmware/application/clock_manager.cpp @@ -370,9 +370,10 @@ void ClockManager::set_sampling_frequency(const uint32_t frequency) { void ClockManager::set_reference_ppb(const int32_t ppb) { constexpr uint32_t pll_multiplier = si5351_pll_xtal_25m.a; + constexpr uint32_t denominator = 1000000 / pll_multiplier; const uint32_t new_a = (ppb >= 0) ? pll_multiplier : (pll_multiplier - 1); - const uint32_t new_b = (ppb >= 0) ? (ppb * pll_multiplier / 1000) : (1000000 + (ppb * pll_multiplier / 1000)); - const uint32_t new_c = (ppb == 0) ? 1 : 1000000; + const uint32_t new_b = (ppb >= 0) ? (ppb / 1000) : (denominator + (ppb / 1000)); + const uint32_t new_c = (ppb == 0) ? 1 : denominator; const si5351::PLL pll { .f_in = si5351_inputs.f_xtal,