From 87555f8c3e3d5815fd92e87af71ec96591ea7d1f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 8 Jun 2020 17:31:09 +0200 Subject: [PATCH] Sweep time calculation and delayed scale increase --- nanovna.h | 1 + plot.c | 13 +++++++++---- sa_core.c | 19 +++++++++++++++---- ui_sa.c | 6 +++++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/nanovna.h b/nanovna.h index 999f391..f9221f9 100644 --- a/nanovna.h +++ b/nanovna.h @@ -580,6 +580,7 @@ typedef struct setting float level; float level_sweep; float sweep_time; + float actual_sweep_time; int test_argument; int auto_IF; uint32_t checksum; diff --git a/plot.c b/plot.c index 38528da..6fb8ed1 100644 --- a/plot.c +++ b/plot.c @@ -117,7 +117,8 @@ void update_grid(void) uint32_t grid; if (fspan == 0) { - fspan = setting.sweep_time*1000000 + 25000; // Time in uS + fspan = setting.actual_sweep_time; // Time in uS + fspan *= 1000; fstart = 0; } @@ -869,7 +870,7 @@ static void trace_get_value_string( dfreq = frequencies[i]; } if (FREQ_IS_CW()) { - float t = ii*(setting.sweep_time*1000000 + 25000)/290; + float t = ii*(setting.actual_sweep_time)*1000.0/290.0; if (t>1000000.0){ plot_printf(&buf2[1], sizeof(buf2) -1, "%4f" , t/1000000.0); buf2[5] = 'S'; @@ -2147,7 +2148,7 @@ draw_frequencies(void) #endif if (FREQ_IS_CW()) { plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW)); - float t = setting.sweep_time*1000.0 + 25.0; // in mS + float t = setting.actual_sweep_time; // in mS ; // in mS if (t>=1000) plot_printf(buf2, sizeof(buf2), "%.2fS",t/1000.0); @@ -2174,8 +2175,12 @@ draw_frequencies(void) buf1[0] = S_SARROW[0]; if (uistat.lever_mode == LM_SPAN) buf2[0] = S_SARROW[0]; + int p2 = FREQUENCIES_XPOS2; + if (FREQ_IS_CW()) { + p2 = 320 - 7*strlen(buf2); + } ili9341_drawstring(buf1, FREQUENCIES_XPOS1, FREQUENCIES_YPOS); - ili9341_drawstring(buf2, FREQUENCIES_XPOS2, FREQUENCIES_YPOS); + ili9341_drawstring(buf2, p2, FREQUENCIES_YPOS); } #ifdef __VNA__ void diff --git a/sa_core.c b/sa_core.c index 3a124c6..34b9f7a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -123,8 +123,8 @@ float calc_min_sweep_time(void) // Calculate minimum sweep time in mS float a = actualStepDelay + MEASURE_TIME; if (FREQ_IS_CW()) - a = MINIMUM_SWEEP_TIME / 290; // time per step in CW mode - t = vbwSteps * sweep_points * (setting.spur ? 2 : 1) * ( (a + (setting.repeat - 1)* REPEAT_TIME) / 1000.0); + a = (float)MINIMUM_SWEEP_TIME / 290.0; // time per step in CW mode + t = vbwSteps * sweep_points * (setting.spur ? 2 : 1) * ( (a + (setting.repeat - 1)* REPEAT_TIME)); return t; } @@ -1522,7 +1522,16 @@ again: float r = value(temppeakLevel); if (!in_selftest && MODE_INPUT(setting.mode) && setting.auto_reflevel) { // Auto reflevel if (UNIT_IS_LINEAR(setting.unit)) { // Linear scales can not have negative values - if ((setting.reflevel > REFLEVEL_MIN && r < setting.reflevel / 2.5 ) || (setting.reflevel < REFLEVEL_MAX && r > setting.reflevel) ) { // ensure minimum and maximum reflevel + static int low_count = 0; + if (setting.reflevel > REFLEVEL_MIN) { + if (r < setting.reflevel / 5) + low_count = 5; + else if (r < setting.reflevel / 2.5) + low_count++; + else + low_count = 0; + } + if ((low_count > 4) || (setting.reflevel < REFLEVEL_MAX && r > setting.reflevel) ) { // ensure minimum and maximum reflevel // r = setting.scale * (floor(r / setting.scale) + 1); #if 0 float m = 1; @@ -1855,13 +1864,14 @@ void draw_cal_status(void) ili9341_set_foreground(color); ili9341_drawstring(buf, x, y); - +#if 0 color = DEFAULT_FG_COLOR; ili9341_set_foreground(color); if (setting.auto_reflevel){ y += YSTEP + YSTEP/2 ; ili9341_drawstring("AUTO", x, y); } +#endif y += YSTEP + YSTEP/2 ; plot_printf(buf, BLEN, "%s",unit); ili9341_drawstring(buf, x, y); @@ -1961,6 +1971,7 @@ void draw_cal_status(void) float t = calc_min_sweep_time(); if (t < setting.sweep_time) t = setting.sweep_time; + setting.actual_sweep_time = t; if (t>=10000.0) plot_printf(buf, BLEN, "%5d",(int)(t/1000)); else if (t>=1000) diff --git a/ui_sa.c b/ui_sa.c index e320787..e395565 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1806,7 +1806,11 @@ set_numeric_value(void) break; case KM_REFLEVEL: set_auto_reflevel(false); - set_reflevel(uistat.value); + if (uistat.value < setting.scale*NGRIDY) { + set_scale(uistat.value/NGRIDY); + set_reflevel(setting.scale*NGRIDY); + } else + set_reflevel(uistat.value); break; case KM_ATTENUATION: setting.auto_attenuation = false;