From fbb3797017cef9e2c2122c39b3de0a5337fd2947 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 12 Apr 2021 07:54:06 +0200 Subject: [PATCH] Separate output correction --- main.c | 17 ++++++++++---- nanovna.h | 13 +++++++---- sa_cmd.c | 23 ++++++++++++++++--- sa_core.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 94 insertions(+), 26 deletions(-) diff --git a/main.c b/main.c index 622abd5..f324e41 100644 --- a/main.c +++ b/main.c @@ -1016,10 +1016,18 @@ config_t config = { .lna_level_offset = 100, .low_level_output_offset = 0.0, // Uncalibrated .high_level_output_offset = 0.0, // Uncalibrated - .correction_frequency = {{ 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }, - { 1000000, 500000000, 1000000000, 1500000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000, 7000000000, 7500000000, 8000000000, 8500000000, 9000000000, 10000000000 }}, - .correction_value = {{ 0, +1, +2, +2.5, +3, +3.5, +6.5, +9.5, +10, +9, +9, +23, +24, +24, +24, +24, +24, +24, +24, +24 }, - { 0, +1, +2.5, +1, +2.5, +6, +9, +11.5, +14.5, +23, +25, +36, +46, +46, +46, +46, +46, +46, +46, +46 }}, + .correction_frequency = + { + { 10000, 100000, 300000, 1000000, 30000000, 500000000, 750000000, 1000000000, 1500000000, 1520000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000 }, + { 10000, 100000, 300000, 1000000, 30000000, 500000000, 750000000, 1000000000, 1500000000, 1520000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000 }, + { 10000, 100000, 300000, 1000000, 30000000, 500000000, 750000000, 1000000000, 1500000000, 1520000000, 2000000000, 2500000000, 3000000000, 3500000000, 4000000000, 4500000000, 5000000000, 5500000000, 6000000000, 6500000000 }, + }, + .correction_value = + { + { 10.5, +4.9, +1.6, +0.6, 0, 0, +4, +2.5, +2, +2, +2, +3.5, +6.5, +6.5, +9, +9, +9, +11, +11, +11, }, + { 10.5, +4.9, +1.6, +0.6, 0, 0, +4, +2.5, +2, +2, +2, +6, +9, +11.5, +14.5, +23, +25, +36, +46, +46, }, + { 10.5, +4.9, +1.6, +0.6, 0, 0, +4, +2.5, +2, +2, +2, +3.5, +6.5, +6.5, +9, +9, +9, +11, +11, +11, }, + }, .setting_frequency_30mhz = 30000000, .cor_am = 0, .cor_wfm = 0, @@ -2508,6 +2516,7 @@ static const VNAShellCommand commands[] = #endif #ifdef TINYSA4 { "g", cmd_g, CMD_WAIT_MUTEX }, + { "z", cmd_z, CMD_WAIT_MUTEX }, #endif #ifdef __ADF4351__ { "x", cmd_x, CMD_WAIT_MUTEX }, diff --git a/nanovna.h b/nanovna.h index 7d8fb38..f05b7a3 100644 --- a/nanovna.h +++ b/nanovna.h @@ -134,10 +134,11 @@ typedef uint32_t freq_t; 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_LNA 1 -#define CORRECTION_HIGH 2 -#define CORRECTION_SIZE 3 +#define CORRECTION_LOW 0 +#define CORRECTION_LNA 1 +#define CORRECTION_LOW_OUT 2 +#define CORRECTION_HIGH 3 +#define CORRECTION_SIZE 4 #endif @@ -633,7 +634,11 @@ typedef struct config { float high_level_offset; float low_level_output_offset; float high_level_output_offset; +#ifdef TINYSA4 float lna_level_offset; + float harmonic_level_offset; + float shift_level_offset; +#endif float correction_value[CORRECTION_SIZE][CORRECTION_POINTS]; freq_t correction_frequency[CORRECTION_SIZE][CORRECTION_POINTS]; #ifdef TINYSA4 diff --git a/sa_cmd.c b/sa_cmd.c index 2e49a47..df1798a 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -294,9 +294,9 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|high|switch"; + static const char cmd_mode_list[] = "low|high|switch|lna|harmonic|shift"; #else - static const char cmd_mode_list[] = "low|high|switch|lna"; + static const char cmd_mode_list[] = "low|high|switch"; #endif if (argc == 0) { const char *p = "leveloffset %s %.1f\r\n"; @@ -307,6 +307,8 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "switch", config.switch_offset); #ifdef TINYSA4 shell_printf(p, "lna", config.lna_level_offset); + shell_printf(p, "harmonic", config.harmonic_level_offset); + shell_printf(p, "shift", config.shift_level_offset); #endif return; } @@ -321,6 +323,8 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 2: config.switch_offset = v; break; #ifdef TINYSA4 case 3: config.lna_level_offset = v; break; + case 4: config.harmonic_level_offset = v; break; + case 5: config.shift_level_offset = v; break; #endif default: goto usage; } @@ -714,6 +718,19 @@ VNA_SHELL_FUNCTION(cmd_y) shell_printf("\r\n"); #endif } +#ifdef TINYSA4 +VNA_SHELL_FUNCTION(cmd_z) +{ + if (argc != 1) { + shell_printf("usage: z 0..30000\r\n%d\r\n", SI4432_step_delay); + return; + } + if (argc == 1) { + setting.step_delay = atoi(argv[0]); + dirty = true; + } +} +#endif #if 0 // not used VNA_SHELL_FUNCTION(cmd_z) { @@ -851,7 +868,7 @@ VNA_SHELL_FUNCTION(cmd_correction) { (void)argc; #ifdef TINYSA4 - static const char cmd[] = "low|lna|high"; + static const char cmd[] = "low|lna|out|high"; static const char range[] = "0-19"; #else static const char cmd[] = "low|high"; diff --git a/sa_core.c b/sa_core.c index efe7679..60b9cd3 100644 --- a/sa_core.c +++ b/sa_core.c @@ -294,8 +294,8 @@ void reset_settings(int m) #ifdef TINYSA4 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_OUT]; + setting.correction_value = config.correction_value[CORRECTION_LOW_OUT]; level_min = SL_GENLOW_LEVEL_MIN + config.low_level_output_offset; level_max = SL_GENLOW_LEVEL_MAX + config.low_level_output_offset; level_range = level_max - level_min; @@ -1369,14 +1369,14 @@ static const struct { int16_t noise_level; } step_delay_table[]={ // RBWx10 step_delay offset_delay spur_gate (value divided by 1000) - { 8500, 100, 50, 400, -90}, - { 3000, 200, 50, 200, -95}, - { 1000, 400, 100, 100, -105}, + { 8500, 150, 50, 400, -90}, + { 3000, 150, 50, 200, -95}, + { 1000, 300, 100, 100, -105}, { 300, 400, 120, 100, -110}, - { 100, 700, 120, 100, -115}, - { 30, 900, 300, 100, -120}, - { 10, 4000, 600, 100, -122}, - { 3, 9000, 3000, 100, -125} + { 100, 600, 120, 100, -115}, + { 30, 1100, 300, 100, -120}, + { 10, 5000, 600, 100, -122}, + { 3, 10000, 3000, 100, -125} }; #endif @@ -1490,6 +1490,23 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c pureRSSI_t cv = 0; if (setting.mode == M_GENHIGH) return(0.0); +#ifdef TINYSA4 + if (setting.mode == M_LOW && ultra && f > ultra_threshold) { +#if 0 + freq_t local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; + if ( f > local_IF && f < local_IF + MIN_BELOW_LO) { // Jump at local_IF + MIN_BELOW_LO = 978 - 550 = 1527MHz + cv += ( float_TO_PURE_RSSI(1.5) * (f - local_IF) ) / MIN_BELOW_LO; // +2.5dB correction. + } + if ( f > MAX_LO_FREQ - local_IF && f < ULTRA_MAX_FREQ) { // = 4350 - 978 = 3372MHz up to 5350MHz + cv += float_TO_PURE_RSSI(1); // +1dB correction. + } +#endif + if ( f > ULTRA_MAX_FREQ) { + cv += float_TO_PURE_RSSI(9); // +9dB correction. + } + } +#endif + #ifdef TINYSA4 #if 0 // Not implemented int cf = (((f >> 28)+1)>>1) - 5; // Correction starts at 2,684,354,560Hz round to closest correction frequency @@ -2362,6 +2379,12 @@ static systime_t sweep_elapsed = 0; // Time since fi uint8_t signal_is_AM = false; static uint8_t check_for_AM = false; static int is_below = false; +#ifdef TINYSA4 +static int LO_shifted; +static int LO_mirrored; +static int LO_harmonic; +static int LO_shifting; +#endif static void calculate_static_correction(void) // Calculate the static part of the RSSI correction { @@ -2747,9 +2770,10 @@ again: // Spur redu local_IF=0; // For all high modes #ifdef TINYSA4 - int LO_shifted = false; - int LO_mirrored = false; - int LO_harmonic = false; + LO_shifted = false; + LO_mirrored = false; + LO_harmonic = false; + LO_shifting = false; #endif if (MODE_LOW(setting.mode)){ // All low mode if (!setting.auto_IF) @@ -2757,7 +2781,7 @@ again: // Spur redu else { #ifdef TINYSA4 - local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; ; + local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; #if 0 if ( S_IS_AUTO(setting.below_IF)) { // if (f < 2000000 && S_IS_AUTO(setting.spur_removal)) @@ -2816,6 +2840,9 @@ again: // Spur redu } else { +#ifdef TINYSA4 + LO_shifting = true; +#endif if (spur_second_pass) { #ifdef TINYSA4 local_IF = local_IF + DEFAULT_SPUR_OFFSET/2; // apply IF spur shift @@ -3220,8 +3247,13 @@ again: // Spur redu int my_step_delay = SI4432_step_delay; if (f < 2000000 && actual_rbw_x10 == 3) my_step_delay = my_step_delay * 2; - if (LO_shifted) // || SI4463_offset_changed) - my_step_delay = my_step_delay * 2; +// if (LO_shifted) // || SI4463_offset_changed) +// my_step_delay = my_step_delay * 2; + if (actual_rbw_x10 >= 1000 && SI4463_frequency_changed && ADF4351_frequency_changed) { + my_step_delay -= 200; // compensate for additional delay of setting SI4463 + if (my_step_delay < 0) + my_step_delay = 0; + } my_microsecond_delay(my_step_delay * ((setting.R == 0 && old_R > 5 ) ? 8 : 1)); ADF4351_frequency_changed = false; SI4463_frequency_changed = false; @@ -3267,6 +3299,11 @@ again: // Spur redu } #endif + if (LO_shifting) + pureRSSI -= float_TO_PURE_RSSI(config.shift_level_offset); + if (LO_harmonic) + pureRSSI -= float_TO_PURE_RSSI(config.harmonic_level_offset); + if (RSSI < pureRSSI) // Take max during subscanning RSSI = pureRSSI; t++; // one subscan done