Updated 200Hz RBW

pull/34/head
erikkaashoek 3 years ago
parent a42955399d
commit 67f15efeea

@ -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 },

@ -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

@ -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)

@ -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<cur_max && trace_data[max_index[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,60 +5201,8 @@ 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;
}
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
add_to_peak_finding(actual_t, i);
// maintain sorted peak table
int j = 0; // Insert max in sorted table
while (j<cur_max && actual_t[max_index[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
}
}
}
@ -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<sweep_points; i++)
add_to_peak_finding(measured[t], i);
}
if (cur_max == 0) {
max_index[0] = local_peakIndex;
max_index[0] = peak_finding_index;
cur_max = 1;
}
if (MODE_INPUT(setting.mode)) { // Assign maxima found to tracking markers
@ -5469,7 +5485,7 @@ static volatile int dummy;
int m = 0;
while (i < cur_max) { // For all maxima found
while (m < MARKERS_MAX) {
if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // Available marker found
if (markers[m].enabled && markers[m].mtype & M_TRACKING && markers[m].trace == t) { // Available marker found
markers[m].index = max_index[i];
interpolate_maximum(m);
m++;
@ -5480,12 +5496,12 @@ static volatile int dummy;
i++;
}
while (m < MARKERS_MAX) { // Insufficient maxima found
if (markers[m].enabled && markers[m].mtype & M_TRACKING) { // More available markers found
if (markers[m].enabled && markers[m].mtype & M_TRACKING && markers[m].trace == t) { // More available markers found
set_marker_index(m, 0); // Enabled but no max so set to left most frequency
}
m++; // Try next marker
}
}
// ----------------------- now follow all the special marker calculations for the measurement modes ----------------------------
@ -5607,7 +5623,7 @@ static volatile int dummy;
peakIndex = max_index[0];
cur_max = 1;
} else
peakIndex = local_peakIndex;
peakIndex = peak_finding_index;
peakLevel = actual_t[peakIndex];
peakFreq = getFrequency(peakIndex);
min_level = temp_min_level;

@ -270,7 +270,7 @@ freq_t local_setting_frequency_30mhz_x100 = 3000000000;
#define CS_ADF_LOW(ch) {palClearLine(ch);ADF_CS_DELAY;}
#define CS_ADF_HIGH(ch) {ADF_CS_DELAY;palSetLine(ch);}
uint32_t registers[6] = {0xC80000, 0x8008011, 0x1800C642, 0x48963,0xA5003C , 0x580005} ; //10 MHz ref
uint32_t registers[6] = {0xC88000, 0x8008011, 0x1800C642, 0x48963,0xA5003C , 0x580005} ; //10 MHz ref
uint32_t old_registers[6];
int debug = 0;
@ -620,7 +620,8 @@ uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq) // freq / 10Hz
if (MOD == 1) MOD = 2;
registers[1] = 0;
registers[1] = MOD << 3;
registers[1] = registers[1] + 1 ; // restore register address "001"
registers[1] |= 1 ; // restore register address "001"
registers[1] |= 1 << 15; // Set PHASE to 1
bitSet (registers[1], 27); // Prescaler at 8/9
return actual_freq;
}
@ -1736,7 +1737,7 @@ static const RBW_t RBW_choices[] =
#else
#define NOISE_BASE_CORRECTION 7
{SI4463_RBW_02kHz, 15,3, NOISE_BASE_CORRECTION + 10}, //
{SI4463_RBW_02kHz, 15,2, NOISE_BASE_CORRECTION + -5}, //
{SI4463_RBW_1kHz, 15,10, NOISE_BASE_CORRECTION + -5},//
{SI4463_RBW_3kHz, 10,30, NOISE_BASE_CORRECTION + -5},//
{SI4463_RBW_10kHz, 14,100,NOISE_BASE_CORRECTION + 0}, //
@ -1744,7 +1745,7 @@ static const RBW_t RBW_choices[] =
{SI4463_RBW_100kHz, 0,1000,NOISE_BASE_CORRECTION + -5},//
{SI4463_RBW_300kHz, 0,3000,NOISE_BASE_CORRECTION}, // 300k must have RSSI correction = 0
{SI4463_RBW_600kHz, 5,6000,NOISE_BASE_CORRECTION + 0}, //
{SI4463_RBW_850kHz, 8,8500,NOISE_BASE_CORRECTION + 10},//
{SI4463_RBW_850kHz, 8,8500,NOISE_BASE_CORRECTION + 5},//
#endif
};

@ -558,6 +558,7 @@ static const menuitem_t menu_marker_ref_select[];
static const menuitem_t menu_connection[];
#endif
//static const menuitem_t menu_drive_wide[];
static const menuitem_t menu_config[];
#ifdef TINYSA4
static const menuitem_t menu_settings3[];
static const menuitem_t menu_curve[];
@ -2214,8 +2215,8 @@ static UI_FUNCTION_CALLBACK(menu_limit_disable_cb)
#endif
#ifdef TINYSA4
static const uint16_t rbwsel_x10[]={0,3,10,30,100,300,1000,3000,6000,8500};
static const char* rbwsel_text[]={"AUTO","300","1k","3k","10k","30k","100k","300k","600k","850k"};
static const uint16_t rbwsel_x10[]={0,2,10,30,100,300,1000,3000,6000,8500};
static const char* rbwsel_text[]={"AUTO","200","1k","3k","10k","30k","100k","300k","600k","850k"};
#else
static const uint16_t rbwsel_x10[]={0,30,100,300,1000,3000,6000};
#endif
@ -2712,7 +2713,7 @@ static const menuitem_t menu_sweep[] = {
static const menuitem_t menu_lowoutput_settings[] = {
{ MT_FORM | MT_ADV_CALLBACK, 0, "Cleanest signal, max 4.4GHz", menu_lowoutput_settings_acb},
{ MT_FORM | MT_ADV_CALLBACK, 1, "Highest accuracy, max 5.4GHz", menu_lowoutput_settings_acb},
{ MT_FORM | MT_SUBMENU, 255, S_RARROW"Expert Settings", menu_settings},
{ MT_FORM | MT_SUBMENU, 255, S_RARROW"Config", menu_config},
{ MT_FORM | MT_NONE, 0, NULL, menu_back} // next-> menu_back
};
#endif

Loading…
Cancel
Save

Powered by TurnKey Linux.