From 77da3dd626529642cb9d2c6ce36c3c1470fc810f Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 29 Nov 2020 08:54:08 +0100 Subject: [PATCH 1/2] Cleanup --- sa_core.c | 40 +++------------------------------------- si4432.h | 11 ++++++----- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/sa_core.c b/sa_core.c index dcbf097..bc43278 100644 --- a/sa_core.c +++ b/sa_core.c @@ -225,9 +225,7 @@ uint32_t calc_min_sweep_time_us(void) // Estimate minimum sweep time in void set_refer_output(int v) { setting.refer = v; -#ifdef __SI4432__ set_calibration_freq(setting.refer); -#endif // dirty = true; } @@ -1070,7 +1068,7 @@ void setupSA(void) #ifdef __SI4432__ SI4432_Init(); #endif - for (int i = 0; i < sizeof(old_freq)/sizeof(unsigned long) ; i++) { + for (unsigned int i = 0; i < sizeof(old_freq)/sizeof(unsigned long) ; i++) { old_freq[i] = 0; real_old_freq[i] = 0; } @@ -1327,8 +1325,8 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# if (setting.spur_removal && 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_x10 = set_rbw(actual_rbw_x10); // see what rbw the SI4432 can realize #endif + actual_rbw_x10 = 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_x10 + (actual_rbw_x10/2)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step if (setting.step_delay_mode==SD_PRECISE) // if in Precise scanning @@ -1482,36 +1480,6 @@ static const int spur_table[] = // Frequencies t 40960000, 41600000, 49650000, -#ifdef IF_AT_4339 - 780000, // 433.9MHz table - 830000, - 880000, - 949000, - 1390000, - 1468000, - 1830000, - 1900000, - 2770000, - 2840000, - 2880000, - 4710000, - 4780000, - 4800000, - 4880000, - 6510000, - 6750000, - 6790000, - 6860000, - 7340000, - 8100000, - 8200000, - 8880000, -// 9970000, 10MHz!!!!!! - 10870000, - 11420000, - 14880000, - 16820000, -#endif }; int binary_search(int f) @@ -1779,9 +1747,7 @@ modulation_again: local_IF = setting.frequency_IF; } if (setting.mode == M_LOW && tracking) { // VERY SPECIAL CASE!!!!! Measure BPF -#ifdef __SI4432__ set_freq (SI4432_RX , local_IF + lf - reffer_freq[setting.refer]); // Offset so fundamental of reffer is visible -#endif } else if (MODE_LOW(setting.mode)) { if (setting.mode == M_LOW && !in_selftest && avoid_spur(lf)) { // check if alternate IF is needed to avoid spur. local_IF = spur_alternate_IF; @@ -3659,7 +3625,7 @@ void self_test(int test) #endif setting.step_delay = setting.step_delay * 5 / 4; setting.offset_delay = setting.step_delay / 2; - setting.rbw_x10 = force_RBW(j); + setting.rbw_x10 = force_rbw(j); shell_printf("RBW = %f, ",setting.rbw_x10/10.0); #if 0 diff --git a/si4432.h b/si4432.h index 1247ce3..43a2784 100644 --- a/si4432.h +++ b/si4432.h @@ -22,6 +22,8 @@ #define __SI4432_H__ +extern int SI4432_step_delay; +extern int SI4432_offset_delay; #ifdef __SI4432__ // @@ -108,8 +110,7 @@ extern volatile int SI4432_Sel; // currently selected SI4432 -extern int SI4432_step_delay; -extern int SI4432_offset_delay; + extern int SI4432_frequency_changed; extern int SI4432_offset_changed; @@ -147,15 +148,15 @@ int SI4432_is_fast_mode(void); bool PE4302_Write_Byte(unsigned char DATA ); void PE4302_init(void); -#ifdef __ULTRA_SA__ +#ifdef __ADF4351__ extern int ADF4351_LE[]; extern int debug; void ADF4351_Setup(void); void ADF4351_WriteRegister32(int channel, const uint32_t value); -void ADF4351_set_frequency(int channel, uint32_t freq, int drive_strength); -void ADF4351_prep_frequency(int channel, uint32_t freq, int drive_strength); +uint32_t ADF4351_set_frequency(int channel, uint32_t freq, int drive_strength); +uint32_t ADF4351_prep_frequency(int channel, uint32_t freq, int drive_strength); //int ADF4351_set_frequency_with_offset(uint32_t freq, int offset, uint8_t drive_strength); void ADF4351_Set(int channel); void ADF4351_enable_output(void); From 6f87211a66c26a11d7724932586f3851627ec4e2 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 29 Nov 2020 10:34:48 +0100 Subject: [PATCH 2/2] Remove __ULTRA_SA__ --- main.c | 5 +---- nanovna.h | 1 - sa_cmd.c | 2 +- sa_core.c | 16 ---------------- si4432.c | 2 +- ui.c | 9 --------- 6 files changed, 3 insertions(+), 32 deletions(-) diff --git a/main.c b/main.c index 5c25803..36c6d47 100644 --- a/main.c +++ b/main.c @@ -2426,7 +2426,7 @@ static const VNAShellCommand commands[] = #ifdef TINYSA4 { "g", cmd_g, CMD_WAIT_MUTEX }, #endif -#ifdef __ULTRA_SA__ +#ifdef __ADF4351__ { "x", cmd_x, 0 }, #endif {NULL , NULL , 0} @@ -2824,9 +2824,6 @@ int main(void) } #endif -#ifdef __ULTRA_SA__ - ADF4351_Setup(); -#endif /* * SPI LCD Initialize */ diff --git a/nanovna.h b/nanovna.h index 1ce5c79..184317b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -47,7 +47,6 @@ #define __FAST_SWEEP__ // Pre-fill SI4432 RSSI buffer to get fastest sweep in zero span mode #define __HAM_BAND__ //#define __ULTRA__ // Add harmonics mode on low input. -//#define __ULTRA_SA__ // Adds ADF4351 control for extra high 1st IF stage #define __SPUR__ // Does spur reduction by shifting IF //#define __USE_SERIAL_CONSOLE__ // Enable serial I/O connection (need enable HAL_USE_SERIAL as TRUE in halconf.h) #ifdef TINYSA3 diff --git a/sa_cmd.c b/sa_cmd.c index 639af24..6769642 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -384,7 +384,7 @@ VNA_SHELL_FUNCTION(cmd_selftest) sweep_mode = SWEEP_SELFTEST; } -#ifdef __ULTRA_SA__ +#ifdef __ADF4351__ VNA_SHELL_FUNCTION(cmd_x) { uint32_t reg; diff --git a/sa_core.c b/sa_core.c index bc43278..07542b2 100644 --- a/sa_core.c +++ b/sa_core.c @@ -80,13 +80,8 @@ void update_min_max_freq(void) maxFreq = DEFAULT_MAX_FREQ; break; case M_HIGH: -#ifdef __ULTRA_SA__ - minFreq = 00000000; - maxFreq = 2000000000; -#else minFreq = HIGH_MIN_FREQ_MHZ * 1000000; maxFreq = HIGH_MAX_FREQ_MHZ * 1000000; -#endif break; case M_GENHIGH: minFreq = 240000000; @@ -1170,11 +1165,6 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } #endif } -#ifdef __ULTRA_SA__ - else { - ADF4351_set_frequency(V-2,freq,3); - } -#endif old_freq[V] = freq; } @@ -1813,17 +1803,11 @@ modulation_again: } else #endif { // Else set LO ('s) -#ifdef __ULTRA_SA__ - set_freq (2, config.frequency_IF2 + lf); // Scanning LO up to IF2 - set_freq (3, config.frequency_IF2 - DEFAULT_IF); // Down from IF2 to fixed second IF in Ultra SA mode - set_freq (SI4432_LO, DEFAULT_IF); // Second IF fixed in Ultra SA mode -#else #ifdef __SI4432__ if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) // if in low input mode and below IF set_freq (SI4432_LO, local_IF-lf); // set LO SI4432 to below IF frequency else set_freq (SI4432_LO, local_IF+lf); // otherwise to above IF -#endif #endif } diff --git a/si4432.c b/si4432.c index 95831b0..416e48e 100644 --- a/si4432.c +++ b/si4432.c @@ -779,7 +779,7 @@ float Simulated_SI4432_RSSI(uint32_t i, int s) #endif //------------------------------- ADF4351 ------------------------------------- -#ifdef __ULTRA_SA__ +#ifdef __ADF4351__ #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) diff --git a/ui.c b/ui.c index b46f0b9..ccb95fa 100644 --- a/ui.c +++ b/ui.c @@ -55,11 +55,7 @@ uistat_t uistat = { #define BIT_DOWN1 1 #define READ_PORT() palReadPort(GPIOA) -#ifdef __ULTRA_SA__ -#define BUTTON_MASK 0 -#else #define BUTTON_MASK 0b1110 -#endif static uint16_t last_button = 0b0000; static uint32_t last_button_down_ticks; @@ -2669,13 +2665,8 @@ static void extcb1(EXTDriver *extp, expchannel_t channel) static const EXTConfig extcfg = { { {EXT_CH_MODE_DISABLED, NULL}, -#ifdef __ULTRA_SA__ - {EXT_CH_MODE_DISABLED, NULL}, - {EXT_CH_MODE_DISABLED, NULL}, -#else {EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1}, {EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1}, -#endif {EXT_CH_MODE_RISING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, extcb1}, {EXT_CH_MODE_DISABLED, NULL}, {EXT_CH_MODE_DISABLED, NULL},