From be66fab7f68d1341468f6248c48f9e898d24058f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 8 Jun 2020 16:50:49 +0200 Subject: [PATCH] Sweep speed improvement and better sweep time calculation --- nanovna.h | 4 ++++ sa_core.c | 70 +++++++++++++++++++++++++++++++++++++------------------ si4432.c | 6 ++--- ui_sa.c | 22 ++++++++++------- 4 files changed, 68 insertions(+), 34 deletions(-) diff --git a/nanovna.h b/nanovna.h index 589db6b..999f391 100644 --- a/nanovna.h +++ b/nanovna.h @@ -594,6 +594,9 @@ void reset_settings(int m); #define S_IS_AUTO(x) ((x)&2) #define S_STATE(X) ((X)&1) enum { S_OFF=0, S_ON=1, S_AUTO_OFF=2, S_AUTO_ON=3 }; +#define MINIMUM_SWEEP_TIME 15 // Minimum sweep time on zero span in miliseconds +#define REPEAT_TIME 34.0 // Time per extra repeat in uS +#define MEASURE_TIME 175.0 // Time per vbwstep without stepdelay in uS extern uint32_t frequencies[POINTS_COUNT]; @@ -827,6 +830,7 @@ void self_test(int); void wait_user(void); void calibrate(void); float to_dBm(float); +float calc_min_sweep_time(void); enum { M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY diff --git a/sa_core.c b/sa_core.c index 180e3da..3a124c6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -66,7 +66,7 @@ void reset_settings(int m) set_sweep_frequency(ST_START, (uint32_t) 0); set_sweep_frequency(ST_STOP, (uint32_t) 350000000); setting.attenuate = 30; - setting.sweep_time = 0.0; + setting.sweep_time = 0; break; #ifdef __ULTRA__ case M_ULTRA: @@ -84,7 +84,7 @@ void reset_settings(int m) maxFreq = 520000000; set_sweep_frequency(ST_CENTER, (int32_t) 10000000); set_sweep_frequency(ST_SPAN, 0); - setting.sweep_time = 10.0; + setting.sweep_time = 10000.0; break; case M_HIGH: #ifdef __ULTRA_SA__ @@ -96,7 +96,7 @@ void reset_settings(int m) #endif set_sweep_frequency(ST_START, (int32_t) minFreq); set_sweep_frequency(ST_STOP, (int32_t) maxFreq); - setting.sweep_time = 0.0; + setting.sweep_time = 0; break; case M_GENHIGH: setting.drive=8; @@ -104,7 +104,7 @@ void reset_settings(int m) maxFreq = 960000000; set_sweep_frequency(ST_CENTER, (int32_t) 300000000); set_sweep_frequency(ST_SPAN, 0); - setting.sweep_time = 10.0; + setting.sweep_time = 10000.0; break; } for (int i = 0; i< MARKERS_MAX; i++) { @@ -117,6 +117,18 @@ void reset_settings(int m) dirty = true; } +float calc_min_sweep_time(void) // Calculate minimum sweep time in mS +{ + float t; + 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); + return t; +} + + void set_refer_output(int v) { setting.refer = v; @@ -171,10 +183,10 @@ void set_level_sweep(float l) void set_sweep_time(float t) { - if (t < 0.0) - t = 0.0; - if (t > 600.0) - t = 600.0; + if (t < MINIMUM_SWEEP_TIME) + t = MINIMUM_SWEEP_TIME; + if (t > 600000.0) + t = 600000.0; setting.sweep_time = t; dirty = true; } @@ -455,6 +467,13 @@ void toggle_LNA(void) void toggle_tracking(void) { setting.tracking = !setting.tracking; + if (setting.tracking) { + set_refer_output(2); + set_sweep_frequency(ST_CENTER, 10000000); + set_sweep_frequency(ST_SPAN, 5000000); + } else { + set_refer_output(-1); + } dirty = true; } @@ -602,12 +621,18 @@ void set_offset(float offset) dirty = true; } +void show_stored_trace_at(float v) +{ + for (int j = 0; j < setting._sweep_points; j++) + stored_t[j] = v; + trace[TRACE_STORED].enabled = true; +} + void set_trigger_level(float trigger_level) { setting.trigger_level = trigger_level; if (setting.trigger != T_AUTO) { - for (int j = 0; j < setting._sweep_points; j++) - stored_t[j] = trigger_level; + show_stored_trace_at(setting.trigger_level); } dirty = true; } @@ -618,9 +643,7 @@ void set_trigger(int trigger) if (trigger == T_AUTO) { trace[TRACE_STORED].enabled = false; } else { - for (int j = 0; j < setting._sweep_points; j++) - stored_t[j] = setting.trigger_level; - trace[TRACE_STORED].enabled = true; + show_stored_trace_at(setting.trigger_level); } sweep_mode = SWEEP_ENABLE; dirty = true; @@ -1188,7 +1211,7 @@ again: #endif if (MODE_INPUT(setting.mode) && i > 0 && FREQ_IS_CW()) - goto skip_LO_setting; + goto skip_LO_setting; // No LO changes during CW loop if (setting.mode == M_LOW && tracking) { // Measure BPF set_freq (0, setting.frequency_IF + lf - reffer_freq[setting.refer]); // Offset so fundamental of reffer is visible @@ -1288,7 +1311,10 @@ again: actualStepDelay = 0; // fastest possible in zero span trigger mode } float subRSSI; - float correct_RSSI = get_level_offset()+ setting.attenuate - signal_path_loss - setting.offset + get_frequency_correction(f); + + static float correct_RSSI = 0; + if (i == 0 || setting.frequency_step != 0 ) + correct_RSSI = get_level_offset()+ setting.attenuate - signal_path_loss - setting.offset + get_frequency_correction(f); wait: subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting.mode)) + correct_RSSI ; // if ( i < 3) @@ -1348,13 +1374,13 @@ again: repeats = 1000; // to avoid interrupting the tone during UI processing modulation_counter = 0; } + float t = calc_min_sweep_time(); while (repeats--) { for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], setting.tracking); - - if ( setting.sweep_time > 0.0 && !(MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE)) { - float s = setting.sweep_time * (1000000.0 / 290.0); + if ( setting.sweep_time > t && !(MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE)) { + float s = (setting.sweep_time - t) * (1000.0 / 290.0); if (s < 30000) my_microsecond_delay((int)s); else @@ -1932,11 +1958,9 @@ void draw_cal_status(void) ili9341_drawstring("Scan:", x, y); y += YSTEP; - float t = setting.sweep_time*1000.0 + 25.0 + (float)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 -#ifdef __SPUR__ - * (setting.spur ? 2 : 1) -#endif - ; // in mS + float t = calc_min_sweep_time(); + if (t < setting.sweep_time) + t = setting.sweep_time; if (t>=10000.0) plot_printf(buf, BLEN, "%5d",(int)(t/1000)); else if (t>=1000) diff --git a/si4432.c b/si4432.c index 65e7ffb..8810404 100644 --- a/si4432.c +++ b/si4432.c @@ -365,7 +365,7 @@ static const short RBW_choices[] = #endif }; -static float SI4432_RSSI_correction = 0; +static float SI4432_RSSI_correction = -120.0; float SI4432_SET_RBW(float w) { uint8_t dwn3=0; @@ -378,7 +378,7 @@ float SI4432_SET_RBW(float w) { ndec = RBW_choices[i-3]; fils = RBW_choices[i-2]; WISH = RBW_choices[i-1]; // RBW achieved by Si4432 in Hz - SI4432_RSSI_correction = RBW_choices[i]/10.0; + SI4432_RSSI_correction = RBW_choices[i]/10.0 - 120.0; uint8_t BW = (dwn3 << 7) | (ndec << 4) | fils ; SI4432_Write_Byte(0x1C , BW ) ; return (((float)WISH) / 10.0) ; @@ -453,7 +453,7 @@ float SI4432_RSSI(uint32_t i, int s) RSSI_RAW = RSSI_RAW / setting.repeat; // if (MODE_INPUT(setting.mode) && RSSI_RAW == 0) // SI4432_Init(); - float dBm = ((float)RSSI_RAW)/32.0 - 120.0 + SI4432_RSSI_correction; + float dBm = ((float)RSSI_RAW)/32.0 + SI4432_RSSI_correction; #ifdef __SIMULATION__ dBm = Simulated_SI4432_RSSI(i,s); #endif diff --git a/ui_sa.c b/ui_sa.c index 49b5442..e320787 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -278,7 +278,7 @@ const uint16_t right_icons [] = }; enum { - KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, + KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFLEVEL, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, }; @@ -422,7 +422,7 @@ static const char * const keypad_mode_label[] = { #ifdef __SA__ static const char * const keypad_mode_label[] = { "error", "START", "STOP", "CENTER", "SPAN", "FREQ", "REFPOS", "\2SCALE\0 5/2/1", // 0-7 - "\2ATTENUATE\0 0-31dB", "\2ACTUAL\0POWER", "IF", "\2SAMPLE\0TIME", "DRIVE", "LEVEL", "LEVEL", "LEVEL", // 8-15 + "\2ATTENUATE\0 0-31dB", "\2ACTUAL\0POWER", "IF", "\2SAMPLE\0TIME", "DRIVE", "LEVEL", "SCANS", "LEVEL", // 8-15 "OFFSET" , "REPEATS", "OFFSET", "\2TRIGGER\0LEVEL", "\2LEVEL\0SWEEP", "\2SWEEP\0SECONDS"// 16- }; #endif @@ -1179,7 +1179,7 @@ static const menuitem_t menu_atten[] = { static const menuitem_t menu_reflevel[] = { { MT_CALLBACK,0, "AUTO", menu_reflevel_cb}, - { MT_KEYPAD, KM_REFPOS, "MANUAL", NULL}, + { MT_KEYPAD, KM_REFLEVEL, "MANUAL", NULL}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1461,7 +1461,7 @@ static const menuitem_t menu_mode[] = { #ifdef __ULTRA__ { MT_FORM | MT_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "ULTRA HIGH INPUT",menu_mode_cb}, #endif - { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, +// { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_FORM | MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1703,7 +1703,7 @@ static void fetch_numeric_target(void) uistat.value = setting.scale; plot_printf(uistat.text, sizeof uistat.text, "%f/", uistat.value); break; - case KM_REFPOS: + case KM_REFLEVEL: uistat.value = setting.reflevel; plot_printf(uistat.text, sizeof uistat.text, "%f", uistat.value); break; @@ -1756,7 +1756,11 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%.1fdB", uistat.value); break; case KM_SWEEP_TIME: - uistat.value = setting.sweep_time; + if (setting.sweep_time < calc_min_sweep_time()) + uistat.value = calc_min_sweep_time(); + else + uistat.value = setting.sweep_time; + uistat.value /= 1000.0; plot_printf(uistat.text, sizeof uistat.text, "%.1fS", uistat.value); break; case KM_TRIGGER: @@ -1800,7 +1804,7 @@ set_numeric_value(void) set_auto_reflevel(false); set_scale(uistat.value); break; - case KM_REFPOS: + case KM_REFLEVEL: set_auto_reflevel(false); set_reflevel(uistat.value); break; @@ -1849,10 +1853,12 @@ set_numeric_value(void) set_level_sweep(uistat.value); break; case KM_SWEEP_TIME: - set_sweep_time(uistat.value); + set_sweep_time(uistat.value*1000.0); update_grid(); break; case KM_TRIGGER: + if (setting.trigger == T_AUTO ) + set_trigger(T_NORMAL); set_trigger_level(to_dBm(uistat.value)); break; }