Rewrite RBW and actualRBW use code

Now values is uint16 (float before)
And value = x10 in kHz (possibly better use uint32_t and in Hz)
Only one part of code i think need more fix:
VBW use still float
pull/4/head
DiSlord 6 years ago
parent 7245722343
commit 0dedf0b19d

@ -571,7 +571,7 @@ typedef struct setting
float attenuate;
int auto_attenuation;
int atten_step;
int rbw;
int rbw_x10;
int below_IF;
int average;
int show_stored;
@ -856,7 +856,7 @@ int SI4432_is_fast_mode(void);
#endif
#endif
void SI4432_Set_Frequency ( uint32_t Freq );
float SI4432_SET_RBW(float WISH);
uint16_t SI4432_SET_RBW(uint16_t WISH);
void SI4432_SetReference(int freq);
// Speed profile definition
@ -887,7 +887,7 @@ void wait_user(void);
void calibrate(void);
float to_dBm(float);
uint32_t calc_min_sweep_time_us(void);
extern float actual_rbw;
extern uint16_t actual_rbw_x10;
enum {
M_OFF, M_IMD, M_OIP3, M_PHASE_NOISE, M_STOP_BAND, M_PASS_BAND, M_LINEARITY

@ -899,7 +899,7 @@ static void trace_get_value_string(
// frequency_string(&buf2[1], sizeof(buf2) -1, dfreq);
v = value(coeff[i]);
if (mtype & M_NOISE)
v = v - 10*log10(actual_rbw*1000.0);
v = v - 10*log10(actual_rbw_x10*100.0);
if (v == -INFINITY)
plot_printf(buf, len, "-INF");
else {

@ -204,14 +204,14 @@ VNA_SHELL_FUNCTION(cmd_rbw)
return;
}
if (strcmp(argv[0],"auto") == 0 || strcmp(argv[0],"0") == 0) {
if (setting.rbw != 0)
if (setting.rbw_x10 != 0)
set_RBW(0);
} else {
int a = my_atoi(argv[0]);
if (a < 2 || a>600)
goto usage;
if (setting.rbw != a)
set_RBW(a);
if (setting.rbw_x10 != a*10)
set_RBW(a*10);
}
}

@ -27,7 +27,7 @@ extern int actualStepDelay;
setting_t setting;
uint32_t frequencies[POINTS_COUNT];
float actual_rbw = 0;
uint16_t actual_rbw_x10 = 0;
int vbwSteps = 1;
uint32_t minFreq = 0;
uint32_t maxFreq = 520000000;
@ -63,7 +63,7 @@ void reset_settings(int m)
set_scale(10);
set_reflevel(-10);
setting.attenuate = 0;
setting.rbw = 0;
setting.rbw_x10 = 0;
setting.average = 0;
setting.harmonic = 0;
setting.show_stored = 0;
@ -491,7 +491,7 @@ int level_is_calibrated(void)
void set_RBW(int v)
{
setting.rbw = v;
setting.rbw_x10 = v;
update_rbw();
dirty = true;
}
@ -786,14 +786,14 @@ void apply_settings(void) // Ensure all settings in the setting structure
else
actualStepDelay = setting.step_delay;
} else if (setting.step_delay <= 2){ // Frequency sweep so use RBW to calculate minimum delay when changing frequency
if (actual_rbw >= 191.0) actualStepDelay = 280;
else if (actual_rbw >= 142.0) actualStepDelay = 350;
else if (actual_rbw >= 75.0) actualStepDelay = 450;
else if (actual_rbw >= 56.0) actualStepDelay = 650;
else if (actual_rbw >= 37.0) actualStepDelay = 700;
else if (actual_rbw >= 18.0) actualStepDelay = 1100;
else if (actual_rbw >= 9.0) actualStepDelay = 1700;
else if (actual_rbw >= 5.0) actualStepDelay = 3300;
if (actual_rbw_x10 >= 1910) actualStepDelay = 280;
else if (actual_rbw_x10 >= 1420) actualStepDelay = 350;
else if (actual_rbw_x10 >= 750) actualStepDelay = 450;
else if (actual_rbw_x10 >= 560) actualStepDelay = 650;
else if (actual_rbw_x10 >= 370) actualStepDelay = 700;
else if (actual_rbw_x10 >= 180) actualStepDelay = 1100;
else if (actual_rbw_x10 >= 90) actualStepDelay = 1700;
else if (actual_rbw_x10 >= 50) actualStepDelay = 3300;
else actualStepDelay = 6400;
if (setting.step_delay == 1) // In precise mode wait twice as long for RSSI to stabalize
actualStepDelay *= 2;
@ -1040,29 +1040,29 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (#
} else {
setting.vbw = 300; // trick to get right default rbw in zero span mode
}
actual_rbw = setting.rbw; // requested rbw
if (actual_rbw == 0) { // if auto rbw
actual_rbw = 2*setting.vbw; // rbw is twice the frequency step to ensure no gaps in coverage
actual_rbw_x10 = setting.rbw_x10; // requested rbw
if (actual_rbw_x10 == 0) { // if auto rbw
actual_rbw_x10 = 20.0*setting.vbw; // rbw is twice the frequency step to ensure no gaps in coverage
}
if (actual_rbw < 2.6)
actual_rbw = 2.6;
if (actual_rbw > 600)
actual_rbw = 600;
if (actual_rbw_x10 < 26)
actual_rbw_x10 = 26;
if (actual_rbw_x10 > 6000)
actual_rbw_x10 = 6000;
if (setting.spur && actual_rbw > 300)
actual_rbw = 250; // if spur suppression reduce max rbw to fit within BPF
if (setting.spur && actual_rbw_x10 > 3000)
actual_rbw_x10 = 2500; // if spur suppression reduce max rbw to fit within BPF
SI4432_Sel = MODE_SELECT(setting.mode);
actual_rbw = SI4432_SET_RBW(actual_rbw); // see what rbw the SI4432 can realize
actual_rbw_x10 = SI4432_SET_RBW(actual_rbw_x10); // see what rbw the SI4432 can realize
if (setting.frequency_step > 0 && MODE_INPUT(setting.mode)) { // When doing frequency scanning in input mode
vbwSteps = ((int)(2 * (setting.vbw + (actual_rbw/2)) / actual_rbw)); // calculate # steps in between each frequency step due to rbw being less than frequency step
vbwSteps = ((int)(2 * (setting.vbw + (actual_rbw_x10/20.0)) / (actual_rbw_x10/10.0))); // calculate # steps in between each frequency step due to rbw being less than frequency step
if (setting.step_delay==1) // if in Precise scanning
vbwSteps *= 2; // use twice as many steps
if (vbwSteps < 1) // at least one step
vbwSteps = 1;
} else { // in all other modes
setting.vbw = actual_rbw;
setting.vbw = actual_rbw_x10/10.0;
vbwSteps = 1; // only one vbwSteps
}
dirty = true;
@ -1072,8 +1072,8 @@ int binary_search_frequency(int f) // Search which index in the frequency t
{
int L = 0;
int R = (sizeof frequencies)/sizeof(int) - 1;
int fmin = f - ((int)actual_rbw ) * 1000;
int fplus = f + ((int)actual_rbw ) * 1000;
int fmin = f - actual_rbw_x10 * 100;
int fplus = f + actual_rbw_x10 * 100;
while (L <= R) {
int m = (L + R) / 2;
if ((int)frequencies[m] < fmin)
@ -1216,8 +1216,8 @@ int binary_search(int f)
{
int L = 0;
int R = (sizeof spur_table)/sizeof(int) - 1;
int fmin = f - ((int)actual_rbw ) * 1000;
int fplus = f + ((int)actual_rbw ) * 1000;
int fmin = f - actual_rbw_x10 * 100;
int fplus = f + actual_rbw_x10 * 100;
while (L <= R) {
int m = (L + R) / 2;
if (spur_table[m] < fmin)
@ -1236,7 +1236,7 @@ int avoid_spur(int f) // find if this frequency should be avoi
// int window = ((int)actual_rbw ) * 1000*2;
// if (window < 50000)
// window = 50000;
if (setting.mode != M_LOW || !setting.auto_IF || actual_rbw > 300.0)
if (setting.mode != M_LOW || !setting.auto_IF || actual_rbw_x10 > 3000)
return(false);
return binary_search(f);
}
@ -1355,7 +1355,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
} else { // Even, shift half step
offs = (t - (vbwSteps >> 1)) * sm + sm/2;
}
offs = (int)(offs * actual_rbw);
offs = (int)(offs * actual_rbw_x10/10.0);
lf = (uint32_t)(f + offs);
}
@ -1399,7 +1399,7 @@ float perform(bool break_on_operation, int i, uint32_t f, int tracking) // M
setting.below_IF = S_AUTO_OFF; // and above IF in second pass
}
else {
int32_t spur_offset = actual_rbw * 1000; // Can not use below IF so calculate IF shift that hopefully will kill the spur.
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
spur_offset = - spur_offset; // IF shift in the other direction
local_IF = local_IF + spur_offset; // apply IF spur shift
@ -2285,7 +2285,7 @@ void draw_cal_status(void)
}
// RBW
if (setting.rbw)
if (setting.rbw_x10)
color = BRIGHT_COLOR_GREEN;
else
color = DEFAULT_FG_COLOR;
@ -2295,7 +2295,7 @@ void draw_cal_status(void)
ili9341_drawstring("RBW:", x, y);
y += YSTEP;
plot_printf(buf, BLEN, "%.1FkHz", actual_rbw);
plot_printf(buf, BLEN, "%.1FkHz", actual_rbw_x10/10.0);
ili9341_drawstring(buf, x, y);
#if 0
@ -2853,7 +2853,7 @@ void self_test(int test)
#define FREQ_STEP 3000
set_RBW(FREQ_STEP/1000);
set_RBW(FREQ_STEP/100);
last_spur = 0;
for (int j = 0; j < 10; j++) {
@ -2893,7 +2893,7 @@ void self_test(int test)
test_prepare(i);
for (int j= 0; j < 50; j++ ) {
test_prepare(i);
set_RBW(30);
set_RBW(300);
set_attenuation((float)j);
float summed_peak_level = 0;
@ -2923,9 +2923,9 @@ void self_test(int test)
test_prepare(i);
setting.spur = 0;
setting.step_delay = setting.step_delay * 5 / 4;
setting.rbw = SI4432_force_RBW(j);
shell_printf("RBW = %d, ",setting.rbw);
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw * 10000));
setting.rbw_x10 = SI4432_force_RBW(j);
shell_printf("RBW = %d, ",setting.rbw_x10/10);
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 1000));
setting.repeat = 10;
test_acquire(i); // Acquire test
test_validate(i); // Validate test
@ -2941,7 +2941,7 @@ void self_test(int test)
setting.spur = 0;
setting.step_delay = setting.step_delay * 4 / 5;
// shell_printf("\n\rRBW = %f",SI4432_force_RBW(j));
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw * 10000));
set_sweep_frequency(ST_SPAN, (uint32_t)(setting.rbw_x10 * 1000));
setting.repeat = 10;
test_acquire(i); // Acquire test
test_validate(i); // Validate test

