Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4781

General • Re: Mutli-channel, multi-sample DMA ADC reads

$
0
0
In the end I followed a different route. I never understood the point of changing the destination address with another DMA channel. I simplified things, just went with a simple 2 channel round robin, set the sample rate to double what I wanted and then de-interleaved the results from the single results array. I may revisit that example at some point to try and understand what they were trying to do.

The only thing I still don't understand is why I had to double the sample rate, i.e. I want to sample 20kHz audio, so need a sample rate of 40kHz, but I had to set the ADC sample rate to 80kHz in round robin mode to get the expected results.

In the setup I have:

Code:

    // ADC  adc_gpio_init(ADC_GPIO_L);  adc_gpio_init(ADC_GPIO_R);  adc_init();  uint chan_mask = get_chan_mask(adc_vals);  adc_set_round_robin(chan_mask);  adc_fifo_setup(true, true, 1, false, false);  // Set ADC clock divisor  uint clock_div = uint(PICO_CLK / SAMPLE_FREQ - ADC_ADJ);  adc_set_clkdiv(clock_div);  dma_chan = dma_claim_unused_channel(true);  dma_conf = dma_channel_get_default_config(dma_chan);  channel_config_set_transfer_data_size(&dma_conf, DMA_SIZE_16);  channel_config_set_read_increment(&dma_conf, false);  channel_config_set_write_increment(&dma_conf, true);  channel_config_set_dreq(&dma_conf, DREQ_ADC);
and in the loop I have

Code:

  // ADC Capture  adc_select_input(ADC_CHANNEL_L);  dma_channel_configure(    dma_chan,    &dma_conf,    samples,    &adc_hw->fifo,    NUM_CHANNELS * FFT_BINS,    true  );  adc_run(true);  dma_channel_wait_for_finish_blocking(dma_chan);  adc_run(false);  adc_fifo_drain();
And then I unpack the results from samples.

Statistics: Posted by StarryPied — Mon Feb 12, 2024 10:00 am



Viewing all articles
Browse latest Browse all 4781

Trending Articles