Remember frequency correctly

This commit is contained in:
Jan Hamal Dvořák 2024-07-31 23:49:15 +02:00
parent 7382677af8
commit 6b444587b6

View file

@ -71,6 +71,7 @@ static int gains[NUM_GAINS] = { 0, 9, 14, 27, 37, 77, 87, 125, 144, 157
static int sample_rate = INIT_SAMPLE_RATE; static int sample_rate = INIT_SAMPLE_RATE;
static int dc_level = CLK_SYS_HZ / INIT_SAMPLE_RATE / 2; static int dc_level = CLK_SYS_HZ / INIT_SAMPLE_RATE / 2;
static int gain = INIT_GAIN; static int gain = INIT_GAIN;
static int frequency = INIT_FREQ;
static int dma_ch_rx1 = -1; static int dma_ch_rx1 = -1;
static int dma_ch_rx2 = -1; static int dma_ch_rx2 = -1;
@ -560,13 +561,14 @@ static void run_command(uint8_t cmd, uint32_t arg)
{ {
if (0x01 == cmd) { if (0x01 == cmd) {
/* Tune to a new center frequency */ /* Tune to a new center frequency */
frequency = arg;
rx_lo_init(arg + sample_rate, true); rx_lo_init(arg + sample_rate, true);
} else if (0x02 == cmd) { } else if (0x02 == cmd) {
/* Set the rate at which IQ sample pairs are sent */ /* Set the rate at which IQ sample pairs are sent */
sample_rate = arg; sample_rate = arg;
dc_level = CLK_SYS_HZ / sample_rate / 2; dc_level = CLK_SYS_HZ / sample_rate / 2;
dma_timer_set_fraction(dma_t_samp, 1, CLK_SYS_HZ / (sample_rate * DECIMATE)); dma_timer_set_fraction(dma_t_samp, 1, CLK_SYS_HZ / (sample_rate * DECIMATE));
rx_lo_init(arg + sample_rate, true); rx_lo_init(frequency + sample_rate, true);
} else if (0x04 == cmd) { } else if (0x04 == cmd) {
/* Set the tuner gain level */ /* Set the tuner gain level */
gain = INIT_GAIN * powf(10.0f, arg / 200.0f); gain = INIT_GAIN * powf(10.0f, arg / 200.0f);
@ -680,7 +682,7 @@ int main()
queue_init(&iq_queue, sizeof(uint8_t *), IQ_QUEUE_LEN); queue_init(&iq_queue, sizeof(uint8_t *), IQ_QUEUE_LEN);
rx_lo_init(INIT_FREQ + INIT_SAMPLE_RATE, true); rx_lo_init(frequency + sample_rate, true);
while (true) { while (true) {
if (check_command() > 0) { if (check_command() > 0) {