From 922e60814d0a4ec8021b83ff6a18527d24c79abe Mon Sep 17 00:00:00 2001 From: Mikael Nousiainen Date: Thu, 14 Sep 2023 10:19:13 +0300 Subject: [PATCH] Fix bug when setting Si4063 frequency. Remove unnecessary GPS debug and delays. Add Si4063 debug printout. Find a suitable frequency offset multiplier to achieve 270 Hz tone spacing for Horus 4FSK. --- src/drivers/si4063/si4063.c | 12 ++++++++++++ src/log.h | 2 +- src/main.c | 6 ------ src/radio_si4063.c | 5 +++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/drivers/si4063/si4063.c b/src/drivers/si4063/si4063.c index c0abc2d..fb396a9 100644 --- a/src/drivers/si4063/si4063.c +++ b/src/drivers/si4063/si4063.c @@ -146,16 +146,20 @@ static void si4603_set_shutdown(bool active) static void si4063_set_state(uint8_t state) { + log_info("Si4063: Set state %02x\n", state); si4063_send_command(SI4063_COMMAND_CHANGE_STATE, 1, &state); } void si4063_enable_tx() { + log_info("Si4063: Enable TX\n"); si4063_set_state(SI4063_STATE_TX); + log_info("Si4063: After enable TX\n"); } void si4063_inhibit_tx() { + log_info("Si4063: Inhibit TX\n"); si4063_set_state(SI4063_STATE_READY); } @@ -180,6 +184,8 @@ void si4063_set_tx_frequency(const uint32_t frequency_hz) uint32_t f_pfd, n, m; float ratio, rest; + log_info("Si4063: Set frequency %lu\n", frequency_hz); + /* Set the output divider according to the recommended ranges in the si406x datasheet */ if (frequency_hz < 177000000UL) { outdiv = 24; @@ -248,6 +254,8 @@ void si4063_set_tx_power(uint8_t power) power & 0x7F // Power level from 00..7F }; + log_info("Si4063: Set TX power %02x\n", power); + si4063_send_command(SI4063_COMMAND_SET_PROPERTY, sizeof(data), data); } @@ -275,6 +283,8 @@ void si4063_set_frequency_deviation(uint32_t deviation) deviation & 0xFF }; + log_info("Si4063: Set freq deviation %lu\n", deviation); + si4063_send_command(SI4063_COMMAND_SET_PROPERTY, sizeof(data), data); } @@ -289,6 +299,8 @@ void si4063_set_modulation_type(si4063_modulation_type type) 0x08 // 0x08 = Direct modulation source (MCU-controlled) }; + log_info("Si4063: Set modulation type %d\n", type); + switch (type) { case SI4063_MODULATION_TYPE_CW: // Pure carrier wave modulation (for modulating via frequency offset, e.g. for RTTY) diff --git a/src/log.h b/src/log.h index b05e1fd..ff4bc20 100644 --- a/src/log.h +++ b/src/log.h @@ -10,7 +10,7 @@ #define log_error printf #define log_warn printf #define log_info printf -#define log_debug printf +#define log_debug(...) #define log_trace(...) #else diff --git a/src/main.c b/src/main.c index 6bb7e4d..b1c2ae7 100644 --- a/src/main.c +++ b/src/main.c @@ -177,12 +177,6 @@ int main(void) radio_handle_main_loop(); //NVIC_SystemLPConfig(NVIC_LP_SEVONPEND, DISABLE); //__WFI(); -#ifdef DFM17 -//DFM17 testing... delete next two lines eventually - log_info("Fix: %d, Time: %02d:%02d:%02d.\n", (int) current_gps_data.fix_ok, current_gps_data.hours, current_gps_data.minutes, current_gps_data.seconds); - delay_ms(1000); -#endif //DFM17 - } } diff --git a/src/radio_si4063.c b/src/radio_si4063.c index e4d4f39..0b9ae83 100644 --- a/src/radio_si4063.c +++ b/src/radio_si4063.c @@ -59,7 +59,7 @@ bool radio_start_transmit_si4063(radio_transmit_entry *entry, radio_module_state return false; } - si4063_set_tx_frequency(((float) entry->frequency) / 1000000.0f); + si4063_set_tx_frequency(entry->frequency); si4063_set_tx_power(entry->tx_power); si4063_set_frequency_offset(frequency_offset); si4063_set_modulation_type(modulation_type); @@ -234,7 +234,8 @@ inline void radio_handle_data_timer_si4063() break; } - si4063_set_frequency_offset(tone_index + HORUS_FREQUENCY_OFFSET_SI4063); + // NOTE: The factor of 23 will produce a tone spacing of about 270 Hz, which is the standard spacing for Horus 4FSK + si4063_set_frequency_offset(tone_index * 23 + HORUS_FREQUENCY_OFFSET_SI4063); radio_shared_state.radio_symbol_count_interrupt++; break;