From 83a6a820533ff0e7f347e9f53e7390bbd29a3fc6 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 14 Nov 2020 16:32:20 +0100 Subject: [PATCH] Frequency setting corrected --- radio_config_Si4468_short.h | 7 +++++ sa_core.c | 57 ++++++++++++++++++++----------------- si4432.c | 55 +++++++++++++++++++++-------------- si4432.h | 4 +-- 4 files changed, 74 insertions(+), 49 deletions(-) diff --git a/radio_config_Si4468_short.h b/radio_config_Si4468_short.h index 08605b2..f95384e 100644 --- a/radio_config_Si4468_short.h +++ b/radio_config_Si4468_short.h @@ -6,6 +6,13 @@ #undef RF_MODEM_AGC_CONTROL_1 #define RF_MODEM_AGC_CONTROL_1 0x11, 0x20, 0x01, 0x35, 0xF1 // Override AGC gain increase +#undef RF_GPIO_PIN_CFG +#define RF_GPIO_PIN_CFG GLOBAL_GPIO_PIN_CFG + +#undef RF_GLOBAL_CLK_CFG_1 +#define RF_GLOBAL_CLK_CFG_1 GLOBAL_CLK_CFG + + #undef RADIO_CONFIGURATION_DATA_ARRAY #define RADIO_CONFIGURATION_DATA_ARRAY { \ 0x10, RF_MODEM_MOD_TYPE_12_1, \ diff --git a/sa_core.c b/sa_core.c index 0e0d8a9..29e84f6 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1200,17 +1200,16 @@ void set_freq(int V, unsigned long freq) // translate the requested frequency } } if (freq) { - ADF4351_set_frequency(V-ADF4351_LO,freq,setting.drive-12); - real_old_freq[V] = freq; + real_old_freq[V] = ADF4351_set_frequency(V-ADF4351_LO,freq,setting.drive-12); } } else if (V==ADF4351_LO2){ - ADF4351_set_frequency(V-ADF4351_LO,freq,setting.drive-12); + real_old_freq[V] = ADF4351_set_frequency(V-ADF4351_LO,freq,setting.drive-12); } 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); + SI4463_set_freq(freq,100); old_frequency_step = setting.frequency_step; } #ifdef __ULTRA_SA__ @@ -1501,7 +1500,7 @@ static const int spur_table[] = // Frequencies t { 117716000, 746083000, - 1956000000, +// 1956000000, #if 0 // 580000, // 433.8 MHz table // 880000, //? @@ -1882,10 +1881,10 @@ modulation_again: } #endif #ifdef __SI4463__ - if ((setting.mode == M_LOW || setting.mode == M_GENLOW ) && i == 0) - { - set_freq (SI4463_RX , local_IF); - } +// if ((setting.mode == M_LOW || setting.mode == M_GENLOW ) && i == 0) +// { +// set_freq (SI4463_RX , local_IF); +// } #endif #ifdef __ULTRA__ } else if (setting.mode == M_ULTRA) { // No above/below IF mode in Ultra @@ -1939,25 +1938,31 @@ modulation_again: #ifdef __ADF4351__ // START_PROFILE; if (setting.mode == M_LOW) { - if (i > 0 && setting.frequency_step < 2000) { - if (S_STATE(setting.below_IF)) - set_freq (SI4463_RX, setting.frequency_IF + setting.frequency_step*i); // sweep RX, local_IF = 0 in high mode + 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; + } + uint32_t target_f; + if (!setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF + if (lf > local_IF + 138000000) + target_f = lf - local_IF; // set LO SI4432 to below IF frequency else - set_freq (SI4463_RX, setting.frequency_IF - setting.frequency_step*i); // sweep RX, local_IF = 0 in high mode - } else { - 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 > extra_IF + 138000000) - set_freq (ADF4351_LO, lf - extra_IF); // set LO SI4432 to below IF frequency - else - set_freq (ADF4351_LO, extra_IF-lf); // set LO SI4432 to below IF frequency - } else - set_freq (ADF4351_LO, extra_IF+lf); // otherwise to above IF + target_f = local_IF-lf; // set LO SI4432 to below IF frequency + } else + target_f = local_IF+lf; // otherwise to above IF + set_freq(ADF4351_LO, target_f); + int32_t error_f = 0; + if (real_old_freq[ADF4351_LO] > target_f) { + error_f = real_old_freq[ADF4351_LO] - target_f; + if (error_f > actual_rbw_x10 * 100) + local_IF += error_f; + } + if (target_f > real_old_freq[ADF4351_LO]) { + error_f = - (target_f - real_old_freq[ADF4351_LO]); + if ( error_f < - actual_rbw_x10 * 100) + local_IF += error_f; } + set_freq (SI4463_RX, local_IF); // compensate ADF error with SI446x } else if (setting.mode == M_HIGH) { set_freq (SI4463_RX, lf); // sweep RX, local_IF = 0 in high mode } diff --git a/si4432.c b/si4432.c index b5ebcf6..2f03655 100644 --- a/si4432.c +++ b/si4432.c @@ -906,14 +906,10 @@ int ADF4351_frequency_changed = false; #define DEBUGLN(X) +#define XTAL 26.0 double RFout, //Output freq in MHz -#if 1 //Black modules - PFDRFout[6] = {50.0,50.0,50.0,10.0,10.0,10.0}, //Reference freq in MHz - Chrystal[6] = {50.0,50.0,50.0,10.0,10.0,10.0}, -#else // Green modules - PFDRFout[6] = {10.0,10.0,10.0,10.0,10.0,10.0}, //Reference freq in MHz - Chrystal[6] = {10.0,10.0,10.0,10.0,10.0,10.0}, -#endif + PFDRFout[6] = {XTAL,XTAL,XTAL,10.0,10.0,10.0}, //Reference freq in MHz + Chrystal[6] = {XTAL,XTAL,XTAL,10.0,10.0,10.0}, OutputChannelSpacing = 0.001, // = 0.01 FRACF; // Temp @@ -945,7 +941,7 @@ void ADF4351_Setup(void) // while(1) { // - ADF4351_R_counter(8); + ADF4351_R_counter(2); ADF4351_set_frequency(0,2000000000,0); @@ -1002,17 +998,18 @@ void ADF4351_enable_output(void) ADF4351_Set(0); } -void ADF4351_set_frequency(int channel, uint32_t freq, int drive) // freq / 10Hz +uint32_t ADF4351_set_frequency(int channel, uint32_t freq, int drive) // freq / 10Hz { // freq -= 71000; - uint32_t offs = ((freq / 1000)* ( 0) )/ 1000; -// uint32_t offs = 0; - ADF4351_prep_frequency(channel,freq + offs, drive); +// uint32_t offs = ((freq / 1000)* ( 0) )/ 1000; + uint32_t offs = 0; + uint32_t actual_freq = ADF4351_prep_frequency(channel,freq + offs, drive); //START_PROFILE; - ADF4351_Set(channel); ADF4351_frequency_changed = true; + ADF4351_Set(channel); //STOP_PROFILE; + return actual_freq; } void ADF4351_spur_mode(int S) @@ -1077,7 +1074,7 @@ static uint32_t gcd(uint32_t x, uint32_t y) return x; } -void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq / 10Hz +uint32_t ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq / 10Hz { // START_PROFILE; // if (channel == 0) @@ -1125,8 +1122,8 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq } INTA = (RFout * OutputDivider) / PFDRFout[channel]; - MOD = (PFDRFout[channel] / OutputChannelSpacing) + 0.01; -// MOD = 3125; +// MOD = (PFDRFout[channel] / OutputChannelSpacing) + 0.01; + MOD = 3125; FRACF = (((RFout * OutputDivider) / PFDRFout[channel]) - INTA) * MOD; FRAC = round(FRACF); @@ -1135,13 +1132,14 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq MOD = MOD >> 1; // Serial.println( "MOD/FRAC reduced"); } - +#if 0 // Don't reduce for now <----------------------------------------------------- int32_t k = gcd(FRAC, MOD); if (k > 1) { FRAC /= k; MOD /= k; // Serial.print( "MOD/FRAC gcd reduced"); } +#endif // while (denom >= (1<<20)) { // num >>= 1; // denom >>= 1; @@ -1172,6 +1170,7 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq // DEBUG(" FRACF="); // DEBUGF(FRACF,6); } + uint32_t actual_freq = 1000000 * PFDRFout[channel] *(INTA + ((double)FRAC)/MOD)/OutputDivider; registers[0] = 0; registers[0] = INTA << 15; // OK FRAC = FRAC << 3; @@ -1225,6 +1224,7 @@ void ADF4351_prep_frequency(int channel, unsigned long freq, int drive) // freq // bitSet (registers[4], 10); // Mute till lock // ADF4351_Set(channel); // STOP_PROFILE; + return actual_freq; } #endif @@ -1438,6 +1438,9 @@ static const uint8_t SI4463_config[] = RADIO_CONFIGURATION_DATA_ARRAY; #undef RADIO_CONFIGURATION_DATA_ARRAY #include "radio_config_Si4468_default.h" +#define GLOBAL_GPIO_PIN_CFG 0x13, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 +#define GLOBAL_CLK_CFG 0x11, 0x00, 0x01, 0x01, 0x00 + //#undef RF_MODEM_RAW_CONTROL_10 // Override RSSI averaging //#define RF_MODEM_RAW_CONTROL_10 0x11, 0x20, 0x0A, 0x45, 0x03, 0x00, 0x00, 0x01, 0x00, 0xFF, 0x06, 0x18, 0x10, 0x40 @@ -1447,6 +1450,11 @@ static const uint8_t SI4463_config[] = RADIO_CONFIGURATION_DATA_ARRAY; //#undef RF_MODEM_RSSI_JUMP_THRESH_4 //#define RF_MODEM_RSSI_JUMP_THRESH_4 0x11, 0x20, 0x04, 0x4B, 0x06, 0x09, 0x10, 0x45 // Increase RSSI reported value with 2.5dB +#undef RF_GPIO_PIN_CFG +#define RF_GPIO_PIN_CFG GLOBAL_GPIO_PIN_CFG +#undef RF_GLOBAL_CLK_CFG_1 +#define RF_GLOBAL_CLK_CFG_1 GLOBAL_CLK_CFG + static const uint8_t SI4468_config[] = RADIO_CONFIGURATION_DATA_ARRAY; #endif @@ -1507,9 +1515,13 @@ void SI4463_clear_int_status() void Si4463_set_refer(int ref) { + + ref = 0; // <--------------------- DISABLED FOR PROTOTYPE!!!!!!!!!!!!!!!!!!!!!!!!! + + if (ref >= 0) { uint8_t data[8] = { - 0x13, 0x08, 0x08, 0x07, 0x12, 0x00, 0x00, 0x00 // GPIO_PIN_CFG GPIO 0 input ,1 CTS, clock div out + 0x13, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 // GPIO_PIN_CFG GPIO 0 input ,1 CTS, clock div out }; SI4463_do_api(data, 8, NULL, 0); @@ -2046,7 +2058,8 @@ static int prev_band = -1; void SI4463_set_freq(uint32_t freq, uint32_t step_size) { - uint32_t offs = ((freq / 1000)* 147) / 1000; +// uint32_t offs = ((freq / 1000)* 147) / 1000; + uint32_t offs = 0; float RFout=(freq+offs)/1000000.0; // To MHz if (RFout >= 822 && RFout <= 1140) { // till 1140MHz SI4463_band = 0; @@ -2078,13 +2091,13 @@ void SI4463_set_freq(uint32_t freq, uint32_t step_size) if (freq < SI4463_prev_freq || freq > SI4463_prev_freq + 255 * SI4463_step_size ) { - SI4463_channel = 128; + SI4463_channel = 0; // 128 <--------------------------BUG!!!!!!!!!!!!!!!!!!!!!!!!!! SI4463_prev_freq = freq - SI4463_channel * SI4463_step_size; RFout -= SI4463_channel * SI4463_step_size / 1000000.0; // shift for channel 128 int32_t R = (RFout * SI4463_outdiv) / (Npresc ? 2*freq_xco : 4*freq_xco) - 1; // R between 0x00 and 0x7f (127) - float MOD = 520251.0; + float MOD = 524288.0; int32_t F = (((RFout * SI4463_outdiv) / (Npresc ? 2*freq_xco : 4*freq_xco)) - R) * MOD; setState(SI446X_STATE_READY); diff --git a/si4432.h b/si4432.h index 7c91004..aada356 100644 --- a/si4432.h +++ b/si4432.h @@ -159,8 +159,8 @@ 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);