diff --git a/nanovna.h b/nanovna.h index cd91535..7d00c9c 100644 --- a/nanovna.h +++ b/nanovna.h @@ -638,7 +638,7 @@ enum { S_OFF=0, S_ON=1, S_AUTO_OFF=2, S_AUTO_ON=3 }; enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL }; #ifdef __FAST_SWEEP__ -#define MINIMUM_SWEEP_TIME 2000U // Minimum sweep time on zero span in uS +#define MINIMUM_SWEEP_TIME 1800U // Minimum sweep time on zero span in uS #else #define MINIMUM_SWEEP_TIME 15000U // Minimum sweep time on zero span in uS #endif @@ -646,8 +646,8 @@ enum { SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL }; #define ONE_SECOND_TIME 1000000U // One second uS #define ONE_MS_TIME 1000U // One ms uS -#define REPEAT_TIME 110 // Time per extra repeat in uS -#define MEASURE_TIME 127 // Time per vbwstep without step delay in uS +#define REPEAT_TIME 111 // Time per extra repeat in uS +#define MEASURE_TIME 127 // Time per single point measurement with vbwstep =1 without step delay in uS extern uint32_t frequencies[POINTS_COUNT]; extern const float unit_scale_value[]; diff --git a/sa_core.c b/sa_core.c index 70d3c94..fc8ed09 100644 --- a/sa_core.c +++ b/sa_core.c @@ -166,19 +166,20 @@ void reset_settings(int m) //static uint32_t minimum_sweep_time = 0; -uint32_t calc_min_sweep_time_us(void) // Calculate minimum sweep time in uS needed just because of the delays for the RSSI to become stable +uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in uS, needed to calculate the initial delays for the RSSI before first sweep { uint32_t t; if (MODE_OUTPUT(setting.mode)) t = 100; else { - uint32_t a = (SI4432_step_delay + MEASURE_TIME) * (sweep_points - 1); // Single RSSI delay and measurement time in uS while scanning + uint32_t bare_sweep_time = (SI4432_step_delay + MEASURE_TIME) * (sweep_points - 1); // Single RSSI delay and measurement time in uS while scanning if (FREQ_IS_CW()) { - a = MINIMUM_SWEEP_TIME; // time per step in fast CW mode - if (setting.repeat != 1 || setting.sweep_time_us >= ONE_SECOND_TIME || setting.spur != 0) - a = 15000; // time per step in CW mode with repeat too long for fast delay + bare_sweep_time = MINIMUM_SWEEP_TIME; // minimum sweep time in fast CW mode + if (setting.repeat != 1 || setting.sweep_time_us >= ONE_SECOND_TIME || setting.spur != 0) // if no fast CW sweep possible + bare_sweep_time = 15000; // minimum CW sweep time when not in fast CW mode } - t = vbwSteps * (setting.spur ? 2 : 1) * ( (a + (setting.repeat - 1)* ( REPEAT_TIME * (sweep_points - 1)))); + t = vbwSteps * (setting.spur ? 2 : 1) * bare_sweep_time ; // factor in vbwSteps and spur impact + t += (setting.repeat - 1)* REPEAT_TIME * (sweep_points - 1); // Add time required for repeats } return t; } @@ -233,8 +234,8 @@ void set_level_sweep(float l) void set_sweep_time_us(uint32_t t) // Set the sweep time as the user wants it to be. { - if (t < MINIMUM_SWEEP_TIME) - t = MINIMUM_SWEEP_TIME; +// if (t < MINIMUM_SWEEP_TIME) // Sweep time of zero means sweep as fast as possible +// t = MINIMUM_SWEEP_TIME; if (t > MAXIMUM_SWEEP_TIME) t = MAXIMUM_SWEEP_TIME; setting.sweep_time_us = t; @@ -1274,6 +1275,7 @@ static const int wfm_modulation[5] = { 0, 190, 118, -118, -190 }; // 5 step wi char age[POINTS_COUNT]; static float old_a = -150; +systime_t measure; float perform(bool break_on_operation, int i, uint32_t f, int tracking) // Measure the RSSI for one frequency, used from sweep and other measurement routines. Must do all HW setup { @@ -1283,6 +1285,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M dirty = false; if (setting.spur) // if in spur avoidance mode setting.spur = 1; // resync spur in case of previous abort + measure = chVTGetSystemTimeX(); // initialize again to eliminate time spend in apply_settings } if (setting.mode == M_GENLOW && setting.level_sweep != 0.0) { // if in low output mode and level sweep is active @@ -1588,7 +1591,6 @@ again: // Waiting for a trigger jumps back to here // shell_printf("\r\n"); modulation_counter = 0; // init modulation counter in case needed - if (dirty) { // Calculate new scanning solution update_rbw(); calculate_step_delay(); @@ -1600,11 +1602,13 @@ again: // Waiting for a trigger jumps back to here // V if (setting.sweep_time_us > setting.actual_sweep_time_us){ setting.additional_step_delay_us = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points-1); + setting.actual_sweep_time_us = setting.sweep_time_us; } else{ // not add additional correction, apply recommend time setting.additional_step_delay_us = 0; - setting.sweep_time_us = setting.actual_sweep_time_us; +// setting.sweep_time_us = setting.actual_sweep_time_us; } +#if 0 // manually set delay, for better sync if (setting.sweep_time_us < 2.5 * ONE_MS_TIME){ setting.additional_step_delay_us = 0; @@ -1614,6 +1618,7 @@ again: // Waiting for a trigger jumps back to here setting.additional_step_delay_us = 1; setting.sweep_time_us = 3000; } +#endif if (MODE_OUTPUT(setting.mode) && setting.additional_step_delay_us < 500) // Minimum wait time to prevent LO from lockup during output frequency sweep setting.additional_step_delay_us = 500; // Update greed and status after @@ -1625,7 +1630,8 @@ again: // Waiting for a trigger jumps back to here } } - setting.measure_sweep_time_us = chVTGetSystemTimeX(); // start measure sweep time + setting.measure_sweep_time_us = 0; // start measure sweep time + measure = chVTGetSystemTimeX(); sweep_again: // stay in sweep loop when output mode and modulation on. @@ -1646,7 +1652,7 @@ sweep_again: // stay in sweep loop when output mo // if break back to top level to handle ui operation if ((operation_requested || shell_function) && break_on_operation) { // break loop if needed - if (setting.sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { + if (setting.actual_sweep_time_us > ONE_SECOND_TIME && MODE_INPUT(setting.mode)) { ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0); } return false; @@ -1654,7 +1660,7 @@ sweep_again: // stay in sweep loop when output mo if (MODE_INPUT(setting.mode)) { - if (setting.sweep_time_us > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required + if (setting.actual_sweep_time_us > ONE_SECOND_TIME && (i & 0x07) == 0) { // if required ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, i, 1, BRIGHT_COLOR_GREEN); // update sweep progress bar ili9341_fill(OFFSETX+i, HEIGHT_NOSCROLL+1, WIDTH-i, 1, 0); } @@ -1765,7 +1771,7 @@ sweep_again: // stay in sweep loop when output mo // ---------------------- process measured actual sweep time ----------------- // For CW mode value calculated in SI4432_Fill if (setting.measure_sweep_time_us == 0) - setting.measure_sweep_time_us = (chVTGetSystemTimeX() - setting.measure_sweep_time_us) * 100; + setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure) * 100; // Update actual time on change on status panel uint32_t delta = abs((int)(setting.actual_sweep_time_us - setting.measure_sweep_time_us)); @@ -1773,6 +1779,7 @@ sweep_again: // stay in sweep loop when output mo redraw_request|=REDRAW_CAL_STATUS; } setting.actual_sweep_time_us = setting.measure_sweep_time_us; + // Not possible reduce sweep time, it minimum! if (setting.sweep_time_us < setting.actual_sweep_time_us && setting.additional_step_delay_us == 0){ // Warning!! not correct set sweep time here, you get error!! @@ -1788,8 +1795,10 @@ sweep_again: // stay in sweep loop when output mo // selected time less then actual, need reduce delay if (setting.sweep_time_us < setting.actual_sweep_time_us){ dt = (setting.actual_sweep_time_us - setting.sweep_time_us)/(sweep_points - 1); - if (setting.additional_step_delay_us > dt) setting.additional_step_delay_us-=dt; - else setting.additional_step_delay_us = 0; + if (setting.additional_step_delay_us > dt) + setting.additional_step_delay_us-=dt; + else + setting.additional_step_delay_us = 0; }// selected time greater then actual, need increase delay else if (setting.sweep_time_us > setting.actual_sweep_time_us){ dt = (setting.sweep_time_us - setting.actual_sweep_time_us)/(sweep_points - 1); diff --git a/si4432.c b/si4432.c index 9994d6a..2e58fb5 100644 --- a/si4432.c +++ b/si4432.c @@ -425,7 +425,7 @@ void SI4432_Fill(int s, int start) #else shiftInBuf(sel, SI4432_REG_RSSI, (uint8_t *)&age[start], sweep_points - start, t); #endif - setting.measure_sweep_time_us+= (chVTGetSystemTimeX() - measure)*100; + setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; buf_index = start; // Is used to skip 1st entry during level triggering buf_read = true; } diff --git a/ui_sa.c b/ui_sa.c index c4c52b3..cd9de62 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1846,9 +1846,9 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; case KM_SWEEP_TIME: - if (setting.sweep_time_us < calc_min_sweep_time_us()) - uistat.value = calc_min_sweep_time_us(); - else +// if (setting.sweep_time_us < calc_min_sweep_time_us()) +// uistat.value = calc_min_sweep_time_us(); +// else uistat.value = setting.sweep_time_us; uistat.value /= (float)ONE_SECOND_TIME; plot_printf(uistat.text, sizeof uistat.text, "%.3Fs", uistat.value);