Remove LO dithering for better SNR

This commit is contained in:
Jan Hamal Dvořák 2024-07-17 18:58:28 +02:00
parent eaad670abb
commit 0e1fc91279

View file

@ -82,14 +82,6 @@ static queue_t iq_queue;
static uint8_t iq_queue_buffer[IQ_QUEUE_LEN][IQ_BLOCK_LEN]; static uint8_t iq_queue_buffer[IQ_QUEUE_LEN][IQ_BLOCK_LEN];
static size_t iq_queue_pos = 0; static size_t iq_queue_pos = 0;
static uint32_t rnd = 0;
inline static uint32_t rnd_next()
{
rnd = rnd * 0x41c64e6d + 12345;
return rnd;
}
static void init_lo() static void init_lo()
{ {
gpio_disable_pulls(LO_PIN); gpio_disable_pulls(LO_PIN);
@ -176,7 +168,7 @@ static void init_rx()
pio_gpio_init(PIO, RX_PIN); pio_gpio_init(PIO, RX_PIN);
const uint16_t insn[] = { const uint16_t insn[] = {
pio_encode_in(pio_pins, 1), pio_encode_in(pio_pins, 1) | pio_encode_delay(1),
}; };
pio_program_t prog = { pio_program_t prog = {
@ -251,14 +243,11 @@ static void lo_generate(uint32_t *buf, double freq, uint32_t phase)
{ {
freq_step = STEP_BASE * freq; freq_step = STEP_BASE * freq;
unsigned down = 2 + __builtin_clz(freq_step);
for (size_t i = 0; i < LO_WORDS; i++) { for (size_t i = 0; i < LO_WORDS; i++) {
uint32_t bits = 0; uint32_t bits = 0;
int shift = (rnd_next() >> down) - (rnd_next() >> down);
for (int j = 0; j < 32; j++) { for (int j = 0; j < 32; j++) {
bits |= (phase + shift) >> 31; bits |= phase >> 31;
bits <<= 1; bits <<= 1;
phase += freq_step; phase += freq_step;
} }
@ -267,25 +256,6 @@ static void lo_generate(uint32_t *buf, double freq, uint32_t phase)
} }
} }
static void lo_tweak(uint32_t *buf, uint32_t phase)
{
static size_t i = 0;
uint32_t bits = 0;
unsigned down = 2 + __builtin_clz(freq_step);
phase += freq_step * i * 32;
for (int j = 0; j < 32; j++) {
int shift = (rnd_next() >> down) - (rnd_next() >> down);
bits |= (phase + shift) >> 31;
bits <<= 1;
phase += freq_step;
}
buf[i] = bits;
i = (i + 1) & (LO_WORDS - 1);
}
static void rx_lo_init(double req_freq, bool align) static void rx_lo_init(double req_freq, bool align)
{ {
const double step_hz = (double)CLK_SYS_HZ / (8 << LO_BITS_DEPTH); const double step_hz = (double)CLK_SYS_HZ / (8 << LO_BITS_DEPTH);
@ -374,18 +344,12 @@ static void rf_rx_start()
dma_channel_start(dma_ch_mix1); dma_channel_start(dma_ch_mix1);
dma_channel_start(dma_ch_samp_cos); dma_channel_start(dma_ch_samp_cos);
pio_sm_set_enabled(PIO, LO_SM, true); pio_set_sm_mask_enabled(PIO, 0x0f, true);
pio_sm_set_enabled(PIO, FB_SM, true);
pio_sm_set_enabled(PIO, RX_SM, true);
pio_sm_set_enabled(PIO, AD_SM, true);
} }
static void rf_rx_stop(void) static void rf_rx_stop(void)
{ {
pio_sm_set_enabled(PIO, LO_SM, false); pio_set_sm_mask_enabled(PIO, 0x0f, false);
pio_sm_set_enabled(PIO, FB_SM, false);
pio_sm_set_enabled(PIO, RX_SM, false);
pio_sm_set_enabled(PIO, AD_SM, false);
sleep_us(10); sleep_us(10);
@ -519,11 +483,6 @@ static void rf_rx(void)
if (queue_try_add(&iq_queue, &block)) { if (queue_try_add(&iq_queue, &block)) {
iq_queue_pos = (iq_queue_pos + 1) & (IQ_QUEUE_LEN - 1); iq_queue_pos = (iq_queue_pos + 1) & (IQ_QUEUE_LEN - 1);
} }
/* Randomize LO phase in the next word. */
for (int i = 0; i < 8; i++) {
lo_tweak(lo_cos, COS_PHASE);
}
} }
} }