diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index acf778e..fb5a8da 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index b8d7390..b85ee23 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -28,6 +28,7 @@ #define BOARD_NAME "tinySA4" #include +//#include "..\nanovna.h" /* * Board frequencies. */ @@ -89,6 +90,7 @@ #define GPIOB_SPI_MOSI 5 #define GPIO_LO_SEL 6 #define LINE_LO_SEL PAL_LINE(GPIOB, GPIO_LO_SEL) +//#define __NEW_SWITCHES__ #ifdef __NEW_SWITCHES__ #define GPIO_SD_CD 12 #define LINE_SD_CD PAL_LINE(GPIOB, GPIO_SD_CD) diff --git a/nanovna.h b/nanovna.h index d9f05d6..4e39824 100644 --- a/nanovna.h +++ b/nanovna.h @@ -49,7 +49,7 @@ #define __SI4463__ #define __SI4468__ #define __ADF4351__ -#define __NEW_SWITCHES__ +//#define __NEW_SWITCHES__ #endif #define __PE4302__ //#define __SIMULATION__ @@ -128,6 +128,10 @@ #define MAX_LO_FREQ 4350000000ULL //#define LOW_MAX_FREQ 800000000ULL #define MIN_BELOW_LO 550000000ULL +#ifdef __NEW_SWITCHES__ +#define DIRECT_START 822000000ULL +#define DIRECT_STOP 1130000000ULL +#endif #endif /* * main.c @@ -692,6 +696,9 @@ typedef struct config { int8_t cor_nfm; uint8_t _brightness; uint8_t high_out_adf4350; +#ifdef __ULTRA__ + uint8_t direct; +#endif float sweep_voltage; float switch_offset; int16_t ext_zero_level; diff --git a/sa_core.c b/sa_core.c index 2738694..d34380f 100644 --- a/sa_core.c +++ b/sa_core.c @@ -72,8 +72,8 @@ bool ultra; #ifdef TINYSA4 int noise_level; float log_averaging_correction; -uint32_t old_CFGR; -uint32_t orig_CFGR; +//uint32_t old_CFGR; // Not used?? +//uint32_t orig_CFGR; // Not used?? int debug_frequencies = false; int linear_averaging = true; @@ -2021,10 +2021,7 @@ case M_LOW: // Mixed into 0 #ifdef TINYSA4 ADF4351_enable(true); // ADF4351_drive(setting.lo_drive); - if (setting.tracking_output) - ADF4351_enable_aux_out(true); - else - ADF4351_enable_aux_out(false); + ADF4351_enable_aux_out(setting.tracking_output); ADF4351_enable_out(true); #endif @@ -2110,7 +2107,7 @@ case M_GENLOW: // Mixed output from 0 ADF4351_enable_out(true); // ADF4351_drive(setting.lo_drive); ADF4351_enable(true); - ADF4351_enable_aux_out(false); + ADF4351_enable_aux_out(setting.tracking_output); if (setting.atten_step) { // use switch as attenuator enable_rx_output(false); @@ -2777,6 +2774,11 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / int modulation_index = 0; int modulation_count_iter = 0; int spur_second_pass = false; +#ifdef __NEW_SWITCHES__ + int direct = (setting.mode == M_LOW && config.direct && f > DIRECT_START && f ultra_threshold) { - enable_ultra(true); - } - else - enable_ultra(false); + // -------------- set ultra or direct --------------------------------- + if (setting.mode == M_LOW) { + if (ultra && f > ultra_threshold) { + enable_ultra(true); + } + else { +#ifdef __NEW_SWITCHES__ + if (direct) { + enable_ultra(true); + enable_direct(true); + enable_high(true); + } + else { + enable_ultra(false); + enable_direct(false); + enable_high(false); +#else + enable_ultra(false); #endif - // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ + } + } +#endif + // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ pureRSSI_t RSSI = float_TO_PURE_RSSI(-150); if (debug_avoid){ // For debugging the spur avoidance control stored_t[i] = -90.0; // Display when to do spur shift in the stored trace @@ -3179,6 +3199,9 @@ modulation_again: local_vbw_steps *= 2; } #endif + + // -----------------------------------START vbwsteps loop ------------------------------------ + int t = 0; do { freq_t lf = f; @@ -3208,7 +3231,7 @@ modulation_again: lf += offs; #endif } -// -------------- Calculate the IF ----------------------------- +// -------------- START Calculate the IF ----------------------------- if (/* MODE_INPUT(setting.mode) && */ i > 0 && FREQ_IS_CW()) // In input mode in zero span mode after first setting of the LO's goto skip_LO_setting; // No more LO changes required, save some time and jump over the code @@ -3246,7 +3269,7 @@ again: // Spur redu local_IF = DEFAULT_IF; #endif } - if (setting.mode == M_LOW) { + if (setting.mode == M_LOW && !direct) { if (tracking) { // VERY SPECIAL CASE!!!!! Measure BPF #if 0 // Isolation test local_IF = lf; @@ -3387,7 +3410,7 @@ again: // Spur redu if (setting.modulation == MO_EXTERNAL) // VERY SPECIAL CASE !!!!!! LO input via high port local_IF += lf; } - } + } // --------------- END IF calculation ------------------------ // ------------- Set LO --------------------------- @@ -3396,7 +3419,7 @@ again: // Spur redu #ifdef TINYSA4 int inverted_f = false; #endif - if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF + if (setting.mode == M_LOW && !direct && !setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF #ifdef __ULTRA__ if (lf < local_IF) #endif @@ -3441,9 +3464,12 @@ again: // Spur redu #endif set_freq (SI4432_LO, target_f); // otherwise to above IF #endif + +// ----------------------------- START Calculate and set the AD4351 frequency and set the RX frequency -------------------------------- + #ifdef __ADF4351__ // START_PROFILE; - if (MODE_LOW(setting.mode)) { + if (MODE_LOW(setting.mode) &&!direct) { if (config.frequency_IF2 != 0) { set_freq (ADF4351_LO2, config.frequency_IF2 - local_IF); // Down from IF2 to fixed second IF in Ultra SA mode local_IF = config.frequency_IF2; @@ -3456,9 +3482,9 @@ again: // Spur redu if (setting.R == 0) { if (setting.mode == M_GENLOW) { if (local_modulo == 0) ADF4351_modulo(1000); - ADF4351_R_counter(1); + ADF4351_R_counter(3); } else - if (lf < 1000000000 /* && lf >= TXCO_DIV3 */ && MODE_INPUT(setting.mode)) { + if (lf > 8000000 && lf < 1000000000 /* && lf >= TXCO_DIV3 */ && MODE_INPUT(setting.mode)) { if (local_modulo == 0) { if (actual_rbw_x10 >= 3000) ADF4351_modulo(1000); @@ -3488,7 +3514,7 @@ again: // Spur redu if (setting.frequency_step < 100000) ADF4351_R_counter(3); else - ADF4351_R_counter(1); + ADF4351_R_counter(1); // Used to be 1 } } else { @@ -3541,7 +3567,7 @@ again: // Spur redu } } #endif - } else if (setting.mode == M_HIGH) { + } else if (setting.mode == M_HIGH || direct) { set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode } else if (setting.mode == M_GENHIGH) { if (config.high_out_adf4350) { @@ -3552,9 +3578,11 @@ again: // Spur redu local_IF = 0; } } + // ----------------------------- END Calculate and set the AD4351 frequency and set the RX frequency -------------------------------- + // STOP_PROFILE; #endif - } + } // ----------------- LO's set -------------------------- #ifdef __MCU_CLOCK_SHIFT__ if (setting.mode == M_LOW && !in_selftest) { // Avoid 48MHz spur @@ -3590,7 +3618,7 @@ again: // Spur redu // ----------- Set IF ------------------ - if (local_IF != 0) // When not in one of the high modes + if (local_IF != 0) // When not in one of the high modes and not in direct mode { #ifdef __SI4432__ set_freq (SI4432_RX , local_IF); @@ -3865,10 +3893,10 @@ again: // Spur redu break; // abort } while (t < local_vbw_steps); // till all sub steps done #ifdef TINYSA4 - if (old_CFGR != orig_CFGR) { - old_CFGR = orig_CFGR; - RCC->CFGR = orig_CFGR; - } +// if (old_CFGR != orig_CFGR) { // Never happens ??? +// old_CFGR = orig_CFGR; +// RCC->CFGR = orig_CFGR; + // } #define IGNORE_RSSI 30000 // pureRSSI_t rssi = (RSSI>0 ? RSSI + correct_RSSI + correct_RSSI_freq : IGNORE_RSSI); // add correction pureRSSI_t rssi = RSSI + correct_RSSI + correct_RSSI_freq; // add correction @@ -5060,14 +5088,14 @@ typedef struct test_case { const test_case_t test_case [] = #ifdef TINYSA4 {// Condition Preparation Center Span Pass Width(%)Stop - TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.05, 0.1, 0, 0, 0), // 1 Zero Hz leakage + TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.06, 0.11, -30, 0, -30), // 1 Zero Hz leakage TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 0.1, 0.1, -70, 0, 0), // 2 Phase noise of zero Hz TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ, 30, 1, -23, 10, -85), // 3 TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ_ULTRA, 900, 1, -75, 10, -85), // 4 Test Ultra mode #define TEST_SILENCE 4 TEST_CASE_STRUCT(TC_BELOW, TP_SILENT, 200, 100, -70, 0, 0), // 5 Wide band noise floor low mode TEST_CASE_STRUCT(TC_BELOW, TPH_SILENT, 633, 994, -85, 0, 0), // 6 Wide band noise floor high mode - TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, -23, 27, -70), // 7 BPF loss and stop band + TEST_CASE_STRUCT(TC_SIGNAL, TP_10MHZEXTRA, 30, 14, -23, 27, -45), // 7 BPF loss and stop band TEST_CASE_STRUCT(TC_FLAT, TP_10MHZEXTRA, 30, 14, -18, 9, -60), // 8 BPF pass band flatness TEST_CASE_STRUCT(TC_BELOW, TP_30MHZ, 900, 1, -90, 0, -90), // 9 LPF cutoff TEST_CASE_STRUCT(TC_SIGNAL, TP_30MHZ_SWITCH,30, 7, -23, 10, -50), // 10 Switch isolation using high attenuation diff --git a/si4468.c b/si4468.c index 9221cc7..cd0c2c2 100644 --- a/si4468.c +++ b/si4468.c @@ -75,8 +75,8 @@ #define ADF_SPI_SPEED SPI_BR_DIV2 #define PE4302_HW_SHIFT true -#define PE_SPI_SPEED SPI_BR_DIV2 -#define PE_SW_DELAY 1 +#define PE_SPI_SPEED SPI_BR_DIV8 +#define PE_SW_DELAY 2 static uint32_t old_spi_settings; #else @@ -1832,7 +1832,7 @@ void enable_extra_lna(int s) #ifdef __ULTRA__ void enable_ultra(int s) { -static int old_ultra = -1; +static int old_ultra = 2; if (s != old_ultra) { #ifdef TINYSA4 if (s) @@ -1871,6 +1871,10 @@ void enable_high(int s) #ifdef __NEW_SWITCHES__ void enable_direct(int s) { + static int old_direct = 2; + if (s == old_direct) + return; + old_direct = s; if (s) SI4463_set_gpio(4,SI446X_GPIO_MODE_DRIVE0); else diff --git a/ui_sa.c b/ui_sa.c index a9ca825..66433d1 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1238,6 +1238,21 @@ static UI_FUNCTION_ADV_CALLBACK(menu_ultra_acb) // menu_move_back(false); ui_mode_normal(); } + +static UI_FUNCTION_ADV_CALLBACK(menu_direct_acb) +{ + (void)data; + (void)item; + if (b){ + b->icon = config.direct == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + return; + } + config.direct = !config.direct; + config_save(); + // menu_move_back(false); + ui_mode_normal(); +} + #endif static UI_FUNCTION_CALLBACK(menu_clearconfig_cb) @@ -2621,6 +2636,7 @@ static const menuitem_t menu_settings3[] = { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, { MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"}, + { MT_ADV_CALLBACK, 0, "ENABLE\nDIRECT", menu_direct_acb}, // { MT_KEYPAD | MT_LOW, KM_IF2, "IF2 FREQ", "Set to zero for no IF2"}, { MT_KEYPAD, KM_R, "R", "Set R"}, { MT_KEYPAD, KM_MOD, "MODULO", "Set MODULO"}, @@ -3118,12 +3134,12 @@ static void fetch_numeric_target(uint8_t mode) if (setting.level_sweep != 0) plot_printf(uistat.text, sizeof uistat.text, "%.1f to %.1fdBm", uistat.value, end_level); else - plot_printf(uistat.text, sizeof uistat.text, "%.1fdBm", uistat.value); + plot_printf(uistat.text, sizeof uistat.text, "%+.1fdBm", uistat.value); break; case KM_HIGHOUTLEVEL: uistat.value = get_level(); // compensation for dB offset during low output mode uistat.value += setting.external_gain; - plot_printf(uistat.text, sizeof uistat.text, "%.1fdBm", uistat.value); + plot_printf(uistat.text, sizeof uistat.text, "%+.1fdBm", uistat.value); break; case KM_DECAY: uistat.value = setting.decay;