diff --git a/main.c b/main.c index 2efc5c9..9bb3b95 100644 --- a/main.c +++ b/main.c @@ -2016,12 +2016,12 @@ static void VNAShell_executeLine(char *line) #ifndef __USE_SD_CARD__ #error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" #endif -void sd_card_load_config(void){ +void sd_card_load_config(char *filename){ // Mount card if (f_mount(fs_volume, "", 1) != FR_OK) return; - if (f_open(fs_file, "config.ini", FA_OPEN_EXISTING | FA_READ) != FR_OK) + if (f_open(fs_file, filename, FA_OPEN_EXISTING | FA_READ) != FR_OK) return; char *buf = (char *)spi_buffer; @@ -2273,7 +2273,7 @@ int main(void) chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); #ifdef __SD_CARD_LOAD__ - sd_card_load_config(); + sd_card_load_config("config.ini"); #endif while (1) { diff --git a/nanovna.h b/nanovna.h index 19eb4c4..647fa53 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1341,7 +1341,7 @@ bool SD_Inserted(void); #define fs_filename ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4) #endif void testLog(void); // debug log -void sd_card_load_config(void); +void sd_card_load_config(char *filename); #endif /* @@ -1444,7 +1444,7 @@ extern void si_fm_offset(int16_t offset); extern bool ADF4351_frequency_changed; extern bool SI4463_frequency_changed; extern bool SI4463_offset_changed; -extern int32_t SI4463_ENBW_Hz; +extern int16_t SI4463_noise_correction_x10; extern int old_R; extern float Si446x_get_temp(void); #define ENBW_Hz SI4463_ENBW_Hz diff --git a/plot.c b/plot.c index 2a826c3..a0b18f8 100644 --- a/plot.c +++ b/plot.c @@ -1430,8 +1430,7 @@ static void trace_print_value_string( // Only used at one place // *ptr2++ = 'N'; *ptr2++ = ' '; if (mtype & M_NOISE){ -// v-= log10f(ENBW_Hz) * 10.0; - v-= logf(ENBW_Hz) * (10.0/logf(10.0)); + v += - logf(actual_rbw_x10*100.0) * (10.0/logf(10.0)) + SI4463_noise_correction_x10/10.0; } // Not possible ??? if (v == -INFINITY){ @@ -1546,7 +1545,7 @@ static void cell_draw_marker_info(int x0, int y0) int ypos = 1 + (j/2)*(16) - y0; cell_printf(xpos, ypos, FONT_b"DEPTH: %3d%%", depth); } else if (setting.measurement == M_FM){ - freq_t dev = markers[1].frequency + ENBW_Hz; // Temp value to prevent calculation of negative deviation + freq_t dev = markers[1].frequency + actual_rbw_x10*100.0; // Temp value to prevent calculation of negative deviation if ( markers[2].frequency < dev) break; dev = ( markers[2].frequency - dev ) >> 1; @@ -1598,7 +1597,7 @@ static void cell_draw_marker_info(int x0, int y0) #else aNP = marker_to_value(0); #endif - float mNF = aNP - logf(ENBW_Hz) * (10.0/logf(10.0)) + 173.93; // measured noise figure at 20C + float mNF = aNP - logf(actual_rbw_x10*100.0) * (10.0/logf(10.0)) + 173.93 + SI4463_noise_correction_x10/10.0; // measured noise figure at 20C if (setting.external_gain != 0) { float mnf = expf(mNF/10 * logf(10)); // measure noise factor float tnf = expf(config.noise_figure/10 * logf(10)); // tinySA noise factor diff --git a/si4468.c b/si4468.c index 2dd52e5..cca7a1a 100644 --- a/si4468.c +++ b/si4468.c @@ -1517,27 +1517,27 @@ typedef struct { const uint8_t *reg; // IF_BW(dwn3, ndec, filset) int16_t RSSI_correction_x_10; // Correction * 10 int16_t RBWx10; // RBW in kHz - int32_t ENBW_Hz; + int16_t noise_correction_x10; // Noise marker correction * 10 }RBW_t; // sizeof(RBW_t) = 8 bytes static const RBW_t RBW_choices[] = { // BW register corr freq - {SI4463_RBW_02kHz, 15,3,188}, - {SI4463_RBW_1kHz, 14,10,1100}, - {SI4463_RBW_3kHz, 10,30,3341}, - {SI4463_RBW_10kHz, 14,100,10910}, - {SI4463_RBW_30kHz, 0,300,32500}, - {SI4463_RBW_100kHz,0,1000,106900}, - {SI4463_RBW_300kHz,1,3000,342000}, - {SI4463_RBW_600kHz,11,6000,640000}, - {SI4463_RBW_850kHz,11,8500,877000}, + {SI4463_RBW_02kHz, 18,3,42}, + {SI4463_RBW_1kHz, 18,10,22}, + {SI4463_RBW_3kHz, 12,30,21}, + {SI4463_RBW_10kHz, 7,100,20}, + {SI4463_RBW_30kHz, 10,300,20}, + {SI4463_RBW_100kHz,2,1000,26}, + {SI4463_RBW_300kHz,2,3000,19}, + {SI4463_RBW_600kHz,3,6000,18}, + {SI4463_RBW_850kHz,12,8500,15}, }; const uint8_t SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); static pureRSSI_t SI4463_RSSI_correction = float_TO_PURE_RSSI(-120); -int32_t SI4463_ENBW_Hz; +int16_t SI4463_noise_correction_x10; static int prev_band = -1; pureRSSI_t getSI4463_RSSI_correction(void){ @@ -1563,7 +1563,7 @@ uint16_t force_rbw(int f) set_RSSI_comp(); // prev_band = -1; SI4463_RSSI_correction = float_TO_PURE_RSSI(RBW_choices[f].RSSI_correction_x_10 - 1200)/10; // Set RSSI correction - SI4463_ENBW_Hz = RBW_choices[f].ENBW_Hz; + SI4463_noise_correction_x10 = RBW_choices[f].noise_correction_x10; return RBW_choices[f].RBWx10; // RBW achieved by SI4463 in kHz * 10 } diff --git a/ui_sa.c b/ui_sa.c index 85b4086..06ce952 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -790,8 +790,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) UI_FUNCTION_CALLBACK(menu_load_config_cb) { (void)item; - (void)data; - sd_card_load_config(); + sd_card_load_config((data?"config.ini":"setting.ini")); ui_mode_normal(); } #endif @@ -1353,8 +1352,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) kp_help_text = "Noise frequency"; ui_mode_keypad(KM_CENTER); set_marker_frequency(0, uistat.value); - kp_help_text = "Noise width"; - ui_mode_keypad(KM_SPAN); +// kp_help_text = "Noise width"; +// ui_mode_keypad(KM_SPAN); + set_sweep_frequency(ST_SPAN, 0); set_average(AV_100); break; #endif @@ -2517,7 +2517,8 @@ static const menuitem_t menu_settings4[] = { MT_KEYPAD, KM_NF, "NOISE\nFIGURE", "Enter tinySA noise figure"}, #endif #ifdef __SD_CARD_LOAD__ - { MT_CALLBACK, 0 , "LOAD\nCONFIG", menu_load_config_cb}, + { MT_CALLBACK, 0 , "LOAD\nCONFIG.INI", menu_load_config_cb}, + { MT_CALLBACK, 1 , "LOAD\nSETTING.INI", menu_load_config_cb}, #endif { MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb}, #ifdef __HARMONIC__