From f2fc3311ae55cdedae696f7324a463455a9ca582 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 12 Nov 2026 10:18:22 +0100 Subject: [PATCH] scanraw: no hardware setup for a new frequency step perform() now also sets up the first point when the frequency step changed, not only when dirty: the part that depends on the step (RBW and its sub-steps, step delay, RSSI correction of the RBW, sweep time estimate) for a new step, the hardware (radios, switches, MCU clock, correction tables) only when dirty. scanraw no longer sets dirty itself, so it skips the hardware setup (the basic power cycles and re-initializes both SI4432, about 80 ms) and the redraw that its dirty caused after it. Zero span keeps dirty: its series of RSSI samples needs the full setup at its frequency. A single zero span point is measured as in a sweep, with a step of half the RBW, instead of filling the RSSI buffer of a whole zero span sweep (40 ms on the Ultra). --- sa_cmd.c | 13 +++++++++++-- sa_core.c | 27 ++++++++++++++++++--------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/sa_cmd.c b/sa_cmd.c index 8c11736..6def7ca 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -1390,9 +1390,17 @@ VNA_SHELL_FUNCTION(cmd_scanraw) freq_t old_step = setting.frequency_step; float f_step = (stop-start)/ points; setting.frequency_step = (freq_t)f_step; + // perform() recalculates for a new frequency step itself. Zero span measures a series of RSSI + // samples at one frequency, which needs a full setup, also for the sweep after it. + bool zero_span = setting.frequency_step == 0; + if (zero_span && points == 1) { // one point as in a sweep: one measurement, auto RBW as in zero span + setting.frequency_step = setting.rbw_x10 ? setting.rbw_x10*50 : 300000; + zero_span = false; + } again: operation_requested = false; - dirty = true; + if (zero_span) + dirty = true; // adc_stop_analog_watchdog(); int oldpos = 0; if (!UI_OFF) { // ui off: no progress bar @@ -1431,7 +1439,8 @@ again: ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1); } setting.frequency_step = old_step; - dirty = true; + if (zero_span) + dirty = true; redraw_request = 0; // disable screen update in this mode } diff --git a/sa_core.c b/sa_core.c index 4d3a8f6..f6b5827 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3715,6 +3715,7 @@ bool depth_error = false; #endif +static freq_t setup_frequency_step; // frequency step the first point of perform() was set up for pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup { @@ -3735,7 +3736,11 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / } #endif TRACE(10); - if (i == 0 && dirty ) { // if first point in scan and dirty + // First point after a change of settings (dirty) or of the frequency step (scanraw, the sweep + // after it): only dirty sets up the hardware, which takes about 80 ms on the tinySA basic + if (i == 0 && (dirty || setting.frequency_step != setup_frequency_step)) { + const bool hw = dirty; + if (hw) { #ifdef __ADF4351__ clear_frequency_cache(); #endif @@ -3749,15 +3754,17 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / PE4302_Write_Byte((int)(setting.attenuate_x2)); #endif set_calibration_freq(setting.refer); - update_rbw(); - calculate_step_delay(); prev_output_level_dBm = MIN_RSSI_VALUE; // clear cached level setting - // Initialize HW - scandirty = true; // This is the first pass with new settings for (int t=0;t