From ae87eec9c68f3e82d2ba3057b2c10e99d280a53b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 2 Jun 2022 09:21:33 +0200 Subject: [PATCH] Add out_switch, disable mode restart --- main.c | 7 +++++-- nanovna.h | 1 + sa_cmd.c | 22 ++++++++++++---------- sa_core.c | 8 ++++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/main.c b/main.c index 48df1dc..4c4ec03 100644 --- a/main.c +++ b/main.c @@ -1030,6 +1030,9 @@ config_t config = { .high_out_adf4350 = true, .ext_zero_level = 174, .receive_switch_offset = 0.0, +#ifdef TINYSA4 + .out_switch_offset = 0.0, +#endif #ifdef __NOISE_FIGURE__ .noise_figure = 5.0, #endif @@ -2598,7 +2601,7 @@ int main(void) int i = 5; while (i--) *t++ = *f++; - +#if 0 // Set mode not working reliably set_mode(b.mode); switch (b.mode) { case M_LOW: @@ -2613,7 +2616,7 @@ int main(void) menu_push_submenu(menu_highoutputmode); break; } - +#endif if (b.frequency0 != 0 || b.frequency1 != 0) { if (b.mode <= M_HIGH){ set_sweep_frequency(ST_START, b.frequency0); diff --git a/nanovna.h b/nanovna.h index eba796a..f1f1318 100644 --- a/nanovna.h +++ b/nanovna.h @@ -713,6 +713,7 @@ typedef struct config { float high_level_output_offset; float receive_switch_offset; #ifdef TINYSA4 + float out_switch_offset; float lna_level_offset; float harmonic_level_offset; float shift1_level_offset; diff --git a/sa_cmd.c b/sa_cmd.c index 951c917..2849a12 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -340,7 +340,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|high|switch|receive_switch|lna|harmonic|shift1|shift2|drive1|drive2|drive3"; + static const char cmd_mode_list[] = "low|high|switch|receive_switch|out_switch|lna|harmonic|shift1|shift2|drive1|drive2|drive3"; #else static const char cmd_mode_list[] = "low|high|switch|receive_switch"; #endif @@ -353,6 +353,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "switch", config.switch_offset); shell_printf(p, "receive_switch",config.receive_switch_offset); #ifdef TINYSA4 + shell_printf(p, "out_switch", config.out_switch_offset); shell_printf(p, "lna", config.lna_level_offset); shell_printf(p, "harmonic", config.harmonic_level_offset); shell_printf(p, "shift1", config.shift1_level_offset); @@ -377,13 +378,14 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 2: config.switch_offset = v; break; case 3: config.receive_switch_offset = v; break; #ifdef TINYSA4 - 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.drive1_level_offset = v; break; - case 9: config.drive2_level_offset = v; break; - case 10: config.drive3_level_offset = v; break; + case 4: config.out_switch_offset = v; break; + case 5: config.lna_level_offset = v; break; + case 6: config.harmonic_level_offset = v; break; + case 7: config.shift1_level_offset = v; break; + case 8: config.shift2_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; #endif default: goto usage; } @@ -1137,7 +1139,7 @@ VNA_SHELL_FUNCTION(cmd_q) static const char cmd[] = "s|d|a"; if (argc < 1) { usage: - usage_printf("q s|d 0..18|a 0..63 %s\r\n", cmd); + usage_printf("q [s 0..1|d 0..18|a 0..63] %s\r\n", cmd); test_output=false; return; } @@ -1153,7 +1155,7 @@ VNA_SHELL_FUNCTION(cmd_q) argc--; switch (m) { case -1: goto usage; - case 0: test_output_switch = true; break; + case 0: test_output_switch = argv[i++][0] - '0'; argc--; break; case 1: test_output_drive = atoi(argv[i++]); argc--; break; case 2: test_output_attenuate = atoi(argv[i++]); argc--; break; } diff --git a/sa_core.c b/sa_core.c index 4c2b442..5a88511 100644 --- a/sa_core.c +++ b/sa_core.c @@ -103,7 +103,7 @@ static freq_t real_old_freq[4] = { 0, 0, 0, 0}; #endif #ifdef TINYSA4 -const float si_drive_dBm [] = {-44.30, -29.98, -19.41, -16.80, -13.79, -11.49, -9.67, -8.18, -6.98, -5.87, -4.91, -4.16, -3.31, -2.62 , -1.99, -1.41, -0.95, -0.47, 0}; +const float si_drive_dBm [] = {-44.1, -30, -21.6, -17, -14, -11.7, -9.9, -8.4, -7.1, -6, -5, -4.2, -3.4, -2.7 , 2.1, -1.5, -1, -0.47, 0}; const float adf_drive_dBm[] = {-15,-12,-9,-6}; const uint8_t drive_register[] = {0, 1, 2, 3, 4, 5, 6, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; float *drive_dBm = (float *) adf_drive_dBm; @@ -117,12 +117,12 @@ int actual_drive = -1; #endif #ifdef TINYSA4 -#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 25.0) +#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 25.0 + config.out_switch_offset) #define RECEIVE_SWITCH_ATTENUATION (29 + config.receive_switch_offset) //#define POWER_OFFSET -18 // Max level with all enabled //#define POWER_RANGE 70 #define MAX_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 3 : 18) -#define MIN_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 0: 1) +#define MIN_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 0: 0) //#define SL_GENHIGH_LEVEL_MIN -15 //#define SL_GENHIGH_LEVEL_RANGE 9 @@ -3149,7 +3149,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / float ls=setting.level_sweep; // calculate and set the output level if (ls > 0) ls += 0.5; - else + else if (ls < 0) ls -= 0.5; float a = ((int)((setting.level + ((float)i / sweep_points) * ls)*2.0)) / 2.0 /* + get_level_offset() */ ; correct_RSSI_freq = get_frequency_correction(f); // No direct in output