From 08f511183daea836e29f5a55b69f3aaab8de6c7f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 5 Sep 2020 11:56:59 +0200 Subject: [PATCH 1/7] Read also LNA when debugging AGC --- sa_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sa_core.c b/sa_core.c index b73d491..7b7ce91 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1890,7 +1890,7 @@ sweep_again: // stay in sweep loop when output mo RSSI = RSSI - stored_t[i] ; } #ifdef __DEBUG_AGC__ // For debugging the AGC control - stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in the stored trace + stored_t[i] = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; // Display the AGC value in the stored trace #endif #ifdef __DEBUG_SPUR__ // For debugging the spur avoidance control stored_t[i] = (avoid_spur(frequencies[i]) ? -60.0 : - 90.0); // Display when to do spur shift in the stored trace From 28d1f9ecad9523cdea7bd7ae999f25b1b13ffc46 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 6 Sep 2020 12:49:48 +0200 Subject: [PATCH 2/7] High mode overload protection --- .settings/language.settings.xml | 2 +- sa_core.c | 39 +++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index fe6ec0c..4408aa2 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + diff --git a/sa_core.c b/sa_core.c index 7b7ce91..3a2fd8c 100644 --- a/sa_core.c +++ b/sa_core.c @@ -624,16 +624,16 @@ void toggle_AGC(void) void auto_set_AGC_LNA(int auto_set) // Adapt the AGC setting if needed { #ifdef __SI4432__ - static unsigned char old_v; + static unsigned char old_v[2]; unsigned char v; if (auto_set) v = 0x60; // Enable AGC and disable LNA else - v = 0x40; // Disable AGC and enable LNA - if (old_v != v) { - SI4432_Sel = SI4432_RX ; + v = 0x50; // Disable AGC and enable LNA + if (old_v[MODE_SELECT(setting.mode)] != v) { + SI4432_Sel = MODE_SELECT(setting.mode); SI4432_Write_Byte(SI4432_AGC_OVERRIDE, v); - old_v = v; + old_v[MODE_SELECT(setting.mode)] = v; } #endif } @@ -1676,7 +1676,7 @@ modulation_again: set_freq (2, IF_2 + lf); // Scanning LO up to IF2 set_freq (3, IF_2 - 433800000); // Down from IF2 to fixed second IF in Ultra SA mode - set_freq (SI4432_LO, 433800000); // Second IF fixe in Ultra SA mode + set_freq (SI4432_LO, 433800000); // Second IF fixed in Ultra SA mode #else #ifdef __SI4432__ if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) // if in low input mode and below IF @@ -1816,6 +1816,7 @@ static bool sweep(bool break_on_operation) { float RSSI; int16_t downslope; + uint32_t peak_freq = 0; // if (setting.mode== -1) // return; // START_PROFILE; @@ -1864,6 +1865,19 @@ sweep_again: // stay in sweep loop when output mo return false; } + // ----------------------- in loop AGC --------------------------------- + + if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { + if (RSSI > -55) { + peak_freq = frequencies[i]; + } + if (peak_freq != 0 && frequencies[i] - peak_freq < 1700000) + auto_set_AGC_LNA(false); + else + auto_set_AGC_LNA(TRUE); + } + + // Delay between points if needed, (all delays can apply in SI4432 fill) if (setting.measure_sweep_time_us == 0){ // If not already in buffer if (setting.additional_step_delay_us && (MODE_INPUT(setting.mode) || setting.modulation == MO_NONE)) { // No delay when modulation is active @@ -2090,12 +2104,15 @@ sweep_again: // stay in sweep loop when output mo // ---------------------------------- auto AGC ---------------------------------- - if (!in_selftest && MODE_INPUT(setting.mode) && S_IS_AUTO(setting.agc) && UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode + + if (!in_selftest && MODE_INPUT(setting.mode) && S_IS_AUTO(setting.agc)) { float actual_max_level = actual_t[max_index[0]] - get_attenuation(); - if (actual_max_level > - 45) - auto_set_AGC_LNA(false); - else - auto_set_AGC_LNA(TRUE); + if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode + if (actual_max_level > - 45) + auto_set_AGC_LNA(false); + else + auto_set_AGC_LNA(TRUE); + } } From e5d27aa3fcca8cc08cefa317a9dfd5ff7927c573 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 6 Sep 2020 18:32:17 +0200 Subject: [PATCH 3/7] Computed AGC in high mode after peak and reduced overload warning levels --- plot.c | 4 ++-- sa_core.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/plot.c b/plot.c index 89b0c69..8982e23 100644 --- a/plot.c +++ b/plot.c @@ -2098,8 +2098,8 @@ static void cell_draw_marker_info(int x0, int y0) ili9341_set_background(DEFAULT_BG_COLOR); uint16_t color; if ((!setting.subtract_stored) && // Disabled when normalized - ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -1) || - (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -10) )) + ((setting.mode == M_LOW && temppeakLevel - get_attenuation() + setting.offset > -10) || + (setting.mode == M_HIGH && temppeakLevel - get_attenuation()+ setting.offset > -29) )) color = BRIGHT_COLOR_RED; else color = marker_color(markers[i].mtype); diff --git a/sa_core.c b/sa_core.c index 3a2fd8c..b86bd5b 100644 --- a/sa_core.c +++ b/sa_core.c @@ -621,7 +621,7 @@ void toggle_AGC(void) dirty = true; } -void auto_set_AGC_LNA(int auto_set) // Adapt the AGC setting if needed +void auto_set_AGC_LNA(int auto_set, int agc) // Adapt the AGC setting if needed { #ifdef __SI4432__ static unsigned char old_v[2]; @@ -629,7 +629,7 @@ void auto_set_AGC_LNA(int auto_set) if (auto_set) v = 0x60; // Enable AGC and disable LNA else - v = 0x50; // Disable AGC and enable LNA + v = 0x40+agc; // Disable AGC and enable LNA if (old_v[MODE_SELECT(setting.mode)] != v) { SI4432_Sel = MODE_SELECT(setting.mode); SI4432_Write_Byte(SI4432_AGC_OVERRIDE, v); @@ -1326,7 +1326,7 @@ search_maximum(int m, int center, int span) //static int spur_old_stepdelay = 0; static const unsigned int spur_IF = 433800000; // The IF frequency for which the spur table is value -static const unsigned int spur_alternate_IF = 434000000; // if the frequency is found in the spur table use this IF frequency +static const unsigned int spur_alternate_IF = 433900000; // if the frequency is found in the spur table use this IF frequency static const int spur_table[] = // Frequencies to avoid { // 580000, // 433.8 MHz table @@ -1535,10 +1535,10 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) } } if (setting.mode == M_LOW && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { // If in low input mode with auto AGC and log unit - if (f < 500000) - auto_set_AGC_LNA(false); + if (f < 1500000) + auto_set_AGC_LNA(false, f*9/1500000); else - auto_set_AGC_LNA(true); + auto_set_AGC_LNA(true, 0); } modulation_again: // ----------------------------------------------------- modulation for output modes --------------------------------------- @@ -1816,7 +1816,9 @@ static bool sweep(bool break_on_operation) { float RSSI; int16_t downslope; - uint32_t peak_freq = 0; + uint32_t agc_peak_freq = 0; + float agc_peak_rssi = -150; + float agc_prev_rssi = -150; // if (setting.mode== -1) // return; // START_PROFILE; @@ -1868,13 +1870,20 @@ sweep_again: // stay in sweep loop when output mo // ----------------------- in loop AGC --------------------------------- if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { - if (RSSI > -55) { - peak_freq = frequencies[i]; +#define AGC_RSSI_THRESHOLD -55 + if (RSSI > AGC_RSSI_THRESHOLD && RSSI > agc_prev_rssi) { + agc_peak_freq = frequencies[i]; + agc_peak_rssi = agc_prev_rssi = RSSI; + } + if (RSSI < AGC_RSSI_THRESHOLD) + agc_prev_rssi = -150; + uint32_t delta_freq = frequencies[i] - agc_peak_freq; + if (agc_peak_freq != 0 && delta_freq < 2000000) { + int max_gain = (-25 - agc_peak_rssi ) / 4; + auto_set_AGC_LNA(false, 16 + delta_freq * max_gain / 2000000 ); // enable LNA and stepwise gain } - if (peak_freq != 0 && frequencies[i] - peak_freq < 1700000) - auto_set_AGC_LNA(false); else - auto_set_AGC_LNA(TRUE); + auto_set_AGC_LNA(TRUE, 0); } @@ -1903,6 +1912,7 @@ sweep_again: // stay in sweep loop when output mo if (setting.subtract_stored) { RSSI = RSSI - stored_t[i] ; } +// #define __DEBUG_AGC__ #ifdef __DEBUG_AGC__ // For debugging the AGC control stored_t[i] = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; // Display the AGC value in the stored trace #endif @@ -2109,9 +2119,9 @@ sweep_again: // stay in sweep loop when output mo float actual_max_level = actual_t[max_index[0]] - get_attenuation(); if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode if (actual_max_level > - 45) - auto_set_AGC_LNA(false); + auto_set_AGC_LNA(false, 0); // Strong signal, no AGC and no LNA else - auto_set_AGC_LNA(TRUE); + auto_set_AGC_LNA(TRUE, 0); } } From 3e428150de5bc3da84687ce6fd4090e775a92a7b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 7 Sep 2020 08:31:37 +0200 Subject: [PATCH 4/7] Mirror masking added --- nanovna.h | 4 ++- sa_core.c | 74 ++++++++++++++++++++++++++++++++++++------------------- ui_sa.c | 23 +++++++++++------ 3 files changed, 67 insertions(+), 34 deletions(-) diff --git a/nanovna.h b/nanovna.h index e381fb1..b9e2e13 100644 --- a/nanovna.h +++ b/nanovna.h @@ -202,6 +202,7 @@ void set_sweep_time_us(uint32_t); #ifdef __SPUR__ //extern int setting.spur; void set_spur(int v); +void toggle_mirror_masking(void); #endif void set_average(int); int GetAverage(void); @@ -652,7 +653,8 @@ typedef struct setting int freq_mode; int measurement; int refer; - int spur; + int spur_removal; + int mirror_masking; trace_t _trace[TRACES_MAX]; marker_t _markers[MARKERS_MAX]; int8_t _active_marker; diff --git a/sa_core.c b/sa_core.c index b86bd5b..17ca04a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -111,7 +111,8 @@ void reset_settings(int m) // setting.refer = -1; // do not reset reffer when switching modes setting.mute = true; #ifdef __SPUR__ - setting.spur = 0; + setting.spur_removal = 0; + setting.mirror_masking = 0; #endif switch(m) { case M_LOW: @@ -190,10 +191,10 @@ uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in #endif if (FREQ_IS_CW()) { bare_sweep_time = MINIMUM_SWEEP_TIME; // minimum sweep time in fast CW mode - if (setting.repeat != 1 || setting.sweep_time_us >= 100*ONE_MS_TIME || setting.spur != 0) // if no fast CW sweep possible + if (setting.repeat != 1 || setting.sweep_time_us >= 100*ONE_MS_TIME || setting.spur_removal != 0) // if no fast CW sweep possible bare_sweep_time = 15000; // minimum CW sweep time when not in fast CW mode } - t = vbwSteps * (setting.spur ? 2 : 1) * bare_sweep_time ; // factor in vbwSteps and spur impact + t = vbwSteps * (setting.spur_removal ? 2 : 1) * bare_sweep_time ; // factor in vbwSteps and spur impact t += (setting.repeat - 1)* REPEAT_TIME * (sweep_points); // Add time required for repeats } return t; @@ -280,6 +281,12 @@ void toggle_tracking_output(void) dirty = true; } +void toggle_mirror_masking(void) +{ + setting.mirror_masking = !setting.mirror_masking; + dirty = true; +} + void toggle_mute(void) { setting.mute = !setting.mute; @@ -534,8 +541,8 @@ void set_spur(int v) { if (setting.mode!=M_LOW) return; - setting.spur = v; -// if (setting.spur && actual_rbw > 360) // moved to update_rbw + setting.spur_removal = v; +// if (setting.spur_removal && actual_rbw > 360) // moved to update_rbw // set_RBW(300); dirty = true; } @@ -1220,7 +1227,7 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# if (actual_rbw_x10 > 6000) actual_rbw_x10 = 6000; - if (setting.spur && actual_rbw_x10 > 3000) + if (setting.spur_removal && actual_rbw_x10 > 3000) actual_rbw_x10 = 2500; // if spur suppression reduce max rbw to fit within BPF #ifdef __SI4432__ @@ -1444,7 +1451,7 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) scandirty = true; // This is the first pass with new settings dirty = false; sweep_elapsed = chVTGetSystemTimeX(); // for measuring accumulated time - if (setting.spur == -1) setting.spur = 1; // ensure spur processing starts in right phase + if (setting.spur_removal == -1) setting.spur_removal = 1; // ensure spur processing starts in right phase // Set for actual time pre calculated value (update after sweep) setting.actual_sweep_time_us = calc_min_sweep_time_us(); // Change actual sweep time as user input if it greater minimum @@ -1602,7 +1609,7 @@ modulation_again: local_IF = 0; else { if (setting.auto_IF) - local_IF = setting.spur ? 433900000 : 433800000; + local_IF = setting.spur_removal ? 433900000 : 433800000; else local_IF = setting.frequency_IF; } @@ -1614,17 +1621,17 @@ modulation_again: if (setting.mode == M_LOW && !in_selftest && avoid_spur(f)) { // check is alternate IF is needed to avoid spur. local_IF = spur_alternate_IF; #ifdef __SPUR__ - } else if (setting.mode== M_LOW && setting.spur){ // If in low input mode and spur reduction is on + } else if (setting.mode== M_LOW && setting.spur_removal){ // If in low input mode and spur reduction is on if (S_IS_AUTO(setting.below_IF) && lf < 150000000) // if below 150MHz and auto_below_IF { // else low/above IF - if (setting.spur == 1) + if (setting.spur_removal == 1) setting.below_IF = S_AUTO_ON; // use below IF in first pass else setting.below_IF = S_AUTO_OFF; // and above IF in second pass } else { int32_t spur_offset = actual_rbw_x10 * 100; // Can not use below IF so calculate IF shift that hopefully will kill the spur. - if (setting.spur == -1) // If second spur pass + if (setting.spur_removal == -1) // If second spur pass spur_offset = - spur_offset; // IF shift in the other direction local_IF = local_IF + spur_offset; // apply IF spur shift } @@ -1640,11 +1647,11 @@ modulation_again: #endif #ifdef __ULTRA__ } else if (setting.mode == M_ULTRA) { // No above/below IF mode in Ultra - local_IF = setting.frequency_IF + (int)(actual_rbw < 350.0 ? setting.spur*300000 : 0 ); + local_IF = setting.frequency_IF + (int)(actual_rbw < 350.0 ? setting.spur_removal*300000 : 0 ); #ifdef __SI4432__ set_freq (SI4432_RX , local_IF); #endif - // local_IF = setting.frequency_IF + (int)(actual_rbw < 300.0?setting.spur * 1000 * actual_rbw:0); + // local_IF = setting.frequency_IF + (int)(actual_rbw < 300.0?setting.spur_removal * 1000 * actual_rbw:0); #endif } else // This must be high mode local_IF= 0; @@ -1653,7 +1660,7 @@ modulation_again: // if (lf > 3406000000 ) // setFreq (1, local_IF/5 + lf/5); // else - if (setting.spur != 1) { // Left of tables + if (setting.spur_removal != 1) { // Left of tables if (lf > 3250000000 ) set_freq (SI4432_LO , lf/5 - local_IF/5); if (lf > 1250000000 ) @@ -1714,7 +1721,7 @@ modulation_again: #ifdef __SI4432__ #ifdef __FAST_SWEEP__ - if (i == 0 && setting.frequency_step == 0 && setting.trigger == T_AUTO && setting.spur == 0 && SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { + if (i == 0 && setting.frequency_step == 0 && setting.trigger == T_AUTO && setting.spur_removal == 0 && SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { // if ultra fast scanning is needed prefill the SI4432 RSSI read buffer SI4432_Fill(MODE_SELECT(setting.mode), 0); } @@ -1768,7 +1775,7 @@ modulation_again: }while(1); #ifdef __FAST_SWEEP__ #ifdef __SI4432__ - if (setting.spur == 0 && SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { + if (setting.spur_removal == 0 && SI4432_step_delay == 0 && setting.repeat == 1 && setting.sweep_time_us < 100*ONE_MS_TIME) { SI4432_Fill(MODE_SELECT(setting.mode), 1); // fast mode possible to pre-fill RSSI buffer } #endif @@ -1785,13 +1792,13 @@ modulation_again: } #ifdef __SPUR__ static pureRSSI_t spur_RSSI = -1; // Initialization only to avoid warning. - if (setting.spur == 1) { // If first spur pass + if (setting.spur_removal == 1) { // If first spur pass spur_RSSI = pureRSSI; // remember measure RSSI - setting.spur = -1; + setting.spur_removal = -1; goto again; // Skip all other processing - } else if (setting.spur == -1) { // If second spur pass + } else if (setting.spur_removal == -1) { // If second spur pass pureRSSI = ( pureRSSI < spur_RSSI ? pureRSSI : spur_RSSI); // Take minimum of two - setting.spur = 1; // and prepare for next call of perform. + setting.spur_removal = 1; // and prepare for next call of perform. } #endif @@ -2069,6 +2076,21 @@ sweep_again: // stay in sweep loop when output mo if (MODE_OUTPUT(setting.mode) ) // Sweep time is calculated, we can sweep again in output mode goto again; // Keep repeating sweep loop till user aborts by input +#define __MIRROR_MASKING__ +#ifdef __MIRROR_MASKING__ + if (setting.mode == M_HIGH && setting.mirror_masking) { + int mirror_offset = 2 * 937000 / setting.frequency_step; + if (mirror_offset > 3) { + for (int i = 1; i < sweep_points - mirror_offset; i++) { + if (actual_t[i] > -80 && actual_t[i+mirror_offset] < actual_t[i] - 25) { + actual_t[i+mirror_offset] = actual_t[i+mirror_offset-1]; + actual_t[i+mirror_offset+1] = actual_t[i+mirror_offset-1]; + } + } + } + } + +#endif // -------------------------- auto attenuate ---------------------------------- #define AUTO_TARGET_LEVEL -25 @@ -2607,7 +2629,7 @@ void draw_cal_status(void) } // Spur #ifdef __SPUR__ - if (setting.spur) { + if (setting.spur_removal) { ili9341_set_foreground(BRIGHT_COLOR_GREEN); y += YSTEP + YSTEP/2 ; ili9341_drawstring("Spur:", x, y); @@ -3084,7 +3106,7 @@ common_silent: setting.step_delay_mode = SD_PRECISE; // set_step_delay(1); // Precise scanning speed #ifdef __SPUR__ - setting.spur = 1; + setting.spur_removal = 1; #endif common: @@ -3101,7 +3123,7 @@ common_silent: set_refer_output(0); // set_step_delay(1); // Do not set !!!!! #ifdef __SPUR__ - setting.spur = 1; + setting.spur_removal = 1; #endif goto common; case TPH_30MHZ: @@ -3270,7 +3292,7 @@ void self_test(int test) j = setting.test_argument; // do_again: test_prepare(i); - setting.spur = 0; + setting.spur_removal = 0; #if 1 // Disable for offset baseline scanning setting.step_delay_mode = SD_NORMAL; setting.repeat = 1; @@ -3308,7 +3330,7 @@ void self_test(int test) #if 1 // Enable for step delay tuning while (setting.step_delay > 10 && test_value != 0 && test_value > saved_peakLevel - 0.5) { test_prepare(i); - setting.spur = 0; + setting.spur_removal = 0; setting.step_delay_mode = SD_NORMAL; setting.step_delay = setting.step_delay * 4 / 5; if (setting.rbw_x10 < 1000) @@ -3335,7 +3357,7 @@ void self_test(int test) test_prepare(i); setting.step_delay_mode = SD_FAST; setting.offset_delay /= 2; - setting.spur = 0; + setting.spur_removal = 0; if (setting.rbw_x10 < 1000) set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 5000)); // 50 times RBW else diff --git a/ui_sa.c b/ui_sa.c index 23068ec..1e6bc15 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -706,14 +706,23 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) (void)data; (void)item; if (b){ - b->icon = setting.spur == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + if (setting.mode == M_LOW) { + b->param_1.text = "SPUR\nREMOVAL"; + b->icon = setting.spur_removal == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + } else { + b->param_1.text = "MIRROR\nMASKING"; + b->icon = setting.mirror_masking == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + } return; } - if (setting.spur) - set_spur(0); - else - set_spur(1); // must be 0 or 1 !!!! -// menu_move_back(); + if (setting.mode == M_LOW) { + if (setting.spur_removal) + set_spur(0); + else + set_spur(1); // must be 0 or 1 !!!! + } else + toggle_mirror_masking(); + // menu_move_back(); ui_mode_normal(); } #endif @@ -1664,7 +1673,7 @@ static const menuitem_t menu_stimulus[] = { { MT_KEYPAD, KM_CW, "ZERO SPAN", NULL}, { MT_SUBMENU,0, "RBW", menu_rbw}, #ifdef __SPUR__ - { MT_ADV_CALLBACK | MT_LOW,0, "SPUR\nREMOVAL", menu_spur_acb}, + { MT_ADV_CALLBACK,0, "%s", menu_spur_acb}, #endif { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel From d2964514b3d5aa8249d5f8d47d753d607b7b6d4e Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 7 Sep 2020 15:34:49 +0200 Subject: [PATCH 5/7] Removed freq grid and corrected spur avoidance bug --- sa_core.c | 24 ++++++++++++++++-------- si4432.c | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/sa_core.c b/sa_core.c index 17ca04a..cda52a8 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1333,11 +1333,13 @@ search_maximum(int m, int center, int span) //static int spur_old_stepdelay = 0; static const unsigned int spur_IF = 433800000; // The IF frequency for which the spur table is value -static const unsigned int spur_alternate_IF = 433900000; // if the frequency is found in the spur table use this IF frequency +static const unsigned int spur_alternate_IF = 434000000; // if the frequency is found in the spur table use this IF frequency static const int spur_table[] = // Frequencies to avoid { // 580000, // 433.8 MHz table +// 880000, //? 960000, +// 1487000, //? 1600000, // 1837000, // Real signal // 2755000, // Real signal @@ -1404,8 +1406,8 @@ int binary_search(int f) { int L = 0; int R = (sizeof spur_table)/sizeof(int) - 1; - int fmin = f - actual_rbw_x10 * 100; - int fplus = f + actual_rbw_x10 * 100; + int fmin = f - actual_rbw_x10 * (100 / 2); + int fplus = f + actual_rbw_x10 * (100 / 2); while (L <= R) { int m = (L + R) / 2; if (spur_table[m] < fmin) @@ -1584,6 +1586,10 @@ modulation_again: // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ pureRSSI_t RSSI = float_TO_PURE_RSSI(-150); +#define __DEBUG_SPUR__ +#ifdef __DEBUG_SPUR__ // For debugging the spur avoidance control + stored_t[i] = -90.0; // Display when to do spur shift in the stored trace +#endif int t = 0; do { uint32_t lf = f; @@ -1609,7 +1615,7 @@ modulation_again: local_IF = 0; else { if (setting.auto_IF) - local_IF = setting.spur_removal ? 433900000 : 433800000; + local_IF = setting.spur_removal ? 433900000 : spur_IF; else local_IF = setting.frequency_IF; } @@ -1618,8 +1624,11 @@ modulation_again: set_freq (SI4432_RX , local_IF + lf - reffer_freq[setting.refer]); // Offset so fundamental of reffer is visible #endif } else if (MODE_LOW(setting.mode)) { - if (setting.mode == M_LOW && !in_selftest && avoid_spur(f)) { // check is alternate IF is needed to avoid spur. + if (setting.mode == M_LOW && !in_selftest && avoid_spur(lf)) { // check if alternate IF is needed to avoid spur. local_IF = spur_alternate_IF; +#ifdef __DEBUG_SPUR__ // For debugging the spur avoidance control + stored_t[i] = -60.0; // Display when to do spur shift in the stored trace +#endif #ifdef __SPUR__ } else if (setting.mode== M_LOW && setting.spur_removal){ // If in low input mode and spur reduction is on if (S_IS_AUTO(setting.below_IF) && lf < 150000000) // if below 150MHz and auto_below_IF @@ -1829,6 +1838,7 @@ static bool sweep(bool break_on_operation) // if (setting.mode== -1) // return; // START_PROFILE; + START_PROFILE; palClearPad(GPIOB, GPIOB_LED); @@ -1922,9 +1932,6 @@ sweep_again: // stay in sweep loop when output mo // #define __DEBUG_AGC__ #ifdef __DEBUG_AGC__ // For debugging the AGC control stored_t[i] = (SI4432_Read_Byte(0x69) & 0x01f) * 3.0 - 90.0; // Display the AGC value in the stored trace -#endif -#ifdef __DEBUG_SPUR__ // For debugging the spur avoidance control - stored_t[i] = (avoid_spur(frequencies[i]) ? -60.0 : - 90.0); // Display when to do spur shift in the stored trace #endif if (scandirty || setting.average == AV_OFF) { // Level calculations actual_t[i] = RSSI; @@ -2338,6 +2345,7 @@ sweep_again: // stay in sweep loop when output mo ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0); palSetPad(GPIOB, GPIOB_LED); + STOP_PROFILE; return true; } diff --git a/si4432.c b/si4432.c index 8826add..9fd947a 100644 --- a/si4432.c +++ b/si4432.c @@ -349,7 +349,7 @@ void SI4432_Set_Frequency ( uint32_t Freq ) { // int mode = SI4432_Read_Byte(0x02) & 0x03; // Disabled as unreliable // SI4432_Write_Byte(0x07, 0x02); // Switch to tune mode - Freq = (Freq / 1000 ) * 1000; // force freq to 1000 grid +// Freq = (Freq / 1000 ) * 1000; // force freq to 1000 grid uint8_t hbsel; if (0) shell_printf("%d: Freq %q\r\n", SI4432_Sel, Freq); From 564b2a971d7c9b83b3b9a33a0581edecb4dc177b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 8 Sep 2020 12:53:38 +0200 Subject: [PATCH 6/7] High node auto AGC and MIRROR MASKING for attenuation active --- sa_core.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/sa_core.c b/sa_core.c index cda52a8..761beaf 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1586,7 +1586,7 @@ modulation_again: // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ pureRSSI_t RSSI = float_TO_PURE_RSSI(-150); -#define __DEBUG_SPUR__ +//#define __DEBUG_SPUR__ #ifdef __DEBUG_SPUR__ // For debugging the spur avoidance control stored_t[i] = -90.0; // Display when to do spur shift in the stored trace #endif @@ -1838,8 +1838,6 @@ static bool sweep(bool break_on_operation) // if (setting.mode== -1) // return; // START_PROFILE; - START_PROFILE; - palClearPad(GPIOB, GPIOB_LED); downslope = true; // Initialize the peak search algorithm @@ -1887,7 +1885,8 @@ sweep_again: // stay in sweep loop when output mo // ----------------------- in loop AGC --------------------------------- if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { -#define AGC_RSSI_THRESHOLD -55 +#define AGC_RSSI_THRESHOLD (-55+get_attenuation()) + if (RSSI > AGC_RSSI_THRESHOLD && RSSI > agc_prev_rssi) { agc_peak_freq = frequencies[i]; agc_peak_rssi = agc_prev_rssi = RSSI; @@ -2087,12 +2086,22 @@ sweep_again: // stay in sweep loop when output mo #ifdef __MIRROR_MASKING__ if (setting.mode == M_HIGH && setting.mirror_masking) { int mirror_offset = 2 * 937000 / setting.frequency_step; +// int mask_start = 0; +// int mask_end = 0; if (mirror_offset > 3) { for (int i = 1; i < sweep_points - mirror_offset; i++) { - if (actual_t[i] > -80 && actual_t[i+mirror_offset] < actual_t[i] - 25) { - actual_t[i+mirror_offset] = actual_t[i+mirror_offset-1]; - actual_t[i+mirror_offset+1] = actual_t[i+mirror_offset-1]; + int m = i+mirror_offset; + if (actual_t[i] > -80 && actual_t[m] < actual_t[i] - 25 && ( actual_t[m] > actual_t[m-1] || actual_t[m+1] > actual_t[m-1] ) /* && (i < mask_start || mask_start == 0) */ ) { +// if (mask_start == 0) +// mask_start = m; + actual_t[m] = actual_t[m-1]; + actual_t[m+1] = actual_t[m-1]; } +// else { +// if (i == mask_start) +// i += mirror_offset; +// mask_start =0; +// } } } } @@ -2345,7 +2354,6 @@ sweep_again: // stay in sweep loop when output mo ili9341_fill(OFFSETX, HEIGHT_NOSCROLL+1, WIDTH, 1, 0); palSetPad(GPIOB, GPIOB_LED); - STOP_PROFILE; return true; } @@ -2642,6 +2650,15 @@ void draw_cal_status(void) y += YSTEP + YSTEP/2 ; ili9341_drawstring("Spur:", x, y); + y += YSTEP; + plot_printf(buf, BLEN, "ON"); + ili9341_drawstring(buf, x, y); + } + if (setting.mirror_masking) { + ili9341_set_foreground(BRIGHT_COLOR_GREEN); + y += YSTEP + YSTEP/2 ; + ili9341_drawstring("Mask:", x, y); + y += YSTEP; plot_printf(buf, BLEN, "ON"); ili9341_drawstring(buf, x, y); From 6351063eb8c5c0287a3746052214e6a9b089787a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 8 Sep 2020 16:36:12 +0200 Subject: [PATCH 7/7] Restore load preset at startup --- main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.c b/main.c index ff2bade..3d741f6 100644 --- a/main.c +++ b/main.c @@ -2763,6 +2763,7 @@ goto again; // menu_mode_cb(setting.mode,0); // } redraw_frame(); +#if 0 set_mode(M_HIGH); set_sweep_frequency(ST_STOP, (uint32_t) 30000000); sweep(false); @@ -2772,6 +2773,7 @@ goto again; set_sweep_frequency(ST_STOP, (uint32_t) 4000000); sweep(false); set_sweep_frequency(ST_STOP, (uint32_t) 350000000); +#endif set_refer_output(-1); // ui_mode_menu(); // Show menu when autostarting mode