From e5dbf7024b80cc61bf182bd6b92f0f15f6db07c9 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 7 Jan 2024 17:39:33 +0100 Subject: [PATCH] SETUP magic update --- main.c | 3 +++ nanovna.h | 5 +++-- sa_cmd.c | 30 +++++++++++++------------- sa_core.c | 63 ++++++++++++++++++++++++++++++++++++------------------- ui.c | 4 +++- 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/main.c b/main.c index ae9e8b1..dfcb256 100644 --- a/main.c +++ b/main.c @@ -1114,6 +1114,7 @@ config_t config = { .high_level_output_offset = 0, // Uncalibrated, but checking code is not yet present .harmonic_level_offset = 0, // 10.5, should be in correction table now .harmonic_lna_level_offset = 0, // 10.5, should be in correction table now + .shift_level_offset = 0, .shift1_level_offset = 0.5, .shift2_level_offset = 3, .shift3_level_offset = 0, @@ -1721,6 +1722,7 @@ VNA_SHELL_FUNCTION(cmd_sweep) int type = get_str_index(argv[0], sweep_cmd); if (type >=0) { set_sweep_frequency(type, value1); + dirty = true; return; } // Parse sweep {go|abort} @@ -1735,6 +1737,7 @@ VNA_SHELL_FUNCTION(cmd_sweep) set_sweep_frequency(ST_STOP, value1); if (value2) set_sweep_points(value2); + dirty = true; return; usage: usage_printf("sweep {start(Hz)} [stop(Hz)] [points]\r\n"\ diff --git a/nanovna.h b/nanovna.h index 544b69b..8d1777d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -804,6 +804,7 @@ typedef struct config { float lna_level_offset; float harmonic_level_offset; float harmonic_lna_level_offset; + float shift_level_offset; float shift1_level_offset; float shift2_level_offset; float shift3_level_offset; @@ -1471,8 +1472,8 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e66 /* 'CONF' */ -#define SETTING_MAGIC 0x434f4e65 +#define CONFIG_MAGIC 0x434f4e67 +#define SETTING_MAGIC 0x434f4e66 extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/sa_cmd.c b/sa_cmd.c index 11bc049..2e11737 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -408,7 +408,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|harmonic_lna|adf"; + static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|harmonic_lna|adf"; #else static const char cmd_mode_list[] = "low|high|switch|receive_switch"; #endif @@ -431,6 +431,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "lna", config.lna_level_offset); shell_printf(p, "harmonic", config.harmonic_level_offset); shell_printf(p, "harmonic_lna", config.harmonic_lna_level_offset); + shell_printf(p, "shift", config.shift_level_offset); shell_printf(p, "shift1", config.shift1_level_offset); shell_printf(p, "shift2", config.shift2_level_offset); shell_printf(p, "shift3", config.shift3_level_offset); @@ -468,18 +469,19 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 3: config.out_switch_offset = v; break; case 4: config.lna_level_offset = v; break; case 5: config.harmonic_level_offset = v; break; - case 6: config.shift1_level_offset = v; break; - case 7: config.shift2_level_offset = v; break; - case 8: config.shift3_level_offset = v; break; - case 9: config.drive1_level_offset = v; break; - case 10: config.drive2_level_offset = v; break; - case 11: config.drive3_level_offset = v; break; - case 12: config.direct_level_offset = v; break; - case 13: config.direct_lna_level_offset = v; break; - case 14: config.ultra_level_offset = v; break; - case 15: config.ultra_lna_level_offset = v; break; - case 16: config.harmonic_lna_level_offset = v; break; - case 17: config.adf_level_offset = v; break; + case 6: config.shift_level_offset = v; break; + case 7: config.shift1_level_offset = v; break; + case 8: config.shift2_level_offset = v; break; + case 9: config.shift3_level_offset = v; break; + case 10: config.drive1_level_offset = v; break; + case 11: config.drive2_level_offset = v; break; + case 12: config.drive3_level_offset = v; break; + case 13: config.direct_level_offset = v; break; + case 14: config.direct_lna_level_offset = v; break; + case 15: config.ultra_level_offset = v; break; + case 16: config.ultra_lna_level_offset = v; break; + case 17: config.harmonic_lna_level_offset = v; break; + case 18: config.adf_level_offset = v; break; #endif default: goto usage; } @@ -492,7 +494,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 0: config.low_level_output_offset = v; config.output_is_calibrated = true; break; case 1: config.high_level_output_offset = v; break; #ifdef TINYSA4 - case 12: config.direct_level_output_offset = v; break; + case 19: config.direct_level_output_offset = v; break; #endif default: goto usage; } diff --git a/sa_core.c b/sa_core.c index dfa2ea7..93b8967 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4867,8 +4867,12 @@ again: // Spur redu pureRSSI = 0; else { pureRSSI = Si446x_RSSI(break_on_operation); - if (LO_shifting && signal_path != PATH_DIRECT) - pureRSSI += float_TO_PURE_RSSI(actual_rbw_x10>USE_SHIFT2_RBW ? config.shift2_level_offset : (lf < LOW_SHIFT_FREQ ? config.shift1_level_offset: 0.0)); + if (LO_shifting && (signal_path != PATH_DIRECT)) { + if (f < 5000000) + pureRSSI += float_TO_PURE_RSSI(actual_rbw_x10>USE_SHIFT2_RBW ? config.shift2_level_offset : (lf < LOW_SHIFT_FREQ ? config.shift1_level_offset: 0.0)); + else + pureRSSI += float_TO_PURE_RSSI(config.shift_level_offset); + } } if (setting.unit == U_RAW) pureRSSI += - float_TO_PURE_RSSI(120); // don't add correction; @@ -6218,9 +6222,7 @@ enum { #ifdef TINYSA4 freq_t test_freq = 0; -//#define CAL_LEVEL -23.5 -//#define CAL_LEVEL -24.2 -#define CAL_LEVEL -35.60 +#define CAL_LEVEL -35.30 #else #define CAL_LEVEL (has_esd ? -26.2 : -25) #endif @@ -6338,7 +6340,9 @@ static volatile int test_wait = false; static float test_value; #ifdef TINYSA4 -static freq_t direct_test_freq = 900000000; +static freq_t spur_test_freq = 900000000; +static freq_t direct_test_freq = 180000000; + void determine_direct_test_freq(void) { return; int old_ultra = config.ultra; @@ -7705,7 +7709,7 @@ float get_jump_config(int i) { return 0; } -enum {CS_NORMAL, CS_LNA, CS_SWITCH, CS_ULTRA, CS_ULTRA_LNA, CS_DIRECT_REF, CS_DIRECT, CS_DIRECT_LNA, CS_HARMONIC, CS_HARMONIC_LNA, /* CS_BPF_REF, CS_BPF, */ CS_CORRECTION_REF, CS_CORRECTION_LNA, CS_MAX }; +enum {CS_NORMAL, CS_LNA, CS_SWITCH, CS_ULTRA, CS_ULTRA_LNA, CS_DIRECT_REF, /* CS_DIRECT,*/ CS_DIRECT_LNA, CS_SPUR_REF, CS_SPUR_ERROR, CS_HARMONIC, CS_HARMONIC_LNA, /* CS_BPF_REF, CS_BPF, */ CS_CORRECTION_REF, CS_CORRECTION_LNA, CS_MAX }; #define ULTRA_HARMONIC_CAL_FREQ 5340000000 #else enum {CS_NORMAL, CS_SWITCH, CS_MAX }; @@ -7826,6 +7830,7 @@ void calibrate(void) // setting.rbw_x10 = 3; test_path = 3; // Ultra lna path force_signal_path = true; + setting.spur_removal = S_OFF; // set_reflevel(-95); } else if (i <= 1) { if (i == 1) @@ -7837,6 +7842,7 @@ void calibrate(void) set_refer_output(0); // 30MHz setting.spur_removal = S_AUTO_OFF; } + test_acquire(TEST_JUMP); // Acquire test set_reflevel(actual_t[sweep_points/3]+5); plot_into_index(measured); @@ -7914,23 +7920,33 @@ void calibrate(void) test_path = 1; // Normal lna path force_signal_path = true; break; - case CS_DIRECT_REF: - set_sweep_frequency(ST_CENTER, direct_test_freq); + + case CS_SPUR_REF: + setting.spur_removal = S_OFF; + goto spur_common; + case CS_SPUR_ERROR: + setting.spur_removal = S_AUTO_OFF; + config.shift_level_offset = 0; + spur_common: + set_sweep_frequency(ST_CENTER, spur_test_freq); test_path = 2; // Ultra force_signal_path = true; break; - case CS_DIRECT: + case CS_DIRECT_REF: + test_path = 0; // Normal + setting.spur_removal = S_OFF; + direct_common: set_sweep_frequency(ST_CENTER, direct_test_freq); - test_path = 4; // Direct path at 900MHz force_signal_path = true; - // config.direct_level_offset -= 1.0; break; +#if 0 + case CS_DIRECT: + test_path = 4; // Direct path at 900MHz + goto direct_common; +#endif case CS_DIRECT_LNA: - set_sweep_frequency(ST_CENTER, direct_test_freq); test_path = 5; // Direct lna path at 900MHz - force_signal_path = true; -// config.direct_lna_level_offset += 1.0; - break; + goto direct_common; case CS_HARMONIC: test_path = 6; // harmonic path force_signal_path = true; @@ -8005,7 +8021,7 @@ void calibrate(void) #ifdef TINYSA4 || (calibration_stage == CS_LNA && peakLevel < -40) || (calibration_stage == CS_ULTRA && peakLevel < -40) - || (calibration_stage == CS_DIRECT && peakLevel < direct_level - 10) + || (calibration_stage == CS_DIRECT_LNA && peakLevel < direct_level - 10) #endif ) { #ifdef TINYSA4 @@ -8033,14 +8049,17 @@ low_level: calibration_stage -= 2; // skip back to REF measurement } } + else if (calibration_stage == CS_SPUR_REF) + direct_level = marker_to_value(0); // Re-use direct_level; + else if (calibration_stage == CS_SPUR_ERROR) + config.shift_level_offset = direct_level - marker_to_value(0); else if (calibration_stage == CS_DIRECT_REF) direct_level = marker_to_value(0); - else if (calibration_stage == CS_DIRECT){ -// config.direct_level_offset += 1.0; - offset = set_actual_power(direct_level); - } else if (calibration_stage == CS_DIRECT_LNA){ -// config.direct_lna_level_offset -= 1.0; +// else if (calibration_stage == CS_DIRECT) +// offset = set_actual_power(direct_level); + else if (calibration_stage == CS_DIRECT_LNA){ offset = set_actual_power(direct_level); + config.direct_level_offset = config.direct_lna_level_offset - (config.low_level_offset - config.lna_level_offset); } else #endif diff --git a/ui.c b/ui.c index 91eace0..512ac18 100644 --- a/ui.c +++ b/ui.c @@ -5150,7 +5150,9 @@ static const menuitem_t menu_trigger[] = { #ifdef __BEEP__ { MT_ADV_CALLBACK, T_BEEP, "BEEP", menu_trigger_acb}, #endif +#ifdef TINYSA4 { MT_ADV_CALLBACK, T_AUTO_SAVE, "AUTO SAVE", menu_trigger_acb}, +#endif { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; @@ -5204,7 +5206,7 @@ static const menuitem_t menu_storage[] = { { MT_CALLBACK, FMT_CFG_FILE, "SAVE\nCONFIG", menu_sdcard_cb}, { MT_ADV_CALLBACK, 0, "MHz\nCSV", menu_mhz_csv_acb }, { MT_CALLBACK, FMT_CSV_FILE, "SAVE\nTRACES", menu_save_traces_cb}, - { MT_KEYPAD, KM_INTERVAL, "INTERVAL\n\b%s", NULL }, +// { MT_KEYPAD, KM_INTERVAL, "INTERVAL\n\b%s", NULL }, { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; #endif