diff --git a/main.c b/main.c index 4c4ec03..ee6a760 100644 --- a/main.c +++ b/main.c @@ -1020,14 +1020,17 @@ config_t config = { { 10.5, +3, +1 , -0.1, 0, 0, +1.1, +1.5, +1.8, +9.7, +3.8, +3.5, +4, +8, +10.5, +13, +17.5, +20, +24, +28,}, // lna in #endif #endif - { 11.5, 7, 6, 3.5, 1.5, 0.5, -0.2, 0, 0, -0.5, +1.5, +2, +4, +6.5, +9, +13, +13, +13, +13, +13, }, // low out + { 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // low out +// { 11.5, 7, 6, 3.5, 1.5, 0.5, -0.2, 0, 0, -0.5, +1.5, +2, +4, +6.5, +9, +13, +13, +13, +13, +13, }, // low out }, .setting_frequency_30mhz = 30000000ULL * FREQ_MULTIPLIER, .cor_am = 0, .cor_wfm = 0, .cor_nfm = 0, .ultra = false, +#ifndef __NEW_SWITCHES__ .high_out_adf4350 = true, +#endif .ext_zero_level = 174, .receive_switch_offset = 0.0, #ifdef TINYSA4 diff --git a/nanovna.h b/nanovna.h index f1f1318..e64c66b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -51,6 +51,7 @@ #define __SI4468__ #define __ADF4351__ #define __NEW_SWITCHES__ +#define __ULTRA_OUT__ // Use ADF output over LOW out // #define __SI5351__ #endif #define __PE4302__ @@ -439,8 +440,10 @@ void enable_ultra(int); #endif #ifdef TINYSA4 void clear_frequency_cache(void); +#ifndef __NEW_SWITCHES__ void toggle_high_out_adf4350(void); extern int high_out_adf4350; +#endif void set_30mhz(freq_t); void set_IF2(int f); void set_R(int f); @@ -750,7 +753,9 @@ typedef struct config { int8_t cor_wfm; int8_t cor_nfm; uint8_t _brightness; +#ifndef __NEW_SWITCHES__ uint8_t high_out_adf4350; +#endif uint8_t flip; #ifdef __ULTRA__ uint8_t direct; diff --git a/sa_core.c b/sa_core.c index 26828b3..532e6ec 100644 --- a/sa_core.c +++ b/sa_core.c @@ -117,16 +117,23 @@ int actual_drive = -1; #endif #ifdef TINYSA4 +#ifdef __NEW_SWITCHES__ +#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH) ? 40 : 25.0 + config.out_switch_offset) +#define MAX_DRIVE ((setting.mode == M_GENHIGH) ? 3 : 18) +#define MIN_DRIVE ((setting.mode == M_GENHIGH) ? 0: 0) +#define SL_GENHIGH_LEVEL_MIN (drive_dBm[MIN_DRIVE]) +#else #define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 25.0 + config.out_switch_offset) +#define MAX_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 3 : 18) +#define MIN_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 0: 0) +#define SL_GENHIGH_LEVEL_MIN (drive_dBm[MIN_DRIVE] - (config.high_out_adf4350 ? 0: 37 - config.switch_offset)) +#endif #define RECEIVE_SWITCH_ATTENUATION (29 + config.receive_switch_offset) //#define POWER_OFFSET -18 // Max level with all enabled //#define POWER_RANGE 70 -#define MAX_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 3 : 18) -#define MIN_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 0: 0) //#define SL_GENHIGH_LEVEL_MIN -15 //#define SL_GENHIGH_LEVEL_RANGE 9 -#define SL_GENHIGH_LEVEL_MIN (drive_dBm[MIN_DRIVE] - (config.high_out_adf4350 ? 0: 37 - config.switch_offset)) #define SL_GENHIGH_LEVEL_MAX drive_dBm[MAX_DRIVE] #define SL_GENLOW_LEVEL_MIN -124 @@ -194,7 +201,11 @@ void update_min_max_freq(void) case M_GENLOW: minFreq = 0; #ifdef TINYSA4 +#ifdef __ULTRA_OUT__ + maxFreq = MAX_LO_FREQ; +#else maxFreq = MAX_LOW_OUTPUT_FREQ; +#endif #else maxFreq = DEFAULT_MAX_FREQ; #endif @@ -220,12 +231,15 @@ void update_min_max_freq(void) break; case M_GENHIGH: #ifdef TINYSA4 - if (config.high_out_adf4350) { - minFreq = 136000000; - maxFreq = MAX_LO_FREQ; - } else { +#ifndef __NEW_SWITCHES__ + if (!config.high_out_adf4350) { minFreq = 136000000; maxFreq = 1150000000U; + } else +#endif + { + minFreq = 136000000; + maxFreq = MAX_LO_FREQ; } #else minFreq = 240000000; @@ -248,7 +262,9 @@ void reset_settings(int m) ultra = config.ultra; #endif #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ drive_dBm = (float *) (setting.mode == M_GENHIGH && config.high_out_adf4350 ? adf_drive_dBm : si_drive_dBm); +#endif setting.exp_aver = 1; setting.increased_R = false; #endif @@ -642,6 +658,7 @@ void toggle_debug_spur(void) #endif #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ void toggle_high_out_adf4350(void) { config.high_out_adf4350 = !config.high_out_adf4350; @@ -649,6 +666,7 @@ void toggle_high_out_adf4350(void) config_save(); dirty = true; } +#endif void toggle_extra_lna(void) { @@ -887,6 +905,7 @@ void correct_high_output_level(void) { float a = setting.level - level_max(); #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ if (!config.high_out_adf4350) { float dt = Si446x_get_temp() - CENTER_TEMPERATURE; if (dt > 0) @@ -894,6 +913,7 @@ void correct_high_output_level(void) else a += dt * DB_PER_DEGREE_BELOW; // Temperature correction } +#endif #endif if (a <= -SWITCH_ATTENUATION) { setting.atten_step = true; @@ -2298,7 +2318,9 @@ case M_GENHIGH: // Direct output from 1 SI4432_Transmit(setting.lo_drive); #endif #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ if (config.high_out_adf4350) { +#endif #ifdef __SI4468__ SI4463_init_rx(); enable_rx_output(true); // to protect the SI @@ -2314,6 +2336,7 @@ case M_GENHIGH: // Direct output from 1 ADF4351_aux_drive(setting.lo_drive); enable_extra_lna(false); enable_ultra(true); // Open low output +#ifndef __NEW_SWITCHES__ } else { ADF4351_enable_aux_out(false); ADF4351_enable_out(false); @@ -2328,6 +2351,7 @@ case M_GENHIGH: // Direct output from 1 #endif } +#endif #endif break; } @@ -3152,7 +3176,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / else if (ls < 0) ls -= 0.5; float a = ((int)((setting.level + ((float)i / sweep_points) * ls)*2.0)) / 2.0 /* + get_level_offset() */ ; - correct_RSSI_freq = get_frequency_correction(f); // No direct in output + correct_RSSI_freq = get_frequency_correction(f); a += PURE_TO_float(correct_RSSI_freq); #ifdef TINYSA4 { @@ -3257,6 +3281,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / { float a = setting.level - level_max(); #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ if (!config.high_out_adf4350) { float dt = Si446x_get_temp() - CENTER_TEMPERATURE; if (dt > 0) @@ -3264,6 +3289,7 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / else a += dt * DB_PER_DEGREE_BELOW; // Temperature correction } +#endif #endif if (a <= -SWITCH_ATTENUATION) { setting.atten_step = true; @@ -3272,10 +3298,12 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / SI4432_Sel = SI4432_LO ; set_switch_receive(); #else - if (config.high_out_adf4350) - ADF4351_enable_aux_out(false); - else +#ifndef __NEW_SWITCHES__ + if (!config.high_out_adf4350) enable_rx_output(false); + else +#endif + ADF4351_enable_aux_out(false); #endif } else { setting.atten_step = false; @@ -3283,10 +3311,12 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / SI4432_Sel = SI4432_LO ; set_switch_transmit(); #else - if (config.high_out_adf4350) - ADF4351_enable_aux_out(true); - else +#ifndef __NEW_SWITCHES__ + if (!config.high_out_adf4350) enable_rx_output(true); + else +#endif + ADF4351_enable_aux_out(true); #endif } @@ -3302,10 +3332,12 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / SI4432_Drive(d); #endif #ifdef TINYSA4 +#ifndef __NEW_SWITCHES__ if (config.high_out_adf4350) - ADF4351_aux_drive(d); - else SI4463_set_output_level(d); + else +#endif + ADF4351_aux_drive(d); #endif } } @@ -3392,10 +3424,35 @@ modulation_again: if (setting.mode == M_LOW || setting.mode == M_GENLOW) { #ifdef __NEW_SWITCHES__ if (direct) { +#ifdef __ULTRA_OUT__ + if (f > MAX_LOW_OUTPUT_FREQ) { +// SI4463_init_rx(); + ADF4351_enable_aux_out(true); + ADF4351_enable_out(true); + ADF4351_enable(true); + enable_ADF_output(true); + + enable_direct(false); + enable_ultra(true); + enable_high(false); + } else { + + ADF4351_enable_aux_out(false); + ADF4351_enable_out(false); + ADF4351_enable(false); + enable_ADF_output(false); + +// SI4463_init_tx(); + enable_ultra(true); + enable_direct(true); + enable_high(true); + } +#else enable_ultra(true); enable_direct(true); enable_high(true); enable_ADF_output(false); +#endif } else #endif { @@ -3527,10 +3584,10 @@ again: // Spur redu #endif #ifdef __ULTRA__ if (S_IS_AUTO(setting.below_IF)) { - if ((freq_t)lf > MAX_ABOVE_IF_FREQ /* && lf <= ULTRA_MAX_FREQ */ ) - setting.below_IF = S_AUTO_ON; // Only way to reach this range. + if ((freq_t)lf > MAX_ABOVE_IF_FREQ && lf <= ULTRA_MAX_FREQ ) + setting.below_IF = S_AUTO_ON; // Only way to reach this range. Use below IF in harmonic mode else - setting.below_IF = S_AUTO_OFF; // default is above IF + setting.below_IF = S_AUTO_OFF; // default is above IF, Use below IF in harmonic mode } #endif if (S_STATE(setting.spur_removal)){ // If in low input mode and spur reduction is on @@ -3893,16 +3950,21 @@ again: // Spur redu } #endif } else if (setting.mode == M_HIGH || direct) { - set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode +#ifdef __ULTRA_OUT__ + if (f > MAX_LOW_OUTPUT_FREQ) + set_freq (ADF4351_LO, lf); // sweep LO, local_IF = 0 in high mode + else +#endif + set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode local_IF = 0; } else if (setting.mode == M_GENHIGH) { - if (config.high_out_adf4350) { - set_freq (ADF4351_LO, lf); // sweep LO, local_IF = 0 in high mode - local_IF = 0; - } else { + local_IF = 0; +#ifndef __NEW_SWITCHES__ + if (!config.high_out_adf4350) set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode - local_IF = 0; - } + else +#endif + set_freq (ADF4351_LO, lf); // sweep LO, local_IF = 0 in high mode } // ----------------------------- END Calculate and set the AD4351 frequency and set the RX frequency -------------------------------- @@ -5562,7 +5624,7 @@ const test_case_t test_case [] = #define TEST_NOISE_RBW 28 TEST_CASE_STRUCT(TC_MEASURE, TP_SILENT, 201, 1, -166, 10, -166), // 16 Measure RBW step time #define TEST_JUMP 29 - TEST_CASE_STRUCT(TC_JUMP, TP_30MHZ_LNA, 30, 0.001, -40, 0, -80), // 16 Measure jumps + TEST_CASE_STRUCT(TC_JUMP, TP_30MHZ_LNA, 30, 0.001, -40, 0, CAL_LEVEL), // 16 Measure jumps }; #else {// Condition Preparation Center Span Pass Width(%)Stop diff --git a/si4468.c b/si4468.c index a844f2d..f9eb9d4 100644 --- a/si4468.c +++ b/si4468.c @@ -622,6 +622,10 @@ uint64_t ADF4351_prepare_frequency(int channel, uint64_t freq) // freq / 10Hz void ADF4351_enable(int s) { + static int old_s = -1; + if (s == old_s) + return; + old_s = s; if (s) bitClear(registers[4], 11); // Inverse logic!!!!! else @@ -631,6 +635,10 @@ void ADF4351_enable(int s) void ADF4351_enable_aux_out(int s) { + static int old_s = -1; + if (s == old_s) + return; + old_s = s; if (s) bitSet(registers[4], 8); else @@ -640,6 +648,10 @@ void ADF4351_enable_aux_out(int s) void ADF4351_enable_out(int s) { + static int old_s = -1; + if (s == old_s) + return; + old_s = s; if (s) { bitClear(registers[4], 11); // Disable VCO power down bitClear(registers[2], 5); // Disable power down diff --git a/ui_sa.c b/ui_sa.c index 77fb31e..4cd457a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1205,7 +1205,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) // menu_move_back(false); ui_mode_normal(); } - +#ifndef __NEW_SWITCHES__ static UI_FUNCTION_ADV_CALLBACK(menu_adf_out_acb) { (void)data; @@ -1218,6 +1218,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_adf_out_acb) // menu_move_back(false); ui_mode_normal(); } +#endif #ifdef __WAIT_CTS_WHILE_SLEEPING__ volatile int sleep = 0; @@ -2735,7 +2736,9 @@ static const menuitem_t menu_settings3[] = { #ifdef TINYSA4 // { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, +#ifndef __NEW_SWITCHES__ { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, +#endif { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, { MT_KEYPAD, KM_ULTRA_START,"ULTRASTART\n\b%s", "10G=auto"}, { MT_ADV_CALLBACK, 0, "ENABLE\nDIRECT", menu_direct_acb},