From ac7e09efdd65c13f73701e80a435dfbff8b1471c Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 24 Aug 2020 13:37:52 +0200 Subject: [PATCH 1/6] Marker PEAK SEARCH added --- nanovna.h | 1 + sa_core.c | 40 ++++++++++++++++++++++++++++------------ ui.c | 16 ++++++++++------ ui_sa.c | 2 +- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/nanovna.h b/nanovna.h index 31ba7f8..cf34dc6 100644 --- a/nanovna.h +++ b/nanovna.h @@ -514,6 +514,7 @@ void marker_position(int m, int t, int *x, int *y); int search_nearest_index(int x, int y, int t); void set_marker_search(int mode); int marker_search(void); +int marker_search_max(void); int marker_search_left(int from); int marker_search_right(int from); int marker_search_left_max(int from); diff --git a/sa_core.c b/sa_core.c index 573d3f8..81e2c84 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2277,9 +2277,9 @@ marker_search_left_max(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from - 1; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { value = new_value; found = i; @@ -2288,7 +2288,7 @@ marker_search_left_max(int from) } for (; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { value = new_value; found = i; @@ -2306,9 +2306,9 @@ marker_search_right_max(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from + 1; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { // follow down value = new_value; found = i; @@ -2316,7 +2316,7 @@ marker_search_right_max(int from) break; // past the minimum } for (; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { // follow up value = new_value; found = i; @@ -2326,6 +2326,22 @@ marker_search_right_max(int from) return found; } +int marker_search_max(void) +{ + int i = 0; + int found = 0; + + float value = actual_t[i]; + for (; i < sweep_points; i++) { + int new_value = actual_t[i]; + if (new_value > value) { // follow up + value = new_value; + found = i; + } + } + return found; +} + #define MINMAX_DELTA 10 @@ -2337,9 +2353,9 @@ marker_search_left_min(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from - 1; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { value = new_value; // follow up // found = i; @@ -2348,7 +2364,7 @@ marker_search_left_min(int from) } for (; i >= 0; i--) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { value = new_value; // follow down found = i; @@ -2366,9 +2382,9 @@ marker_search_right_min(int from) if (uistat.current_trace == -1) return -1; - int value = actual_t[from]; + float value = actual_t[from]; for (i = from + 1; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value > value) { // follow up value = new_value; // found = i; @@ -2376,7 +2392,7 @@ marker_search_right_min(int from) break; // past the maximum } for (; i < sweep_points; i++) { - int new_value = actual_t[i]; + float new_value = actual_t[i]; if (new_value < value) { // follow down value = new_value; found = i; diff --git a/ui.c b/ui.c index 99a0639..ca42e1a 100644 --- a/ui.c +++ b/ui.c @@ -809,8 +809,8 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) int i = -1; if (active_marker == -1) return; - if (data < 4) - markers[active_marker].mtype &= ~M_TRACKING; +// if (data < 4) +// markers[active_marker].mtype &= ~M_TRACKING; switch (data) { case 0: /* search Left */ i = marker_search_left_min(markers[active_marker].index); @@ -831,12 +831,14 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) case 3: /* search right */ i = marker_search_right_max(markers[active_marker].index); break; - case 4: /* tracking */ - markers[active_marker].mtype ^= M_TRACKING; + case 4: /* peak search */ + i = marker_search_max(); break; } - if (i != -1) + if (i != -1) { markers[active_marker].index = i; + markers[active_marker].frequency = frequencies[i]; + } draw_menu(); redraw_marker(active_marker); select_lever_mode(LM_SEARCH); @@ -2091,8 +2093,10 @@ lever_search_marker(int status) i = marker_search_left(markers[active_marker].index); else if (status & EVT_UP) i = marker_search_right(markers[active_marker].index); - if (i != -1) + if (i != -1) { markers[active_marker].index = i; + markers[active_marker].frequency = frequencies[i]; + } redraw_marker(active_marker); } } diff --git a/ui_sa.c b/ui_sa.c index d44b13d..e7f1a79 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1406,7 +1406,7 @@ static const menuitem_t menu_reflevel[] = { }; const menuitem_t menu_marker_search[] = { - //{ MT_CALLBACK, "OFF", menu_marker_search_cb }, + { MT_CALLBACK, 4, "PEAK\n SEARCH", menu_marker_search_cb }, { MT_CALLBACK, 0, "MIN\n" S_LARROW" LEFT", menu_marker_search_cb }, { MT_CALLBACK, 1, "MIN\n" S_RARROW" RIGHT", menu_marker_search_cb }, { MT_CALLBACK, 2, "MAX\n" S_LARROW" LEFT", menu_marker_search_cb }, From 0e7c601c71ba839f1162697c9aa7803ab0607f45 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 24 Aug 2020 17:45:05 +0200 Subject: [PATCH 2/6] Marker search now deactivates tracking --- nanovna.h | 2 +- ui.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/nanovna.h b/nanovna.h index cf34dc6..e381fb1 100644 --- a/nanovna.h +++ b/nanovna.h @@ -26,7 +26,7 @@ #define __SA__ #define __SI4432__ -//#define __PE4302__ +#define __PE4302__ //#define __SIMULATION__ //#define __PIPELINE__ #define __SCROLL__ diff --git a/ui.c b/ui.c index ca42e1a..ae97bfe 100644 --- a/ui.c +++ b/ui.c @@ -809,8 +809,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) int i = -1; if (active_marker == -1) return; -// if (data < 4) -// markers[active_marker].mtype &= ~M_TRACKING; + markers[active_marker].mtype &= ~M_TRACKING; switch (data) { case 0: /* search Left */ i = marker_search_left_min(markers[active_marker].index); From b21627591e2e3b0b7d78f784e7a16f20d0ca3492 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 26 Aug 2020 08:48:17 +0200 Subject: [PATCH 3/6] Lever mode never searches but always moves --- ui.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui.c b/ui.c index ae97bfe..658ab91 100644 --- a/ui.c +++ b/ui.c @@ -840,7 +840,10 @@ static UI_FUNCTION_CALLBACK(menu_marker_search_cb) } draw_menu(); redraw_marker(active_marker); - select_lever_mode(LM_SEARCH); +// if (data == 4) + select_lever_mode(LM_MARKER); // Allow any position with level +// else +// select_lever_mode(LM_SEARCH); // Jump from maximum to maximum } static UI_FUNCTION_ADV_CALLBACK(menu_marker_tracking_acb){ @@ -2089,9 +2092,9 @@ lever_search_marker(int status) int i = -1; if (active_marker >= 0) { if (status & EVT_DOWN) - i = marker_search_left(markers[active_marker].index); + i = marker_search_left_max(markers[active_marker].index); else if (status & EVT_UP) - i = marker_search_right(markers[active_marker].index); + i = marker_search_right_max(markers[active_marker].index); if (i != -1) { markers[active_marker].index = i; markers[active_marker].frequency = frequencies[i]; From ff5430099491d62b37108374d9e93327548896e1 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 26 Aug 2020 09:12:33 +0200 Subject: [PATCH 4/6] Show direct marker selection even when sweep is paused --- ui.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ui.c b/ui.c index 658ab91..0587efb 100644 --- a/ui.c +++ b/ui.c @@ -2539,6 +2539,7 @@ touch_marker_select(void) if (markers[i].enabled) { if (selected_marker == 0) { active_marker = i; + redraw_marker(active_marker); break; } selected_marker --; From 140a1be1a8c1dbabe237aed30cfdf242c4416321 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 29 Aug 2020 13:33:17 +0200 Subject: [PATCH 5/6] Bugs corrected - Overload warning when normalized - trace store not working - save command not working --- main.c | 4 ++-- plot.c | 5 +++-- ui_sa.c | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index d72101f..d500bea 100644 --- a/main.c +++ b/main.c @@ -1785,7 +1785,7 @@ VNA_SHELL_FUNCTION(cmd_trace) set_unit(type); goto update; } - goto usage; +// goto usage; } static const char cmd_store_list[] = "store|clear|subtract"; if (argc == 1) { @@ -1803,7 +1803,7 @@ VNA_SHELL_FUNCTION(cmd_trace) goto update; } } - goto usage; +// goto usage; } // 0 1 static const char cmd_scale_ref_list[] = "scale|reflevel"; diff --git a/plot.c b/plot.c index 51bc308..89b0c69 100644 --- a/plot.c +++ b/plot.c @@ -2097,8 +2097,9 @@ static void cell_draw_marker_info(int x0, int y0) // buf[k++] = 0; ili9341_set_background(DEFAULT_BG_COLOR); uint16_t color; - if ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -1) || - (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -10)) + if ((!setting.subtract_stored) && // Disabled when normalized + ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -1) || + (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -10) )) color = BRIGHT_COLOR_RED; else color = marker_color(markers[i].mtype); diff --git a/ui_sa.c b/ui_sa.c index e7f1a79..23068ec 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -894,6 +894,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_storage_acb) break; case 3: toggle_normalize(); + if (setting.subtract_stored) { + kp_help_text = "Ref level"; + ui_mode_keypad(KM_REFLEVEL); + ui_process_keypad(); +// setting.normalize_level = uistat.value; + } else + set_auto_reflevel(true); break; } ui_mode_normal(); From abef8aa051446b8e5249c1feab3acd17e6851e00 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 30 Aug 2020 09:18:30 +0200 Subject: [PATCH 6/6] Added save/recall commands and changed auto reflevel target to -30 --- main.c | 4 ++-- sa_core.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index d500bea..ff2bade 100644 --- a/main.c +++ b/main.c @@ -1620,6 +1620,7 @@ VNA_SHELL_FUNCTION(cmd_cal) } shell_printf("usage: cal [%s]\r\n", cmd_cal_list); } +#endif VNA_SHELL_FUNCTION(cmd_save) { @@ -1654,7 +1655,6 @@ VNA_SHELL_FUNCTION(cmd_recall) usage: shell_printf("recall {id}\r\n"); } -#endif static const struct { const char *name; @@ -2308,9 +2308,9 @@ static const VNAShellCommand commands[] = {"resume" , cmd_resume , 0}, #ifdef __VNA__ {"cal" , cmd_cal , CMD_WAIT_MUTEX}, +#endif {"save" , cmd_save , 0}, {"recall" , cmd_recall , CMD_WAIT_MUTEX}, -#endif {"trace" , cmd_trace , CMD_WAIT_MUTEX}, {"trigger" , cmd_trigger , 0}, {"marker" , cmd_marker , 0}, diff --git a/sa_core.c b/sa_core.c index 81e2c84..77272fb 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2029,18 +2029,18 @@ sweep_again: // stay in sweep loop when output mo // -------------------------- auto attenuate ---------------------------------- - +#define AUTO_TARGET_LEVEL -30 if (!in_selftest && setting.mode == M_LOW && setting.auto_attenuation && max_index[0] > 0) { // calculate and apply auto attenuate setting.atten_step = false; // No step attenuate in low mode auto attenuate int changed = false; float actual_max_level = actual_t[max_index[0]] - get_attenuation(); - if (actual_max_level < - 31 && setting.attenuate >= 10) { + if (actual_max_level < AUTO_TARGET_LEVEL - 11 && setting.attenuate >= 10) { setting.attenuate -= 10.0; changed = true; - } else if (actual_max_level < - 26 && setting.attenuate >= 5) { + } else if (actual_max_level < AUTO_TARGET_LEVEL - 6 && setting.attenuate >= 5) { setting.attenuate -= 5.0; changed = true; - } else if (actual_max_level > - 19 && setting.attenuate <= 20) { + } else if (actual_max_level > AUTO_TARGET_LEVEL + 2 && setting.attenuate <= 20) { setting.attenuate += 10.0; changed = true; }