diff --git a/changelog.txt b/changelog.txt index 9b6ddf9..87706ee 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,8 @@ +V1.4330 2026-11-17 For all tinySA Ultra models +- Internal spurs of the tinySA Ultra+ (the models with the 1070 MHz IF filter): the lines caused by harmonics of the LO near 267, 356, 534, 712 and 1604 MHz are avoided per sweep point from the actual LO setting, with an IF shift of at most 450 kHz instead of 0.5 or 1.5 MHz. The affected points read within about 1 dB instead of up to 4 dB low, a unit whose IF filter sits 0.5 MHz below the stored centre is no longer 20-26 dB deaf around 534 MHz at RBW 300 kHz and above, and the 712 MHz and 356 MHz lines that stayed at RBW 10 kHz and below are gone. The 1604 MHz line is removed as well while spur reduction is off (Ultra+ only) +- Fast sweep (SWEEP SETTINGS > FAST) no longer loses the first point after a full retune of the receiver +- Console: "if1" accepts the 1070 MHz IF of the Ultra+ (it refused every value) (Ultra+ only) + V1.4321 2026-11-12 For all tinySA models - Console: "ui off" stops all drawing on the screen while a PC is in control, so commands no longer wait for the screen to be redrawn (e.g. 2 ms instead of about 120 ms after a setting). The screen shows "Remote only mode. Touch screen to enable UI", "ui off "text"" adds a line under it, e.g. to tell the tracking generator from the analyzer when a PC uses two tinySA. A touch or a jog press gives the UI back, as do "ui on", unplugging USB, USB DISK mode and the commands that need the user (selftest, touchcal, touchtest, menu); the console then sends "ui on" before the next text reply. While the UI is off, messages such as errors go to the console. "ui" shows the state. It is not stored in the config or in presets and stays off when the mode changes (Ultra only) - Console: "scanraw" no longer sets up the hardware again for every scan, only the RBW and timing of its frequency step: a one point scanraw takes about 2 ms instead of 86 ms on the tinySA basic, and the screen is no longer redrawn after each scanraw. "scanraw {f} {f} 1" (one point at one frequency) takes 2 ms instead of 93 ms on the tinySA basic and 6 ms instead of 40 ms on the Ultra diff --git a/sa_cmd.c b/sa_cmd.c index 6def7ca..17f8447 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -737,7 +737,12 @@ VNA_SHELL_FUNCTION(cmd_if1) return; } else { freq_t a = (freq_t)my_atoui(argv[0]); - if (a!= 0 &&( a < (DEFAULT_IF - (freq_t)80000000) || a>(DEFAULT_IF + (freq_t)80000000))) + freq_t f = DEFAULT_IF; +#ifdef TINYSA4 + if (hw_if) + f = DEFAULT_IF_PLUS; // the 1070 MHz IF of the hw_if units +#endif + if (a!= 0 &&( a < (f - (freq_t)80000000) || a>(f + (freq_t)80000000))) goto usage; config.frequency_IF1 = a; config_save(); diff --git a/sa_core.c b/sa_core.c index 1db339a..1f52195 100644 --- a/sa_core.c +++ b/sa_core.c @@ -96,6 +96,9 @@ int linear_averaging = true; static freq_t old_freq[5] = { 0, 0, 0, 0,0}; static freq_t real_old_freq[5] = { 0, 0, 0, 0,0}; static long real_offset = 0; +#ifdef TINYSA4 +static int old_delta = 0x20000; // Si4468 offset register value set by set_freq() in fast mode +#endif static float old_temp = 0.0; static int LO_spur_shifted; @@ -2660,7 +2663,6 @@ void set_freq(int V, freq_t freq) // translate the requested frequency into a delta = delta >> 1; delta = ((float)delta) / OFFSET_STEP; // Calculate and set the offset register i.s.o programming a new frequency if (delta > - 0x7fff && delta < 0x7fff) { // and requested frequency can be reached by using the offset registers - static int old_delta = 0x20000; if (old_delta != delta) { si_set_offset(delta); // Signal offset changed so RSSI retrieval is delayed for frequency settling old_delta = delta; @@ -2671,6 +2673,7 @@ void set_freq(int V, freq_t freq) // translate the requested frequency into a fast_counter = 0; // Offset tuning not possible real_offset = 0; real_old_freq[V] = SI4463_set_freq(freq); // Not in fast mode + old_delta = 0x20000; // SI4463_set_freq() cleared the offset register } done: #endif @@ -3221,6 +3224,29 @@ static freq_t *spur_table = (freq_t *)static_spur_table; int spur_table_size = STATIC_SPUR_TABLE_SIZE; freq_t spur_IF = static_spur_IF; +// Spur families of the units with the hardware IF (ZS406, ZS407): harmonics of the LO (2L, 3L, 4L) leak into the +// Si4468 and are received through the 3rd, 4th and 5th harmonic of its own LO, which sits SI4468_LOW_IF below +// the receive frequency (bench 2026-11-16/17, doc/spur_reduction_proposal.md). +// With the LO error e and the part c of it the Si4468 takes up, a family's product lands at +// k1 * (lf + e - f) - kc * c - ks * shift from the receive frequency; f is its input frequency at the +// nominal IF, shift an IF shift on top of that, ks = kc - k1. +#define SI4468_LOW_IF 468750 // Si4468 receiver IF: 30 MHz / 64 +#define SPUR_SHIFT_MAX 450000 // largest IF shift: stays inside the BPF with IF1 0.5 MHz off +enum { SPUR_A4, SPUR_C3M, SPUR_C3P, SPUR_B2, SPUR_A3, SPUR_B5, SPUR_FAMILIES }; // 266.95, 355.78, 356.10, 533.91, 712.50, 1603.60 MHz +static uint32_t spur_family_freq[SPUR_FAMILIES]; +static uint32_t spur_family_lo[SPUR_FAMILIES], spur_family_hi[SPUR_FAMILIES]; // inputs that can put a product within D +static const uint8_t spur_family_k1[SPUR_FAMILIES] = { 4, 3, 3, 2, 3, 2 }; +static const uint8_t spur_family_kc[SPUR_FAMILIES] = { 5, 4, 4, 3, 5, 5 }; +static const uint8_t spur_family_ks[SPUR_FAMILIES] = { 1, 1, 1, 1, 2, 3 }; + +// Required distance of a family product from the receive frequency. The RBW filter gives about 47 dB at 2 RBW; +// the strongest family (B2, -73 dBm on the ZS407) needs more where the floor is lower, less at wide RBW. +static int32_t spur_family_D(void) +{ + int d10 = (actual_rbw_x10 >= 3000 ? 15 : actual_rbw_x10 >= 300 ? 20 : actual_rbw_x10 >= 30 ? 25 : 30); // RBW/10 + return (int32_t)actual_rbw_x10 * 10 * d10; // RBW = actual_rbw_x10 * 100 Hz +} + #endif int binary_search(freq_t f) @@ -3341,26 +3367,35 @@ void fill_spur_table(void) // dynamic_spur_table[dynamic_spur_table_size++] = 153000000; // dynamic_spur_table[dynamic_spur_table_size++] = 174600000; // dynamic_spur_table[dynamic_spur_table_size++] = 219000000; - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -spur_factor/2; - if (!hw_if) + if (hw_if) { // all internal spurs of these units are found from the actual LO setting by + // spur_family_offset(); the table stays empty (the former entries IF/4 - 400 kHz, + // 2IF/3 + 160 kHz and 3IF/2 held no line of their own, bench 2026-11-16/17) + spur_family_freq[SPUR_A4] = (corr_IF - 4*SI4468_LOW_IF)/4; + spur_family_freq[SPUR_C3M] = (corr_IF - 5*SI4468_LOW_IF)/3; + spur_family_freq[SPUR_C3P] = (corr_IF - 3*SI4468_LOW_IF)/3; + spur_family_freq[SPUR_B2] = (corr_IF - 4*SI4468_LOW_IF)/2; + spur_family_freq[SPUR_A3] = (2*corr_IF - 4*SI4468_LOW_IF)/3; + spur_family_freq[SPUR_B5] = (3*corr_IF - 4*SI4468_LOW_IF)/2; + int32_t D = spur_family_D(); + for (int i = 0; i < SPUR_FAMILIES; i++) { + uint32_t w = (D + spur_family_ks[i] * SPUR_SHIFT_MAX) / spur_family_k1[i] + 250000; // also with the largest IF shift + spur_family_lo[i] = spur_family_freq[i] - w; + spur_family_hi[i] = spur_family_freq[i] + w; + if ((i == SPUR_C3M || i == SPUR_C3P) && actual_rbw_x10 > 1000) // -98 dBm: below the noise above 100 kHz RBW + spur_family_hi[i] = 0; + } + } else { + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -spur_factor/2; dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 -spur_factor/2 + 60000; - else - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/4 - 400000; - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/3 -spur_factor/3; - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor - 40000; - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor - 20000; - if (actual_rbw_x10 < 3000) { - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor + 10000; - } -// if (actual_rbw_x10 < 1000 && hw_if) { -// dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 - spur_factor + 120000; -// dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 - spur_factor + 170000; -// } - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -spur_factor*2/3; - if (actual_rbw_x10 < 6000 && hw_if) { - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -spur_factor*2/3 + 160000; + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/3 -spur_factor/3; + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor - 40000; + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor - 20000; + if (actual_rbw_x10 < 3000) { + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF/2 -spur_factor + 10000; + } + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*2/3 -spur_factor*2/3; + dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*3/2 -spur_factor*3/2; } - dynamic_spur_table[dynamic_spur_table_size++] = corr_IF*3/2 -spur_factor*3/2; spur_table = dynamic_spur_table; spur_table_size = dynamic_spur_table_size; #if 0 @@ -3412,6 +3447,60 @@ enum {avoid_auto, avoid_off, avoid_on}; void set_avoid(int s) { avoid_setting = s; } + +#define MAX_COMPENSATION 50000 // LO error the Si4468 takes up before the LO is set again + +// True when perform() sets the LO for target_f: set_freq() skips an unchanged target +static bool LO_retune(freq_t target_f) +{ + freq_t L = real_old_freq[ADF4351_LO]; + return (target_f < L - MAX_COMPENSATION || target_f > L + MAX_COMPENSATION) && old_freq[ADF4351_LO] != target_f; +} + +// Correction of the Si4468 frequency for the LO at L instead of target_f +static int32_t LO_IF_correction(freq_t L, freq_t target_f, int inverted_f) +{ + if (!(actual_rbw_x10 < 3000 || setting.frequency_step < 100000)) //TODO always compensate for the moment as this eliminates artifacts at larger RBW + return 0; + int32_t error_f = (int32_t)(L - target_f); + if (inverted_f) + error_f = -error_f; + if (LO_harmonic) + return error_f * setting.harmonic; + if (error_f > actual_rbw_x10 * 5 || error_f < - actual_rbw_x10 * 5) //RBW / 20 + return error_f; + return 0; +} + +// True when lf is in a family window: elsewhere no product comes within 2 RBW +static bool spur_family_window(freq_t lf) +{ + for (int i = 0; i < SPUR_FAMILIES; i++) + if (lf >= spur_family_lo[i] && lf <= spur_family_hi[i]) + return true; + return false; +} + +// Signed offset from the receive frequency of the nearest spur family product with the LO at L, INT32_MAX when +// none is near. target_f = lf + nominal IF + shift. +static int32_t spur_family_offset(freq_t lf, freq_t target_f, freq_t L, int inverted_f, int32_t shift, int *family) +{ + int32_t e = (int32_t)(L - target_f); + int32_t c = LO_IF_correction(L, target_f, inverted_f); + int32_t best = INT32_MAX, dist = INT32_MAX; + for (int i = 0; i < SPUR_FAMILIES; i++) { + if (lf < spur_family_lo[i] || lf > spur_family_hi[i]) + continue; + int32_t o = spur_family_k1[i] * ((int32_t)(lf - spur_family_freq[i]) + e) - spur_family_kc[i] * c - spur_family_ks[i] * shift; + int32_t a = (o < 0 ? -o : o); + if (a < dist) { + dist = a; + best = o; + *family = i; + } + } + return best; +} #endif int avoid_spur(freq_t f) // find if this frequency should be avoided @@ -4660,43 +4749,92 @@ again: // Spur redu } if (signal_path == PATH_LEAKAGE) set_freq(ADF4351_LO, target_f); // Never used as leakage is taken care under direct - else { -#define MAX_COMPENSATION 50000 + else if (hw_if && lf >= spur_family_lo[SPUR_A4] && lf <= spur_family_hi[SPUR_B5] // families sorted by frequency + && spur_family_window(lf) && setting.mode == M_LOW && (signal_path == PATH_LOW || signal_path == PATH_ULTRA) + && !tracking && setting.auto_IF && config.frequency_IF2 == 0 + && avoid_setting == avoid_auto && !in_selftest && !S_STATE(setting.spur_removal) && setting.below_IF == S_AUTO_OFF + && !LO_shifting && !LO_spur_shifted) { + // Plan the LO, move the spur family products it would put in the RBW filter, then set it + ADF4351_plan_t plan; + bool retune = LO_retune(target_f); + freq_t L = (retune ? ADF4351_plan_frequency(target_f, &plan) : real_old_freq[ADF4351_LO]); + int family = -1; + int32_t o = spur_family_offset(lf, target_f, L, inverted_f, 0, &family); + int32_t D = spur_family_D(); + if (o != INT32_MAX && o < D && o > -D && (!debug_avoid || debug_avoid_second)) { + // With the LO exactly at target_f the product sits at o_ref; it moves by -ks for every Hz the LO is set + // higher. Find the LO grid point nearest to target_f, in either direction, that puts the product at least D + // away, and shift the IF by that LO move: the Si4468 then needs no compensation (IF_rx = L' - lf). + int ks = spur_family_ks[family]; + int f2; + int32_t o_ref = spur_family_offset(lf, target_f, target_f, inverted_f, 0, &f2); + int32_t need[2] = { (o_ref + D + ks - 1) / ks, -((D - o_ref + ks - 1) / ks) }; // LO above / below target_f + int32_t nudge = (D / 8 > 2500 ? D / 8 : 2500); + ADF4351_plan_t best_plan = {0}; + freq_t best_f = target_f; + int32_t best_s = 0, best_cost = INT32_MAX, best_a = (o < 0 ? -o : o); + for (int dir = 0; dir < 2; dir++) { + int32_t s = need[dir]; + for (int tries = 0; tries < 3; tries++) { + if (s > SPUR_SHIFT_MAX || s < -SPUR_SHIFT_MAX) + break; + ADF4351_plan_t p; + int32_t dL = (int32_t)(ADF4351_plan_frequency(target_f + s, &p) - target_f); + int32_t o2 = o_ref - ks * dL; + int32_t a2 = (o2 < 0 ? -o2 : o2), cost = (dL < 0 ? -dL : dL); + if (a2 >= D) { + if (cost < best_cost && cost <= SPUR_SHIFT_MAX) { + best_cost = cost; best_s = dL; best_f = target_f + dL; best_plan = p; best_a = a2; + } + break; + } + s += (dir == 0 ? nudge : -nudge); // the grid rounded the LO short of the needed move + } + } + if (best_cost == INT32_MAX) { // nothing within the budget: the budget edge that helps most + for (int dir = 0; dir < 2; dir++) { + int32_t s = (dir == 0 ? SPUR_SHIFT_MAX : -SPUR_SHIFT_MAX); + ADF4351_plan_t p; + int32_t dL = (int32_t)(ADF4351_plan_frequency(target_f + s, &p) - target_f); + int32_t o2 = o_ref - ks * dL; + int32_t a2 = (o2 < 0 ? -o2 : o2); + if (a2 > best_a) { + best_s = dL; best_f = target_f + dL; best_plan = p; best_a = a2; + } + } + } + if (best_a < D && (family == SPUR_A4 || family == SPUR_C3M || family == SPUR_C3P) && lf < local_IF/2 - 10000000) { + // the shift budget does not clear the product: below IF, as the spur table did for the lowest spurs + if (debug_avoid) stored_t[i] = -70.0; // Display when to do spur shift in the stored trace + setting.below_IF = S_AUTO_ON; + target_f = local_IF - lf; + retune = LO_retune(target_f); + if (retune) + ADF4351_plan_frequency(target_f, &plan); + } else if (best_cost != INT32_MAX || best_a > (o < 0 ? -o : o)) { + // A planned LO that clears D (or the budget edge that helps most). Program it even when the move is + // zero: the product was inside D only because the hysteresis holds the LO off the target. + if (debug_avoid) stored_t[i] = -60.0; // Display when to do spur shift in the stored trace + if (best_s != 0) { + local_IF += best_s; + LO_spur_shifted = true; + } + target_f = best_f; + plan = best_plan; + retune = true; + } + } + if (retune) { // as set_freq(ADF4351_LO, target_f) + real_old_freq[ADF4351_LO] = ADF4351_commit_frequency(&plan); + old_freq[ADF4351_LO] = target_f; + } + } else { if ( target_f < real_old_freq[ADF4351_LO] - MAX_COMPENSATION || target_f > real_old_freq[ADF4351_LO] + MAX_COMPENSATION ) set_freq(ADF4351_LO, target_f); } #if 1 // Compensate frequency ADF4350 error with SI4468 - if (actual_rbw_x10 < 3000 || setting.frequency_step < 100000) { //TODO always compensate for the moment as this eliminates artifacts at larger RBW - int32_t error_f = 0; - if (real_old_freq[ADF4351_LO] > target_f) { - error_f = real_old_freq[ADF4351_LO] - target_f; - - if (inverted_f) { - error_f = -error_f; - goto correct_min; - } - correct_plus: - if (LO_harmonic) - error_f *= setting.harmonic; - if (error_f > actual_rbw_x10 * 5 || LO_harmonic) { //RBW / 4 - local_IF += error_f; - } - } else if ( real_old_freq[ADF4351_LO] < target_f) { - error_f = real_old_freq[ADF4351_LO] - target_f; - if (inverted_f) { - error_f = -error_f; - goto correct_plus; - } - correct_min: - if (LO_harmonic) { - error_f *= setting.harmonic; - } - if ( error_f < - actual_rbw_x10 * 5 || LO_harmonic) { //RBW / 4 - local_IF += error_f; - } - } - } + local_IF += LO_IF_correction(real_old_freq[ADF4351_LO], target_f, inverted_f); #endif } else if (setting.mode == M_HIGH || direct) { // direct means PATH_DIRECT or PATH_LEAKAGE if (signal_path == PATH_DIRECT) { @@ -4991,8 +5129,6 @@ again: // Spur redu #ifdef TINYSA4 if (SI4432_step_delay && (ADF4351_frequency_changed || SI4463_frequency_changed)) { int my_step_delay = SI4432_step_delay; - if (lf < LOW_SHIFT_FREQ && actual_rbw_x10 == 3 && !in_step_test) - my_step_delay = my_step_delay * 2; // if (LO_spur_shifted) // || SI4463_offset_changed) // my_step_delay = my_step_delay * 2; #if 0 // Always have some delay before measuring RSSI diff --git a/si4432.h b/si4432.h index deeebce..1537fb7 100644 --- a/si4432.h +++ b/si4432.h @@ -162,6 +162,12 @@ void ADF4351_Setup(void); void ADF4351_WriteRegister32(int channel, const uint32_t value); void ADF4351_Latch(void); uint64_t ADF4351_set_frequency(int channel, uint64_t freq); +typedef struct { + freq_t actual; // frequency the setting gives + uint16_t N, frac, out_div; +} ADF4351_plan_t; +freq_t ADF4351_plan_frequency(uint64_t freqHz, ADF4351_plan_t *p); +freq_t ADF4351_commit_frequency(const ADF4351_plan_t *p); uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq); //int ADF4351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength); void ADF4351_Set(int channel); diff --git a/si4468.c b/si4468.c index 3198f95..51fbe65 100644 --- a/si4468.c +++ b/si4468.c @@ -518,10 +518,8 @@ static uint32_t adf4350_get_O(uint64_t freqHz) { } } -freq_t xtal; - -uint64_t ADF4351_set_frequency(int channel, uint64_t freqHz) { - (void) channel; +// Calculate the PLL setting for freqHz without changing the chip state: ADF4351_commit_frequency() sends it +freq_t ADF4351_plan_frequency(uint64_t freqHz, ADF4351_plan_t *p) { // RFout = xtalFreqHz � (N + FRAC/MOD) = xtalFreqHz � (N * MOD + FRAC) / MOD // step = xtalFreqHz / MOD; !!!! should get integer result, also this result should divided by 16 // for 24M step = 24M / 4000 = 6k and 6k/16 = 375 @@ -529,6 +527,8 @@ uint64_t ADF4351_set_frequency(int channel, uint64_t freqHz) { // N * 4000 + frac = Nx // N = Nx / 4000 // frac = Nx % 4000 + freq_t xtal; + uint16_t N, frac, out_div; #if 1 out_div = adf4350_get_O(freqHz); #ifdef __SI5351__ @@ -586,14 +586,32 @@ uint64_t ADF4351_set_frequency(int channel, uint64_t freqHz) { freq_t actual_freq = ((uint64_t)xtal *(N * modulus +frac))/ (1<N = N; + p->frac = frac; + p->out_div = out_div; + p->actual = actual_freq; + return actual_freq; +} - if (prev_actual_freq == actual_freq) +// Program a setting calculated by ADF4351_plan_frequency() +freq_t ADF4351_commit_frequency(const ADF4351_plan_t *p) { + out_div = p->out_div; + N = p->N; + frac = p->frac; + if (prev_actual_freq == p->actual) return prev_actual_freq; - prev_actual_freq = actual_freq; + prev_actual_freq = p->actual; ADF4351_frequency_changed = true; sendConfig(); - return actual_freq; + return p->actual; +} + +uint64_t ADF4351_set_frequency(int channel, uint64_t freqHz) { + (void) channel; + ADF4351_plan_t p; + ADF4351_plan_frequency(freqHz, &p); + return ADF4351_commit_frequency(&p); } void ADF4351_force_refresh(void) { @@ -2531,7 +2549,7 @@ void SI4463_set_IF(int band) { static const uint8_t if_freq_high[6] = { 0x03, 0x03, 0x03, 0x03, 0, 0x02}; static const uint8_t if_freq_low[6] = { 0xc0, 0x60, 0x80, 0x40, 0, 0x80}; - uint8_t data3[] = { 0x11, 0x20, 0x03, 0x1b, if_freq_high[band], if_freq_low[band] }; + uint8_t data3[] = { 0x11, 0x20, 0x03, 0x1b, if_freq_high[band], if_freq_low[band], 0x00 }; // three property bytes SI4463_do_api(data3, sizeof(data3), NULL, 0); }