From 3a6de231c6782655bfe7a8a5bdb1d97a744c2958 Mon Sep 17 00:00:00 2001 From: TT Date: Sat, 5 Oct 2019 21:11:19 +0900 Subject: [PATCH] fix: remove glitch on interpolation --- main.c | 9 ++++++++- si5351.c | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index e4f281e..4345369 100644 --- a/main.c +++ b/main.c @@ -43,8 +43,8 @@ bool sweep(bool break_on_operation); static MUTEX_DECL(mutex); #define DRIVE_STRENGTH_AUTO (-1) -//#define FREQ_HARMONICS 300000000 #define FREQ_HARMONICS (config.harmonic_freq_threshold) +#define IS_HARMONIC_MODE(f) ((f) > FREQ_HARMONICS) int32_t frequency_offset = 5000; int32_t frequency = 10000000; @@ -1292,6 +1292,13 @@ cal_interpolate(int s) // found f between freqs at j and j+1 float k1 = (float)(f - src->_frequencies[j]) / (src->_frequencies[j+1] - src->_frequencies[j]); + + // avoid glitch between freqs in different harmonics mode + if (IS_HARMONIC_MODE(src->_frequencies[j]) != IS_HARMONIC_MODE(src->_frequencies[j+1])) { + // assume f[j] < f[j+1] + k1 = IS_HARMONIC_MODE(f) ? 1.0 : 0.0; + } + float k0 = 1.0 - k1; for (eterm = 0; eterm < 5; eterm++) { cal_data[eterm][i][0] = src->_cal_data[eterm][j][0] * k0 + src->_cal_data[eterm][j+1][0] * k1; diff --git a/si5351.c b/si5351.c index 9dae5c2..6e66e8a 100644 --- a/si5351.c +++ b/si5351.c @@ -310,10 +310,10 @@ si5351_set_frequency_with_offset(int freq, int offset, uint8_t drive_strength) int delay = 3; uint32_t ofreq = freq + offset; uint32_t rdiv = SI5351_R_DIV_1; - if (freq > config.harmonic_freq_threshold * 3) { + if (freq >= config.harmonic_freq_threshold * 3) { freq /= 5; ofreq /= 7; - } else if (freq > config.harmonic_freq_threshold) { + } else if (freq >= config.harmonic_freq_threshold) { freq /= 3; ofreq /= 5; }