Skip to content

Commit

Permalink
fix correction
Browse files Browse the repository at this point in the history
  • Loading branch information
paulh002 committed Jun 20, 2023
1 parent 2e5f27a commit 2d3ac3c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 8 additions & 1 deletion SoapyHifiBerrySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
vfoIQMode = Single;
disableOutput = true;
uptr_cfg = make_unique<cfg::File>();
multiplier = 0;
if (!uptr_cfg->loadFromFile("hifiberry.cfg"))
{
uptr_cfg->setDefaultOptions(defaultOptions);
uptr_cfg->writeToFile("hifiberry.cfg");
}
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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -183,6 +188,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
pSI5351 = make_unique<Si5351>("/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);
Expand All @@ -194,6 +200,7 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
pSI5351tx = make_unique<Si5351>("/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));
Expand Down
2 changes: 0 additions & 2 deletions si5351.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2d3ac3c

Please sign in to comment.