From 5ac2dcab109433a46d0a8f21b97f494ca883ae48 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 24 Jul 2022 09:12:35 +0200 Subject: [PATCH] Many updates --- nanovna.h | 18 ++++++++--- plot.c | 4 +-- sa_core.c | 93 +++++++++++++++++++++++++++++++++++++++++-------------- ui.c | 2 +- ui_sa.c | 44 ++++++++++++++++++++------ 5 files changed, 120 insertions(+), 41 deletions(-) diff --git a/nanovna.h b/nanovna.h index 6196037..a222960 100644 --- a/nanovna.h +++ b/nanovna.h @@ -280,7 +280,11 @@ enum { }; enum { - MO_NONE, MO_AM, MO_NFM, MO_WFM, MO_EXTERNAL, + MO_NONE, MO_AM, MO_NFM, +#ifdef TINYSA4 + MO_NFM2, MO_NFM3, +#endif + MO_WFM, MO_EXTERNAL, MO_MAX }; #define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) @@ -760,6 +764,10 @@ typedef struct config { int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; +#ifdef TINYSA4 + int8_t cor_nfm2; + int8_t cor_nfm3; +#endif uint8_t _brightness; #ifndef __NEW_SWITCHES__ uint8_t high_out_adf4350; @@ -1326,7 +1334,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e56 /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e57 /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; @@ -1383,9 +1391,9 @@ void clear_all_config_prop_data(void); // Set structure align as WORD (save flash memory) #pragma pack(push, 2) typedef struct { - uint8_t type; - uint8_t data; - char *label; + const uint8_t type; + const uint8_t data; + const char *label; const void *reference; } menuitem_t; #pragma pack(pop) diff --git a/plot.c b/plot.c index 268946c..4794d8e 100644 --- a/plot.c +++ b/plot.c @@ -1548,10 +1548,10 @@ static void trace_print_value_string( // Only used at one place #else if (bold) format++; // Skip small prefix for bold output #endif - cell_printf(xpos, ypos, format, buf2, v, unit_string[unit_index], (mtype & M_NOISE?"/Hz":""), (mtype & M_AVER?"/T":"")); + cell_printf(xpos, ypos, format, buf2, v, unit_string[unit_index], (mtype & M_NOISE?"c/Hz":""), (mtype & M_AVER?"/T":"")); #ifdef __LEVEL_METER__ if (level_text[0] == 0) - plot_printf(level_text, sizeof(level_text), &format[3], v, unit_string[unit_index], (mtype & M_NOISE?"/Hz":"") ,(mtype & M_AVER?"/T":"")); + plot_printf(level_text, sizeof(level_text), &format[3], v, unit_string[unit_index], (mtype & M_NOISE?"c/Hz":"") ,(mtype & M_AVER?"/T":"")); #endif } diff --git a/sa_core.c b/sa_core.c index 56a1e8f..d793e19 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1326,9 +1326,11 @@ void limits_update(void) int prev = -1; if (setting.average[t] != AV_TABLE) continue; + int count = 0; for (int i = 0; i DIRECT_START && f= MINIMUM_DIRECT_FREQ && f < ultra_start) ); @@ -3545,9 +3555,25 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / #endif modulation_delay = ((1000000-MO_FREQ_COR)/ MODULATION_STEPS ) / setting.modulation_frequency; // 8 steps so 1MHz/8 modulation_counter = 0; + modulation_index = 0; if (setting.modulation == MO_AM) // -14 default modulation_delay += config.cor_am; - else { // must be FM + else { +#ifdef TINYSA4 + switch(setting.modulation){ + case MO_NFM: + modulation_delay += config.cor_nfm; + break; + modulation_delay += config.cor_nfm2; + break; + modulation_delay += config.cor_nfm3; + break; + modulation_delay += config.cor_wfm; + break; + } + modulation_index = setting.modulation - MO_NFM; +#else + // must be FM if (setting.modulation == MO_WFM) { // -17 default modulation_delay += config.cor_wfm; modulation_index = 1; @@ -3555,16 +3581,18 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / modulation_delay += config.cor_nfm; // -17 default // modulation_index = 0; // default value } +#endif #ifdef TINYSA4 - if ((setting.mode == M_GENLOW) || - (setting.mode == M_GENHIGH && f > ((freq_t)480000000) ) ) + if (false) #else if ((setting.mode == M_GENLOW && f > ((freq_t)480000000) - DEFAULT_IF) || (setting.mode == M_GENHIGH && f > ((freq_t)480000000) ) ) #endif modulation_index += 2; current_fm_modulation = (int *)fm_modulation[modulation_index]; +#ifdef TINYSA3 f -= fm_modulation_offset[modulation_index]; // Shift output frequency +#endif } } } @@ -4530,10 +4558,12 @@ static bool sweep(bool break_on_operation) int refreshing = false; if (MODE_OUTPUT(setting.mode) && config.cor_nfm == 0) { // Calibrate the modulation frequencies at first use -//#ifndef TINYSA4 - calibrate_modulation(MO_AM, &config.cor_am); // No AM mondulation for now -//#endif + calibrate_modulation(MO_AM, &config.cor_am); calibrate_modulation(MO_NFM, &config.cor_nfm); +#ifdef TINYSA4 + calibrate_modulation(MO_NFM2, &config.cor_nfm2); + calibrate_modulation(MO_NFM3, &config.cor_nfm3); +#endif calibrate_modulation(MO_WFM, &config.cor_wfm); } @@ -6750,7 +6780,23 @@ static int R_table[R_TABLE_SIZE] = {1,3,-3,4,5}; perform(false,0, 30000000, false); perform(false,1, 30000000, false); config.cor_nfm = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; +#ifdef TINYSA4 + setting.modulation = MO_NFM2; + setting.modulation_frequency = 5000; + in_selftest = true; + config.cor_nfm2 = 0; + perform(false,0, 30000000, false); + perform(false,1, 30000000, false); + config.cor_nfm2 = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; + setting.modulation = MO_NFM3; + setting.modulation_frequency = 5000; + in_selftest = true; + config.cor_nfm3 = 0; + perform(false,0, 30000000, false); + perform(false,1, 30000000, false); + config.cor_nfm3 = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency))/8; +#endif setting.modulation = MO_WFM; setting.modulation_frequency = 5000; in_selftest = true; @@ -7021,6 +7067,7 @@ void calibrate_modulation(int modulation, int8_t *correction) in_selftest = false; *correction = -(start_of_sweep_timestamp - (ONE_SECOND_TIME / setting.modulation_frequency ))/8; setting.modulation = M_OFF; + setting.modulation_frequency = 1000; } } diff --git a/ui.c b/ui.c index 80ebef0..42def71 100644 --- a/ui.c +++ b/ui.c @@ -1234,7 +1234,7 @@ draw_menu_buttons(const menuitem_t *menu, uint32_t mask) text = button.text; } else - text = m->label; + text = (char *)m->label; // Only keypad retrieves value if (MT_MASK(m->type) == MT_KEYPAD) { fetch_numeric_target(m->data); diff --git a/ui_sa.c b/ui_sa.c index 92b0bb8..31634a5 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1048,12 +1048,22 @@ 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[]={"None", "AM", "NFM", "WFM", "External"}; +const char *menu_modulation_text[MO_MAX]= +{ "None", "AM 30%", +#ifdef TINYSA4 + "FM 2.5kHz", + "FM 3kHz", + "FM 5kHz", +#else + "FM 5kHz", +#endif + "FM 75kHz", "External"}; static UI_FUNCTION_ADV_CALLBACK(menu_modulation_acb) { (void)item; if (b){ + plot_printf(b->text, sizeof b->text, "%s", menu_modulation_text[data]); b->icon = data == setting.modulation ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; return; } @@ -1063,9 +1073,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_modulation_acb) set_level_sweep(0); } set_modulation(data); - menu_move_back(false); -// ui_mode_normal(); // Stay in menu mode -// draw_cal_status(); +// menu_move_back(false); // Don't move back } static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ @@ -1075,7 +1083,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL) plot_printf(b->text, sizeof b->text, "MOD: %s", menu_modulation_text[setting.modulation]); else { - plot_printf(b->text, sizeof b->text, "MOD: %5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); + plot_printf(b->text, sizeof b->text, "MOD: %4dHz %s", (int)(setting.modulation_frequency), menu_modulation_text[setting.modulation]); } return; } @@ -1964,6 +1972,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_limit_select_acb) { (void)item; if(b){ + int count = 0; + for (int i=0;itext, sizeof(b->text), "%.6FHz\n%.2F%s", (float)setting.limits[current_trace][data].frequency, value(setting.limits[current_trace][data].level),unit_string[setting.unit]); b->icon = (setting.limits[current_trace][data].enabled?BUTTON_ICON_CHECK:BUTTON_ICON_NOCHECK) ; return; @@ -2083,6 +2094,13 @@ static UI_FUNCTION_CALLBACK(menu_limit_disable_cb) { (void)item; (void)data; + int count = 0; + for (int i=0;i menu_back };