diff --git a/main.c b/main.c index e30d297..69cdf29 100644 --- a/main.c +++ b/main.c @@ -1000,6 +1000,7 @@ config_t config = { .ultra_level_offset = 0.0, // Uncalibrated .direct_lna_level_offset = 0, .ultra_lna_level_offset = 0, + .adf_level_offset = 0, .correction_frequency = { /* low */ { 10000, 40000, 100000, 300000, 500000, 900000, 4000000, 6000000, 30000000, 90000000, 210000000, 300000000, 380000000, 510000000, 600000000, 690000000, 780000000, 810000000, 820000000, 830000000}, diff --git a/nanovna.h b/nanovna.h index 518baa9..fb499ca 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 @@ -743,6 +743,7 @@ typedef struct config { float ultra_level_offset; float direct_lna_level_offset; float ultra_lna_level_offset; + float adf_level_offset; #endif #ifdef __NOISE_FIGURE__ float noise_figure; diff --git a/sa_cmd.c b/sa_cmd.c index 215e22e..231e0aa 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -370,7 +370,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna"; + static const char cmd_mode_list[] = "low|switch|receive_switch|out_switch|lna|harmonic|shift1|shift2|shift3|drive1|drive2|drive3|direct|direct_lna|ultra|ultra_lna|adf"; #else static const char cmd_mode_list[] = "low|high|switch|receive_switch"; #endif @@ -402,6 +402,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "direct_lna", config.direct_lna_level_offset); shell_printf(p, "ultra", config.ultra_level_offset); shell_printf(p, "ultra_lna", config.ultra_lna_level_offset); + shell_printf(p, "adf", config.adf_level_offset); #endif return; } @@ -437,6 +438,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 13: config.direct_lna_level_offset = v; break; case 14: config.ultra_level_offset = v; break; case 15: config.ultra_lna_level_offset = v; break; + case 16: config.adf_level_offset = v; break; #endif default: goto usage; } diff --git a/sa_core.c b/sa_core.c index 60b1e17..eb996b6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1554,7 +1554,7 @@ float get_level_offset(void) return(lev == 100? 0 : lev); } if (setting.mode == M_GENLOW) { - return(LOW_OUT_OFFSET); + return(LOW_OUT_OFFSET); } if (setting.mode == M_GENHIGH) { return(config.high_level_output_offset); @@ -2071,6 +2071,8 @@ void calculate_step_delay(void) SI4432_step_delay = step_delay_table[i].step_delay; SI4432_offset_delay = step_delay_table[i].offset_delay; spur_gate = actual_rbw_x10 * (actual_rbw_x10 > 5000 ? (100/2) : 100); + if (spur_gate < 30000) + spur_gate = 30000; // spur_gate = step_delay_table[i].spur_div_1000 * 1000; noise_level = step_delay_table[i].noise_level - PURE_TO_float(get_signal_path_loss()); log_averaging_correction = step_delay_table[i].log_aver_correction; @@ -2214,6 +2216,7 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c break; case PATH_LEAKAGE: c = CORRECTION_LOW_OUT_ADF; + cv += float_TO_PURE_RSSI(-config.adf_level_offset); break; } } @@ -2925,7 +2928,7 @@ static const freq_t spur_table[] = // Frequenci const int spur_table_size = (sizeof spur_table)/sizeof(freq_t); #endif #ifdef TINYSA4 -#define STATIC_SPUR_TABLE_SIZE 55 +#define STATIC_SPUR_TABLE_SIZE 56 static const freq_t static_spur_table[STATIC_SPUR_TABLE_SIZE] = // Valid for IF=977.4MHz { 5233000, @@ -2949,6 +2952,7 @@ static const freq_t static_spur_table[STATIC_SPUR_TABLE_SIZE] = // Valid fo 115200000, 243881127, 471300000, + 487750054, 487762254, 501300000, 508800000, @@ -4094,7 +4098,8 @@ again: // Spur redu if (local_modulo == 0) ADF4351_modulo(4000); freq_t tf = ((lf + actual_rbw_x10*200) / TCXO) * TCXO; - if (tf + actual_rbw_x10*200 >= lf && tf < lf + actual_rbw_x10*200 && tf != 180000000) { // 30MHz + if (tf + actual_rbw_x10*200 >= lf && tf < lf + actual_rbw_x10*200 /* && tf != 180000000 */ ) { // 30MHz + setting.increased_R = true; if ( (tf / TCXO) & 1 ) { // Odd harmonic of 30MHz ADF4351_R_counter(-3); } diff --git a/si4468.c b/si4468.c index b0cc862..0d88c22 100644 --- a/si4468.c +++ b/si4468.c @@ -1796,8 +1796,8 @@ void SI4463_set_modem_DSM(void) { uint16_t force_rbw(int f) { - if (SI4463_in_tx_mode || f >= (int)(sizeof(RBW_choices)/sizeof(RBW_t))) - return(0); + if (/*SI4463_in_tx_mode || */ f >= (int)(sizeof(RBW_choices)/sizeof(RBW_t))) + return(0); // RBW can be selected before switch to input mode is made SI4463_set_state(SI446X_STATE_READY); const uint8_t *config = RBW_choices[f].reg; uint16_t i=0; diff --git a/ui_sa.c b/ui_sa.c index b514f54..8c61fd1 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -765,8 +765,11 @@ static UI_FUNCTION_CALLBACK(menu_output_curve_prepare_cb) { (void)item; (void)data; - if (config.low_level_output_offset == 100) + if (config.low_level_output_offset == 100) { + drawMessageBox("Error", "First set OUTPUT LEVEL", 2000); + redraw_request|= REDRAW_AREA; return; + } current_curve = CORRECTION_LOW_OUT; menu_push_submenu(menu_curve); } @@ -2883,10 +2886,76 @@ static const menuitem_t menu_sweep_speed[] = { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; +#ifdef TINYSA4 +static const menuitem_t menu_curve3[] = { + { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(14,6), MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_NONE, 0, NULL, menu_back} // next-> menu_back +}; + +static const menuitem_t menu_curve2[] = { + { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(7,7), MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve3}, + { MT_NONE, 0, NULL, menu_back} // next-> menu_back +}; + +static const menuitem_t menu_curve[] = { + { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(0,7), MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve2}, + { MT_NONE, 0, NULL, menu_back} // next-> menu_back +}; + +static const menuitem_t menu_curve_confirm[] = { + { MT_CALLBACK, 1, "OK", menu_curve_confirm_cb }, + { MT_CALLBACK, 0, "CANCEL", menu_curve_confirm_cb }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +static const menuitem_t menu_noise_figure_confirm[] = { + { MT_CALLBACK, 1, "STORE\nTINYSA NF", menu_noise_figure_confirm_cb }, + { MT_CALLBACK, 0, "CANCEL", menu_noise_figure_confirm_cb }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +#endif + +static const menuitem_t menu_actual_power[] = +{ + { MT_KEYPAD, KM_ACTUALPOWER, "INPUT\nLEVEL", "dBm"}, + { MT_ADV_CALLBACK, 0, "OUTPUT\nLEVEL", menu_output_level_acb}, +#ifdef TINYSA4 + { MT_CALLBACK, 0, "INPUT\nCURVE", menu_input_curve_prepare_cb}, + { MT_CALLBACK, 0, "LNA\nCURVE", menu_lna_curve_prepare_cb}, + { MT_CALLBACK, 0, "ULTRA\nCURVE", menu_ultra_curve_prepare_cb}, + { MT_CALLBACK, 0, "LNA_U\nCURVE", menu_lna_u_curve_prepare_cb}, + { MT_CALLBACK, 0, "OUTPUT\nCURVE", menu_output_curve_prepare_cb}, +#endif + { MT_NONE, 0, NULL, menu_back} // next-> menu_back +}; + #ifdef TINYSA4 static const menuitem_t menu_settings4[]; #endif +#ifdef TINYSA4 +static const menuitem_t menu_settings4[] = +{ + { MT_ADV_CALLBACK, 0, "DEBUG\nFREQ", menu_debug_freq_acb}, + { MT_ADV_CALLBACK, 0, "DEBUG\nAVOID", menu_debug_avoid_acb}, + { MT_ADV_CALLBACK, 0, "DEBUG\nSPUR", menu_debug_spur_acb}, +#if 0 // only used during development + { MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"}, + { MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"}, + { MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"}, +#endif +// { MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb}, + { MT_ADV_CALLBACK, 0, "LINEAR\nAVERAGING", menu_linear_averaging_acb}, +// { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, + { MT_KEYPAD, KM_DIRECT_START, "DSTART\n\b%s", ""}, + { MT_KEYPAD, KM_DIRECT_STOP, "DSTOP\n\b%s", ""}, + { MT_NONE, 0, NULL, menu_back} // next-> menu_back +}; +#endif + static const menuitem_t menu_settings3[] = { #ifdef TINYSA4 @@ -2932,33 +3001,6 @@ static const menuitem_t menu_settings3[] = #endif // TINYSA4 { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; -#ifdef TINYSA4 -static const menuitem_t menu_settings4[] = -{ - { MT_ADV_CALLBACK, 0, "DEBUG\nFREQ", menu_debug_freq_acb}, - { MT_ADV_CALLBACK, 0, "DEBUG\nAVOID", menu_debug_avoid_acb}, - { MT_ADV_CALLBACK, 0, "DEBUG\nSPUR", menu_debug_spur_acb}, - { MT_ADV_CALLBACK, 0, "PROGRESS\nBAR", menu_progress_bar_acb}, -#if 0 // only used during development - { MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"}, - { MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"}, - { MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"}, -#endif -#ifdef __NOISE_FIGURE__ - { MT_KEYPAD, KM_NF, "NF\n\b%s", "Enter tinySA noise figure"}, -#endif -#ifdef __SD_CARD_LOAD__ - { 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}, - { MT_ADV_CALLBACK, 0, "LINEAR\nAVERAGING", menu_linear_averaging_acb}, -// { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, - { MT_KEYPAD, KM_DIRECT_START, "DSTART\n\b%s", ""}, - { MT_KEYPAD, KM_DIRECT_STOP, "DSTOP\n\b%s", ""}, - { MT_NONE, 0, NULL, menu_back} // next-> menu_back -}; -#endif static const menuitem_t menu_settings2[] = { @@ -2966,75 +3008,37 @@ static const menuitem_t menu_settings2[] = { MT_ADV_CALLBACK, 0, "LNA", menu_settings_lna_acb}, { MT_ADV_CALLBACK | MT_LOW, 0, "BPF", menu_settings_bpf_acb}, { MT_ADV_CALLBACK | MT_LOW, 0, "BELOW IF", menu_settings_below_if_acb}, + { MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ\n\b%s", "0=auto IF"}, { MT_KEYPAD, KM_DECAY, "DECAY\n\b%s", "0..1000000ms or sweeps"}, #ifdef __QUASI_PEAK__ { MT_KEYPAD, KM_ATTACK, "ATTACK\n\b%s", "0..100000ms"}, #endif + { MT_SUBMENU,0, "SCAN\nSPEED", menu_scanning_speed}, #ifdef TINYSA4 - { MT_KEYPAD, KM_FREQ_CORR, "FREQ CORR\n\b%s", "Enter ppb correction"}, + { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_mixer_drive}, +#else + { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_lo_drive}, #endif { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings3}, { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; -#ifdef TINYSA4 -static const menuitem_t menu_curve3[] = { - { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(14,6), MT_CUSTOM_LABEL, menu_curve_acb }, - { MT_NONE, 0, NULL, menu_back} // next-> menu_back -}; - -static const menuitem_t menu_curve2[] = { - { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(7,7), MT_CUSTOM_LABEL, menu_curve_acb }, - { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve3}, - { MT_NONE, 0, NULL, menu_back} // next-> menu_back -}; - -static const menuitem_t menu_curve[] = { - { MT_FORM | MT_ADV_CALLBACK | MT_REPEATS, DATA_STARTS_REPEATS(0,7), MT_CUSTOM_LABEL, menu_curve_acb }, - { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve2}, - { MT_NONE, 0, NULL, menu_back} // next-> menu_back -}; - -static const menuitem_t menu_curve_confirm[] = { - { MT_CALLBACK, 1, "OK", menu_curve_confirm_cb }, - { MT_CALLBACK, 0, "CANCEL", menu_curve_confirm_cb }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -static const menuitem_t menu_noise_figure_confirm[] = { - { MT_CALLBACK, 1, "STORE\nTINYSA NF", menu_noise_figure_confirm_cb }, - { MT_CALLBACK, 0, "CANCEL", menu_noise_figure_confirm_cb }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -#endif - -static const menuitem_t menu_actual_power[] = -{ - { MT_KEYPAD, KM_ACTUALPOWER, "INPUT\nLEVEL", "dBm"}, - { MT_ADV_CALLBACK, 0, "OUTPUT\nLEVEL", menu_output_level_acb}, -#ifdef TINYSA4 - { MT_CALLBACK, 0, "INPUT\nCURVE", menu_input_curve_prepare_cb}, - { MT_CALLBACK, 0, "LNA\nCURVE", menu_lna_curve_prepare_cb}, - { MT_CALLBACK, 0, "ULTRA\nCURVE", menu_ultra_curve_prepare_cb}, - { MT_CALLBACK, 0, "LNA_U\nCURVE", menu_lna_u_curve_prepare_cb}, - { MT_CALLBACK, 0, "OUTPUT\nCURVE", menu_output_curve_prepare_cb}, -#endif - { MT_NONE, 0, NULL, menu_back} // next-> menu_back -}; - static const menuitem_t menu_settings[] = { { MT_SUBMENU, 0, "LEVEL\nCORRECTION", menu_actual_power}, - { MT_KEYPAD | MT_LOW, KM_IF, "IF FREQ\n\b%s", "0=auto IF"}, - { MT_SUBMENU,0, "SCAN\nSPEED", menu_scanning_speed}, + { MT_ADV_CALLBACK, 0, "PROGRESS\nBAR", menu_progress_bar_acb}, #ifdef TINYSA4 - { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_mixer_drive}, -#else - { MT_SUBMENU | MT_LOW,0, "MIXER\nDRIVE", menu_lo_drive}, + { MT_KEYPAD, KM_FREQ_CORR, "FREQ CORR\n\b%s", "Enter ppb correction"}, +#endif +#ifdef __NOISE_FIGURE__ + { MT_KEYPAD, KM_NF, "NF\n\b%s", "Enter tinySA noise figure"}, +#endif +#ifdef __SD_CARD_LOAD__ + { MT_CALLBACK, 0 , "LOAD\nCONFIG.INI", menu_load_config_cb}, +// { MT_CALLBACK, 1 , "LOAD\nSETTING.INI", menu_load_config_cb}, #endif - { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2}, + { MT_SUBMENU, 0, "INTERNALS", menu_settings2}, { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; @@ -3154,7 +3158,6 @@ static const menuitem_t menu_config[] = { #ifdef __USE_RTC__ { MT_SUBMENU, 0, "DATE\nTIME", menu_date_time}, #endif -// { MT_SUBMENU, 0, "EXPERT\nCONFIG", menu_settings}, #ifndef TINYSA4 { MT_SUBMENU, 0, S_RARROW" DFU", menu_dfu}, #endif