@ -303,15 +303,14 @@ static RBW_t RBW_choices[] = {
static float SI4432_RSSI_correction = -120.0;
float SI4432_force_RBW(int i)
uint16_t SI4432_force_RBW(int i)
{
SI4432_Write_Byte(SI4432_IF_FILTER_BW, RBW_choices[i].reg); // Write RBW settings to Si4432
SI4432_RSSI_correction = ((int)RBW_choices[i].RSSI_correction_x_10-1200)/10.0; // Set RSSI correction
return (((float)RBW_choices[i].RBWx10) / 10.0); // RBW achieved by Si4432 in kHz
return RBW_choices[i].RBWx10; // RBW achieved by Si4432 in kHz * 10
}
float SI4432_SET_RBW(float w) {
uint16_t WISH = (uint16_t)(w * 10.0);
uint16_t SI4432_SET_RBW(uint16_t WISH) {
int i;
for (i=0; i < (int)(sizeof(RBW_choices)/sizeof(RBW_t)) - 1; i++)
if (WISH <= RBW_choices[i].RBWx10)
@ -526,7 +525,7 @@ void SI4432_Sub_Init(void)
// Clock Recovery Gearshift Value
SI4432_Write_Byte(SI4432_CLOCK_RECOVERY_GEARSHIFT, 0x00);
// IF Filter Bandwidth
SI4432_SET_RBW(10) ;
SI4432_SET_RBW(100) ;
// // Register 0x75 Frequency Band Select
// byte sbsel = 1 ; // recommended setting
// byte hbsel = 0 ; // low bands

@ -111,7 +111,7 @@ float Simulated_SI4432_RSSI(uint32_t i, int s);
void SI4432_Set_Frequency ( uint32_t Freq );
void SI4432_Transmit(int d);
void SI4432_Receive(void);
float SI4432_SET_RBW(float WISH);
uint16_t SI4432_SET_RBW(uint16_t WISH);
void PE4302_Write_Byte(unsigned char DATA );
void PE4302_init(void);

@ -970,13 +970,13 @@ static void menu_marker_modify_cb(int item, uint8_t data)
draw_menu();
}
const int rbwsel[]={0,3,10,30,100,300,600};
// last index - for item back button!!
static const uint16_t rbwsel_x10[]={0,30,100,300,1000,3000,6000, -1};
static void menu_rbw_cb(int item, uint8_t data)
{
(void)item;
set_RBW(rbwsel[data]);
set_RBW(rbwsel_x10[data]);
menu_move_back();
ui_mode_normal();
// draw_cal_status();
@ -1643,7 +1643,7 @@ static void menu_item_modify_attribute(
mark = true;
}
} else if (menu == menu_rbw) {
if (rbwsel[item] == setting.rbw){
if (rbwsel_x10[item] == setting.rbw_x10){
mark = true;
}

Loading…
Cancel
Save

Powered by TurnKey Linux.