From 2d3ac3cb1e82da9cc3da8dccd340207803e0f834 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 21 Jun 2023 00:28:58 +0200 Subject: [PATCH] fix correction --- SoapyHifiBerrySettings.cpp | 9 ++++++++- si5351.cpp | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SoapyHifiBerrySettings.cpp b/SoapyHifiBerrySettings.cpp index 9f6fe31..c3984b2 100644 --- a/SoapyHifiBerrySettings.cpp +++ b/SoapyHifiBerrySettings.cpp @@ -44,6 +44,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) vfoIQMode = Single; disableOutput = true; uptr_cfg = make_unique(); + multiplier = 0; if (!uptr_cfg->loadFromFile("hifiberry.cfg")) { uptr_cfg->setDefaultOptions(defaultOptions); @@ -51,7 +52,8 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) } multiplier = SoapyHifiBerry::get_int("si5351", "multiplier"); if (!multiplier) - multiplier = 4; + multiplier = 1; + int samplerate = SoapyHifiBerry::get_int("sound", "samplerate"); int driveConfig = SoapyHifiBerry::get_int("si5351", "rxdrive"); switch (driveConfig) @@ -100,6 +102,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) } } int corr = get_int("si5351", "correction"); + int corrtx = get_int("si5351", "correctiontx"); string dev = get_string("sound", "device"); uptr_HifiBerryAudioOutputput->open(dev); @@ -156,6 +159,8 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) } if (vfoIQMode == Single) { + if (!multiplier) + multiplier = 4; cout << "si5351 found" << endl; pSI5351->set_correction((long)corr, SI5351_PLL_INPUT_XO); pSI5351->drive_strength(CLK_VFO_RX, rxDrive); @@ -183,6 +188,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) pSI5351 = make_unique("/dev/i2c-1", SI5351_BUS_BASE_ADDR, CLK_VFO_I, CLK_VFO_Q); if (pSI5351->init(SI5351_CRYSTAL_LOAD_8PF, 0, 0)) { + pSI5351->set_correction((long)corr, SI5351_PLL_INPUT_XO); pSI5351->drive_strength(CLK_VFO_I, rxDrive); pSI5351->drive_strength(CLK_VFO_Q, rxDrive); pSI5351->output_enable(CLK_VFO_I, 1); @@ -194,6 +200,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args) pSI5351tx = make_unique("/dev/i2c-1", SI5351_BUS_BASE_ADDR, CLK_VFO_I, CLK_VFO_Q); if (pSI5351tx->init(SI5351_CRYSTAL_LOAD_8PF, 0, 0, pSI5351->getFileHandle())) { + pSI5351tx->set_correction((long)corrtx, SI5351_PLL_INPUT_XO); pSI5351tx->drive_strength(CLK_VFO_I, txDrive); pSI5351tx->drive_strength(CLK_VFO_Q, txDrive); pSI5351tx->output_enable(CLK_VFO_I, disableOutput ? (0) : (1)); diff --git a/si5351.cpp b/si5351.cpp index b8c9e1b..32e9829 100644 --- a/si5351.cpp +++ b/si5351.cpp @@ -1876,8 +1876,6 @@ void Si5351::setIQFrequency(uint64_t freq) uint64_t f = freq * 100ULL; uint64_t pllFreq = freq * mult * 100ULL; - int32_t correction = get_correction(SI5351_PLL_INPUT_XO); - pllFreq = pllFreq + (int32_t)((((((int64_t)correction) << 31) / 1000000000LL) * pllFreq) >> 31); printf("mult = %d pll = %ld Mhz freq %ld\n", mult, pllFreq / 100L, freq); set_iq_freq_manual(f, pllFreq, iclock, qclock);