From f0c4a8f547e916e53422265665ce3fd9799ce4d4 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 7 Feb 2023 09:48:36 +0100 Subject: [PATCH] Added output curve editing --- main.c | 29 ++++++++++++++++++++-------- nanovna.h | 14 ++++++++------ sa_core.c | 44 +++++++++++++++++++++---------------------- ui.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 100 insertions(+), 43 deletions(-) diff --git a/main.c b/main.c index c6300c3..eb360be 100644 --- a/main.c +++ b/main.c @@ -89,7 +89,7 @@ uint8_t sweep_mode = SWEEP_ENABLE; uint16_t sweep_once_count = 1; uint16_t redraw_request = 0; // contains REDRAW_XXX flags // Version text, displayed in Config->Version menu, also send by info command -const char *info_about[]={ +const char * const info_about[]={ BOARD_NAME, "2019-2022 Copyright @Erik Kaashoek", "2016-2020 Copyright @edy555", @@ -966,14 +966,27 @@ config_t config = { .vbat_offset = 500, .low_level_offset = 0, // Uncalibrated .high_level_offset = 0, // Uncalibrated - .correction_frequency = { { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, - { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }}, + .correction_frequency = + { + { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 349000000 }, + { 241000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 958000000 }, + { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 349000000 }, +// { 241000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 958000000 } + }, #ifdef __ULTRA__ - .correction_value = { { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +0.4, +0.4, +0.4 }, - { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, + .correction_value = + { + { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +0.4, +0.4, +0.4 }, + { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, + { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +0.4, +0.4, +0.4 }}, +// { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, #else - .correction_value = { { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, - { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, + .correction_value = + { + { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, + { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 }, + { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }}, +// { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, #endif .setting_frequency_10mhz = 10000000, .cor_am = 0,// -10, @@ -1949,7 +1962,7 @@ VNA_SHELL_FUNCTION(cmd_color) #if CH_CFG_USE_REGISTRY == FALSE #error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h" #endif -const char *states[] = {CH_STATE_NAMES}; +const char *const states[] = {CH_STATE_NAMES}; VNA_SHELL_FUNCTION(cmd_threads) { thread_t *tp; diff --git a/nanovna.h b/nanovna.h index aece004..3da5e6b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -114,7 +114,7 @@ #else //#define __ULTRA__ //#define __HARMONIC__ -#define __USE_FREQ_TABLE__ // Enable use table for frequency list +//#define __USE_FREQ_TABLE__ // Enable use table for frequency list #endif #ifdef TINYSA3 @@ -205,16 +205,18 @@ typedef uint32_t freq_t; typedef int32_t long_t; extern bool has_esd; #define CORRECTION_POINTS 10 // Frequency dependent level correction table entries - #define CORRECTION_LOW 0 - #define CORRECTION_HIGH 1 +#define CORRECTION_LOW_IN 0 +#define CORRECTION_HIGH_IN 1 +#define CORRECTION_LOW_OUT 2 +#define CORRECTION_HIGH_OUT 3 // #define CORRECTION_LOW_OUT 2 // Must be same order as output path options!!!!! - #define CORRECTION_SIZE 2 + #define CORRECTION_SIZE 3 #endif #ifdef TINYSA4 typedef uint64_t freq_t; typedef int64_t long_t; #define CORRECTION_POINTS 20 // Frequency dependent level correction table entries - #define CORRECTION_LOW 0 + #define CORRECTION_LOW_IN 0 #define CORRECTION_LNA 1 #define CORRECTION_LOW_ULTRA 2 #define CORRECTION_LNA_ULTRA 3 @@ -330,7 +332,7 @@ enum { extern uint8_t sweep_mode; extern uint8_t completed; -extern const char *info_about[]; +extern const char * const info_about[]; #ifdef TINYSA4 void toggle_extra_lna(void); diff --git a/sa_core.c b/sa_core.c index d8c179e..e252a45 100644 --- a/sa_core.c +++ b/sa_core.c @@ -154,7 +154,7 @@ int signal_path = PATH_OFF; #ifdef TINYSA4 -const char *path_text[]=PATH_TEXT; +const char *const path_text[]=PATH_TEXT; void set_output_drive(int d) { @@ -689,8 +689,8 @@ void reset_settings(int m) setting.lo_drive=5; setting.extra_lna = false; #endif -// setting.correction_frequency = config.correction_frequency[CORRECTION_LOW]; -// setting.correction_value = config.correction_value[CORRECTION_LOW]; +// setting.correction_frequency = config.correction_frequency[CORRECTION_LOW_IN]; +// setting.correction_value = config.correction_value[CORRECTION_LOW_IN]; break; case M_GENLOW: #ifdef TINYSA4 @@ -709,8 +709,8 @@ void reset_settings(int m) // setting.correction_frequency = config.correction_frequency[CORRECTION_LOW_OUT]; // setting.correction_value = config.correction_value[CORRECTION_LOW_OUT]; #else -// setting.correction_frequency = config.correction_frequency[CORRECTION_LOW]; -// setting.correction_value = config.correction_value[CORRECTION_LOW]; +// setting.correction_frequency = config.correction_frequency[CORRECTION_LOW_IN]; +// setting.correction_value = config.correction_value[CORRECTION_LOW_IN]; #endif // level_min = SL_GENLOW_LEVEL_MIN + LOW_OUT_OFFSET; // level_max = SL_GENLOW_LEVEL_MAX + LOW_OUT_OFFSET; @@ -723,8 +723,8 @@ void reset_settings(int m) #ifdef TINYSA4 setting.extra_lna = false; #endif -// setting.correction_frequency = config.correction_frequency[CORRECTION_HIGH]; -// setting.correction_value = config.correction_value[CORRECTION_HIGH]; +// setting.correction_frequency = config.correction_frequency[CORRECTION_HIGH_IN]; +// setting.correction_value = config.correction_value[CORRECTION_HIGH_IN]; break; case M_GENHIGH: #ifdef TINYSA4 @@ -739,8 +739,8 @@ void reset_settings(int m) set_sweep_frequency(ST_SPAN, 0); setting.sweep_time_us = 2*ONE_SECOND_TIME; setting.step_delay_mode = SD_FAST; -// setting.correction_frequency = config.correction_frequency[CORRECTION_HIGH]; -// setting.correction_value = config.correction_value[CORRECTION_HIGH]; +// setting.correction_frequency = config.correction_frequency[CORRECTION_HIGH_IN]; +// setting.correction_value = config.correction_value[CORRECTION_HIGH_IN]; // level_min = SL_GENHIGH_LEVEL_MIN + config.high_level_output_offset; // level_max = SL_GENHIGH_LEVEL_MAX + config.high_level_output_offset; // level_range = level_max - level_min; @@ -1011,8 +1011,8 @@ void set_extra_lna(int t) setting.correction_frequency = config.correction_frequency[CORRECTION_LNA]; setting.correction_value = config.correction_value[CORRECTION_LNA]; } else { - setting.correction_frequency = config.correction_frequency[CORRECTION_LOW]; - setting.correction_value = config.correction_value[CORRECTION_LOW]; + setting.correction_frequency = config.correction_frequency[CORRECTION_LOW_IN]; + setting.correction_value = config.correction_value[CORRECTION_LOW_IN]; } #endif dirty = true; @@ -2149,13 +2149,7 @@ static void calculate_correction(void) pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI correction to subtract for imperfect LPF { pureRSSI_t cv = 0; - int c=CORRECTION_LOW; -#ifdef TINYSA3 - if (setting.mode == M_GENHIGH) { - c = CORRECTION_HIGH; - return float_TO_PURE_RSSI(0.0); - } -#endif + int c=CORRECTION_LOW_IN; #ifdef TINYSA4 if (setting.mode == M_LOW) { @@ -2189,7 +2183,7 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c switch (signal_path) { case PATH_LOW: - c = CORRECTION_LOW; + c = CORRECTION_LOW_IN; break; case PATH_ULTRA: c = CORRECTION_LOW_ULTRA; @@ -2232,8 +2226,14 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c } } #else - if (MODE_HIGH(setting.mode)) - c = CORRECTION_HIGH; + if (setting.mode == M_HIGH) + c = CORRECTION_HIGH_IN; + else if (setting.mode == M_GENLOW) + c = CORRECTION_LOW_OUT; + else if (setting.mode == M_GENHIGH) { + cv = 0; + goto done; + } #endif @@ -6078,7 +6078,7 @@ const test_case_t test_case [] = enum { TS_WAITING, TS_PASS, TS_FAIL, TS_CRITICAL }; -static const char *(test_text [4]) = +static const char *const test_text [4] = { "Waiting", "Pass", "Fail", "Critical" }; diff --git a/ui.c b/ui.c index a85a3ee..cf7cded 100644 --- a/ui.c +++ b/ui.c @@ -1277,7 +1277,7 @@ static const keypads_t keypads_time[] = { }; #ifdef __USE_SD_CARD__ -static const keypads_t keypads_text[] = { +static const keypads_t const keypads_text[] = { {40, TXT_KEYBOARD }, // size and position {0x00, '1'}, {0x10, '2'}, {0x20, '3'}, {0x30, '4'}, {0x40, '5'}, {0x50, '6'}, {0x60, '7'}, {0x70, '8'}, {0x80, '9'}, {0x90, '0'}, {0x01, 'Q'}, {0x11, 'W'}, {0x21, 'E'}, {0x31, 'R'}, {0x41, 'T'}, {0x51, 'Y'}, {0x61, 'U'}, {0x71, 'I'}, {0x81, 'O'}, {0x91, 'P'}, @@ -1569,6 +1569,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_curve_acb) config.correction_value[current_curve][data]); return; } + int old_m = 0; + (void)old_m; switch(current_curve) { #ifdef TINYSA4 case CORRECTION_LOW_OUT: @@ -1608,17 +1610,47 @@ static UI_FUNCTION_ADV_CALLBACK(menu_curve_acb) reset_settings(M_LOW); setting.extra_lna = true; goto common; +#else + case CORRECTION_LOW_OUT: + old_m = setting.mode; + reset_settings(M_GENLOW); + goto common_out; +// case CORRECTION_HIGH_OUT: +// old_m = setting.mode; +// reset_settings(M_GENHIGH); + common_out: + dirty = true; + set_level(-25); + set_sweep_frequency(ST_CW, config.correction_frequency[current_curve][data]); + setting.mute = false; + perform(false, 0, config.correction_frequency[current_curve][data], false); + perform(false, 1, config.correction_frequency[current_curve][data], false); + plot_printf(uistat.text, sizeof uistat.text, "Level of %.3QHz output", + config.correction_frequency[current_curve][data]); + kp_help_text = uistat.text; + kp_buf[0]=0; + ui_mode_keypad(KM_LEVEL); + + if (kp_buf[0] != 0) { + float new_offset = (-25.0) - uistat.value + config.correction_value[current_curve][data]; // calculate offset based on difference between measured peak level and known peak level + if (new_offset > -25 && new_offset < 25) { + config.correction_value[current_curve][data] = new_offset; + config_save(); + } + } + reset_settings(old_m); + break; #endif #ifdef TINYSA4 case CORRECTION_LOW_ULTRA: goto common; #else - case CORRECTION_HIGH: + case CORRECTION_HIGH_IN: reset_settings(M_HIGH); goto common; #endif - case CORRECTION_LOW: + case CORRECTION_LOW_IN: reset_settings(M_LOW); common: set_sweep_frequency(ST_SPAN, 1000000); @@ -1677,7 +1709,7 @@ static UI_FUNCTION_CALLBACK(menu_input_curve_prepare_cb) ui_mode_keypad(KM_LEVEL); if (kp_buf[0] != 0) { local_actual_level = uistat.value; - current_curve = CORRECTION_LOW; + current_curve = CORRECTION_LOW_IN; menu_push_submenu(menu_curve); } } @@ -1695,7 +1727,7 @@ static UI_FUNCTION_CALLBACK(menu_high_curve_prepare_cb) ui_mode_keypad(KM_LEVEL); if (kp_buf[0] != 0) { local_actual_level = uistat.value; - current_curve = CORRECTION_HIGH; + current_curve = CORRECTION_HIGH_IN; menu_push_submenu(menu_curve); } } @@ -1789,6 +1821,14 @@ static UI_FUNCTION_CALLBACK(menu_output_adf_curve_prepare_cb) current_curve = CORRECTION_LOW_OUT_ADF; menu_push_submenu(menu_curve); } +#else +static UI_FUNCTION_CALLBACK(menu_output_curve_prepare_cb) +{ + (void)item; + current_curve = data; + menu_push_submenu(menu_curve); +} + #endif #endif @@ -2158,7 +2198,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_lowoutput_settings_acb) #endif // const int menu_modulation_value[]={MO_NONE,MO_AM, MO_NFM, MO_WFM, MO_EXTERNAL}; -const char *menu_modulation_text[MO_MAX]= +const char * const menu_modulation_text[MO_MAX]= { "None", "AM 30%", #ifdef TINYSA4 "FM 2.5kHz", @@ -2208,7 +2248,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ } // 0 1 2 3 4 5 6 7 -const char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; +const char *const menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; static UI_FUNCTION_ADV_CALLBACK(menu_reffer_acb) { (void)item; @@ -4191,6 +4231,8 @@ static const menuitem_t menu_actual_power[] = #else { MT_CALLBACK, 0, "IN LOW\nCURVE", menu_input_curve_prepare_cb}, { MT_CALLBACK, 0, "IN HIGH\nCURVE", menu_high_curve_prepare_cb}, + { MT_CALLBACK, CORRECTION_LOW_OUT, "OUT LOW\nCURVE", menu_output_curve_prepare_cb}, +// { MT_CALLBACK, CORRECTION_HIGH_OUT,"OUT HIGH\nCURVE", menu_output_curve_prepare_cb}, #endif #endif { MT_NONE, 0, NULL, menu_back} // next-> menu_back