From 94e620bf0da2c5000f048fb854939683a5de6211 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 11 Oct 2020 08:46:57 +0200 Subject: [PATCH] Add IF2 --- NANOVNA_STM32_F303/board.h | 2 +- nanovna.h | 2 ++ sa_core.c | 52 ++++++++++++++++++++++++-------------- si4432.c | 42 +++++++++++++++--------------- si4432.h | 1 + ui_sa.c | 12 ++++++++- 6 files changed, 70 insertions(+), 41 deletions(-) diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 0811b95..c193e1d 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -354,7 +354,7 @@ PIN_MODE_INPUT(11) | \ PIN_MODE_INPUT(12) | \ PIN_MODE_OUTPUT(GPIOC_LED) | \ - PIN_MODE_INPUT(14) | \ + PIN_MODE_OUTPUT(14) | \ PIN_MODE_OUTPUT(15)) #define VAL_GPIOC_OTYPER (PIN_OTYPE_PUSHPULL(0) | \ PIN_OTYPE_PUSHPULL(1) | \ diff --git a/nanovna.h b/nanovna.h index f157b87..5da66ff 100644 --- a/nanovna.h +++ b/nanovna.h @@ -197,6 +197,7 @@ void SetGenerate(int); void set_RBW(uint32_t rbw_x10); void set_drive(int d); void set_IF(int f); +void set_IF2(int f); void set_step_delay(int t); void set_offset_delay(int t); void set_repeat(int); @@ -471,6 +472,7 @@ typedef struct config { uint16_t ham_color; uint16_t gridlines; uint16_t hambands; + uint32_t frequency_IF2; int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; diff --git a/sa_core.c b/sa_core.c index 19df767..fbdfcba 100644 --- a/sa_core.c +++ b/sa_core.c @@ -381,6 +381,13 @@ void set_IF(int f) dirty = true; } +void set_IF2(int f) +{ + + config.frequency_IF2 = f; + dirty = true; +} + #define POWER_STEP 0 // Should be 5 dB but appearently it is lower #define POWER_OFFSET 15 #define SWITCH_ATTENUATION 30 @@ -1154,18 +1161,20 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency ADF4351_set_frequency(V-2,freq,3); real_old_freq[V] = freq; } - } - if (V==SI4463_RX) { - if (setting.frequency_step<930000) // maximum step size is 937.49kHz - SI4463_set_freq(freq,setting.frequency_step); - else - SI4463_set_freq(freq,1000); - old_frequency_step = setting.frequency_step; - } -#ifdef __ULTRA_SA__ - else { + } else if (V==ADF4351_LO2){ ADF4351_set_frequency(V-2,freq,3); - } + } else + if (V==SI4463_RX) { + if (setting.frequency_step<930000) // maximum step size is 937.49kHz + SI4463_set_freq(freq,setting.frequency_step); + else + SI4463_set_freq(freq,1000); + old_frequency_step = setting.frequency_step; + } +#ifdef __ULTRA_SA__ + else { + ADF4351_set_frequency(V-2,freq,3); + } #endif old_freq[V] = freq; } @@ -1843,10 +1852,10 @@ modulation_again: { // Else set LO ('s) #ifdef __ULTRA_SA__ //#define IF_1 2550000000 -#define IF_2 2025000000 // First IF in Ultra SA mode +#define IF_2 config.frequency_IF2 // First IF in Ultra SA mode - set_freq (2, IF_2 + lf); // Scanning LO up to IF2 - set_freq (3, IF_2 - 433800000); // Down from IF2 to fixed second IF in Ultra SA mode + set_freq (2, config.frequency_IF2 + lf); // Scanning LO up to IF2 + set_freq (3, config.frequency_IF2 - 433800000); // Down from IF2 to fixed second IF in Ultra SA mode set_freq (SI4432_LO, 433800000); // Second IF fixed in Ultra SA mode #else #ifdef __SI4432__ @@ -1858,15 +1867,20 @@ modulation_again: #ifdef __ADF4351__ // START_PROFILE; if (setting.mode == M_LOW) { + uint32_t extra_IF = local_IF; + if (config.frequency_IF2 != 0) { + extra_IF = config.frequency_IF2; + set_freq (ADF4351_LO2, config.frequency_IF2 - local_IF); // Down from IF2 to fixed second IF in Ultra SA mode + } if (!setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF - if (lf > local_IF) - set_freq (ADF4351_LO, lf - local_IF); // set LO SI4432 to below IF frequency + if (lf > extra_IF) + set_freq (ADF4351_LO, lf - extra_IF); // set LO SI4432 to below IF frequency else - set_freq (ADF4351_LO, local_IF-lf); // set LO SI4432 to below IF frequency + set_freq (ADF4351_LO, extra_IF-lf); // set LO SI4432 to below IF frequency } else - set_freq (ADF4351_LO, local_IF+lf); // otherwise to above IF + set_freq (ADF4351_LO, extra_IF+lf); // otherwise to above IF } else if (setting.mode == M_HIGH) { - set_freq (SI4463_RX, local_IF+lf); // sweep RX + set_freq (SI4463_RX, local_IF+lf); // sweep RX, local_IF = 0 in high mode } // STOP_PROFILE; #endif diff --git a/si4432.c b/si4432.c index 98054cd..21be7e8 100644 --- a/si4432.c +++ b/si4432.c @@ -1234,6 +1234,8 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq #define Npresc 0 // No High performance mode +#define MIN_DELAY 1 + #include void SI4463_write_byte(uint8_t ADR, uint8_t DATA) @@ -1244,14 +1246,14 @@ void SI4463_write_byte(uint8_t ADR, uint8_t DATA) // SI4432_guard = 1; // SPI1_CLK_LOW; palClearPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); // my_microsecond_delay(SELECT_DELAY); ADR |= 0x80 ; // RW = 1 shiftOut( ADR ); shiftOut( DATA ); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); palSetPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); // SI4432_guard = 0; } @@ -1263,15 +1265,15 @@ void SI4463_write_buffer(uint8_t ADR, uint8_t *DATA, int len) // SI4432_guard = 1; // SPI1_CLK_LOW; palClearPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); // my_microsecond_delay(SELECT_DELAY); ADR |= 0x80 ; // RW = 1 shiftOut( ADR ); while (len-- > 0) shiftOut( *(DATA++) ); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); palSetPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); // SI4432_guard = 0; } @@ -1286,13 +1288,13 @@ uint8_t SI4463_read_byte( uint8_t ADR ) // SPI1_CLK_LOW; set_SPI_mode(SPI_MODE_SI); palClearPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); shiftOut( ADR ); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); DATA = shiftIn(); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); palSetPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); // SI4432_guard = 0; return DATA ; } @@ -1306,21 +1308,21 @@ uint8_t SI4463_get_response(void* buff, uint8_t len) // SI4432_guard = 1; // SPI1_CLK_LOW; palClearPad(GPIOB, GPIOB_RX_SEL); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); shiftOut( SI446X_CMD_READ_CMD_BUFF ); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); cts = (shiftIn() == 0xFF); - my_microsecond_delay(2); + my_microsecond_delay(MIN_DELAY); if (cts) { // Get response data for(uint8_t i=0;i