From 47a4b2fadc8468e9b5e350327cedec3a6c9b41e1 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 13 Apr 2021 14:40:13 +0200 Subject: [PATCH] level testing command added --- main.c | 3 +- nanovna.h | 4 +++ sa_cmd.c | 31 +++++++++++++++++ sa_core.c | 102 +++++++++++++++++++++++++++++++++--------------------- 4 files changed, 99 insertions(+), 41 deletions(-) diff --git a/main.c b/main.c index 86bec44..0484341 100644 --- a/main.c +++ b/main.c @@ -2507,7 +2507,7 @@ static const VNAShellCommand commands[] = { "e", cmd_e, CMD_WAIT_MUTEX }, { "s", cmd_s, CMD_WAIT_MUTEX }, { "m", cmd_m, CMD_WAIT_MUTEX }, - { "p", cmd_p, CMD_WAIT_MUTEX }, + { "p", cmd_p, CMD_WAIT_MUTEX }, { "w", cmd_w, CMD_WAIT_MUTEX }, { "o", cmd_o, CMD_WAIT_MUTEX }, { "d", cmd_d, CMD_WAIT_MUTEX }, @@ -2516,6 +2516,7 @@ static const VNAShellCommand commands[] = #endif #ifdef TINYSA4 { "g", cmd_g, CMD_WAIT_MUTEX }, + { "q", cmd_q, CMD_WAIT_MUTEX }, { "z", cmd_z, CMD_WAIT_MUTEX }, #endif #ifdef __ADF4351__ diff --git a/nanovna.h b/nanovna.h index f05b7a3..a5a5dfc 100644 --- a/nanovna.h +++ b/nanovna.h @@ -294,6 +294,10 @@ extern const char * const unit_string[]; extern freq_t ultra_threshold; extern bool ultra; extern float *drive_dBm; +extern int test_output; +extern int test_output_switch; +extern int test_output_drive; +extern int test_output_attenuate; #else extern const int8_t drive_dBm []; #endif diff --git a/sa_cmd.c b/sa_cmd.c index df1798a..2ee9cd3 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -886,6 +886,7 @@ VNA_SHELL_FUNCTION(cmd_correction) for (int i=0; i 0) - ls += 0.5; - else - ls -= 0.5; - float a = ((int)((setting.level + ((float)i / sweep_points) * ls)*2.0)) / 2.0; - a += PURE_TO_float(get_frequency_correction(f)); - if (a != old_a) { - int very_low_flag = false; - old_a = a; - a = a - level_max; // convert to all settings maximum power output equals a = zero - if (a < -SWITCH_ATTENUATION) { - a = a + SWITCH_ATTENUATION; +#ifdef TINYSA4 + if (test_output) { + enable_rx_output(!test_output_switch); + SI4463_set_output_level(test_output_drive); + PE4302_Write_Byte(test_output_attenuate); + } else +#endif + { + float ls=setting.level_sweep; // calculate and set the output level + if (ls > 0) + ls += 0.5; + else + ls -= 0.5; + float a = ((int)((setting.level + ((float)i / sweep_points) * ls)*2.0)) / 2.0; + correct_RSSI_freq = get_frequency_correction(f); + a += PURE_TO_float(correct_RSSI_freq); + if (a != old_a) { + int very_low_flag = false; + old_a = a; + a = a - level_max; // convert to all settings maximum power output equals a = zero + if (a < -SWITCH_ATTENUATION) { + a = a + SWITCH_ATTENUATION; #ifdef TINYSA3 - SI4432_Sel = SI4432_RX ; - set_switch_receive(); + SI4432_Sel = SI4432_RX ; + set_switch_receive(); #else - enable_rx_output(false); - very_low_flag = true; + enable_rx_output(false); + very_low_flag = true; #endif - } else { + } else { #ifdef TINYSA3 - SI4432_Sel = SI4432_RX ; - set_switch_transmit(); + SI4432_Sel = SI4432_RX ; + set_switch_transmit(); #else - enable_rx_output(true); + enable_rx_output(true); #endif - } + } #ifdef TINYSA4 #define LOWEST_LEVEL (very_low_flag ? 0 : MIN_DRIVE) #else #define LOWEST_LEVEL MIN_DRIVE #endif - int d = MAX_DRIVE; // Reduce level till it fits in attenuator range - while (a - BELOW_MAX_DRIVE(d) < - 31 && d > LOWEST_LEVEL) { - d--; - } - a -= BELOW_MAX_DRIVE(d); + int d = MAX_DRIVE; // Reduce level till it fits in attenuator range + while (a - BELOW_MAX_DRIVE(d) < - 31 && d > LOWEST_LEVEL) { + d--; + } + a -= BELOW_MAX_DRIVE(d); #ifdef __SI4432__ - SI4432_Sel = SI4432_RX ; - SI4432_Drive(d); + SI4432_Sel = SI4432_RX ; + SI4432_Drive(d); #endif #ifdef __SI4463__ - SI4463_set_output_level(d); + SI4463_set_output_level(d); #endif - if (a > 0) - a = 0; - if (a < -31.5) - a = -31.5; - a = -a; + if (a > 0) + a = 0; + if (a < -31.5) + a = -31.5; + a = -a; #ifdef __PE4302__ - setting.attenuate_x2 = (int)(a * 2); - PE4302_Write_Byte(setting.attenuate_x2); + setting.attenuate_x2 = (int)(a * 2); + PE4302_Write_Byte(setting.attenuate_x2); #endif + } } } else if (setting.mode == M_GENHIGH) { @@ -2660,6 +2674,14 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / if (setting.frequency_step != 0) correct_RSSI_freq = get_frequency_correction(f); } +//#define DEBUG_CORRECTION +#ifdef DEBUG_CORRECTION + if (SDU1.config->usbp->state == USB_ACTIVE) { + shell_printf ("%d:%Q %d\r\n", i, f, correct_RSSI_freq); + osalThreadSleepMilliseconds(2); +} +#endif + // ----------------------------- Initiate modulation ---------------------------