From 67f15efeea1b6ca2741ba4e200f3f5e364639196 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 29 Aug 2022 16:00:07 +0200 Subject: [PATCH] Updated 200Hz RBW --- main.c | 1 + nanovna.h | 4 +- sa_cmd.c | 10 ++++ sa_core.c | 152 ++++++++++++++++++++++++++++++------------------------ si4468.c | 9 ++-- ui_sa.c | 7 +-- 6 files changed, 106 insertions(+), 77 deletions(-) diff --git a/main.c b/main.c index a368c5b..7bb1d9f 100644 --- a/main.c +++ b/main.c @@ -2115,6 +2115,7 @@ static const VNAShellCommand commands[] = { "g", cmd_g, CMD_WAIT_MUTEX }, { "n", cmd_n, CMD_WAIT_MUTEX }, { "z", cmd_z, CMD_WAIT_MUTEX }, + { "r", cmd_r, CMD_WAIT_MUTEX }, #endif #ifdef __ADF4351__ { "x", cmd_x, CMD_WAIT_MUTEX }, diff --git a/nanovna.h b/nanovna.h index dabbfac..65e1431 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -//#ifdef TINYSA_F303 +#ifdef TINYSA_F303 #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" #endif @@ -26,7 +26,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -//#endif +#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 diff --git a/sa_cmd.c b/sa_cmd.c index ee01f4f..7c036b1 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -1056,6 +1056,16 @@ VNA_SHELL_FUNCTION(cmd_g) int a = my_atoi(argv[1]); SI4463_set_gpio(p,a); } + +VNA_SHELL_FUNCTION(cmd_r) +{ + (void)argc; + int r = my_atoi(argv[0]); + set_R(r); +} + + + #endif VNA_SHELL_FUNCTION(cmd_w) diff --git a/sa_core.c b/sa_core.c index 2be549a..f104410 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3180,6 +3180,74 @@ int avoid_spur(freq_t f) // find if this frequency should be a return F_NOSPUR; } + +static uint16_t max_index[MAX_MAX]; +static uint16_t cur_max = 0; +float temppeakLevel = -150; +int16_t downslope = true; +int peak_finding_index; +float peak_finding_level; + + +void add_to_peak_finding(float *trace_data, int i) { + // START_PROFILE + if (i == 0 || getFrequency(i) < actual_rbw_x10 * 200) { // Prepare peak finding + cur_max = 0; // Always at least one maximum + temppeakIndex = 0; + temppeakLevel = trace_data[0]; + max_index[0] = 0; + downslope = true; + peak_finding_index = 0; + peak_finding_level = temppeakLevel; + } + if (cur_max == 0 && peak_finding_level < trace_data[i]) { + peak_finding_index = i; + peak_finding_level = trace_data[i]; + } + if (downslope) { // If in down slope peak finding + if (temppeakLevel > trace_data[i]) { // Follow down + temppeakIndex = i; // Latest minimum + temppeakLevel = trace_data[i]; + } else if (temppeakLevel + setting.noise < trace_data[i] ) { // Local minimum found + temppeakIndex = i; // This is now the latest maximum + temppeakLevel = trace_data[i]; + downslope = false; + } + } else { // up slope peak finding + if (temppeakLevel < trace_data[i]) { // Follow up + temppeakIndex = i; + temppeakLevel = trace_data[i]; + } else if (trace_data[i] < temppeakLevel - setting.noise) { // Local max found + + // maintain sorted peak table + int j = 0; // Insert max in sorted table + while (j= temppeakLevel) // Find where to insert + j++; + if (j < MAX_MAX) { // Larger then one of the previous found + int k = MAX_MAX-1; + while (k > j) { // Shift to make room for max + max_index[k] = max_index[k-1]; + // maxlevel_index[k] = maxlevel_index[k-1]; // Only for debugging + k--; + } + max_index[j] = temppeakIndex; + // maxlevel_index[j] = trace_data[temppeakIndex]; // Only for debugging + if (cur_max < MAX_MAX) { + cur_max++; + } + //STOP_PROFILE + } + // Insert done + temppeakIndex = i; // Latest minimum + temppeakLevel = trace_data[i]; + + downslope = true; + } + } // end of peak finding +} + + + static int modulation_counter = 0; static int cycle_counter = 0; @@ -4638,9 +4706,6 @@ again: // Spur redu } -static uint16_t max_index[MAX_MAX]; -static uint16_t cur_max = 0; - static uint8_t low_count = 0; static uint8_t sweep_counter = 0; // Only used for HW refresh @@ -4648,8 +4713,8 @@ static uint8_t sweep_counter = 0; // Only used for HW refresh static bool sweep(bool break_on_operation) { float RSSI; - float local_peakLevel = -150.0; - int local_peakIndex = 0; +// float local_peakLevel = -150.0; +// int local_peakIndex = 0; #ifdef __SI4432__ freq_t agc_peak_freq = 0; float agc_peak_rssi = -150; @@ -4667,7 +4732,7 @@ static bool sweep(bool break_on_operation) #ifdef TINYSA4 palClearLine(LINE_LED); #endif -// float temp_min_level = 100; + float temp_min_level = 100; // spur_old_stepdelay = 0; // shell_printf("\r\n"); @@ -4725,9 +4790,6 @@ static bool sweep(bool break_on_operation) sweep_again: // stay in sweep loop when output mode and modulation on. - temppeakLevel = -150; - float temp_min_level = 100; // Initialize the peak search algorithm - int16_t downslope = true; #ifdef __ULTRA__ if (config.ultra_start == ULTRA_AUTO) { if (setting.mode == M_LOW){ @@ -5139,63 +5201,11 @@ static volatile int dummy; // --------------------------- find peak and add to peak table if found ------------------------ - // START_PROFILE - if (i == 0 || getFrequency(i) < actual_rbw_x10 * 200) { // Prepare peak finding - cur_max = 0; // Always at least one maximum - temppeakIndex = 0; - temppeakLevel = actual_t[0]; - max_index[0] = 0; - downslope = true; - local_peakIndex = 0; - local_peakLevel = temppeakLevel; + add_to_peak_finding(actual_t, i); + } - if (cur_max == 0 && local_peakLevel < actual_t[i]) { - local_peakIndex = i; - local_peakLevel = actual_t[i]; } - if (downslope) { // If in down slope peak finding - if (temppeakLevel > actual_t[i]) { // Follow down - temppeakIndex = i; // Latest minimum - temppeakLevel = actual_t[i]; - } else if (temppeakLevel + setting.noise < actual_t[i] ) { // Local minimum found - temppeakIndex = i; // This is now the latest maximum - temppeakLevel = actual_t[i]; - downslope = false; - } - } else { // up slope peak finding - if (temppeakLevel < actual_t[i]) { // Follow up - temppeakIndex = i; - temppeakLevel = actual_t[i]; - } else if (actual_t[i] < temppeakLevel - setting.noise) { // Local max found - - // maintain sorted peak table - int j = 0; // Insert max in sorted table - while (j= temppeakLevel) // Find where to insert - j++; - if (j < MAX_MAX) { // Larger then one of the previous found - int k = MAX_MAX-1; - while (k > j) { // Shift to make room for max - max_index[k] = max_index[k-1]; - // maxlevel_index[k] = maxlevel_index[k-1]; // Only for debugging - k--; - } - max_index[j] = temppeakIndex; - // maxlevel_index[j] = actual_t[temppeakIndex]; // Only for debugging - if (cur_max < MAX_MAX) { - cur_max++; - } - //STOP_PROFILE - } - // Insert done - temppeakIndex = i; // Latest minimum - temppeakLevel = actual_t[i]; - - downslope = true; - } - } // end of peak finding - } } - } // ---------------------- end of postprocessing ----------------------------- @@ -5460,8 +5470,14 @@ static volatile int dummy; // --------------------- set tracking markers from maximum table ----------------- + for (int t=0; t < TRACES_MAX; t++) { + if (t != 0) { + for (int i=0;i menu_back }; #endif