AnsweredAssumed Answered

AN4590 & 2 Channel Ping-Pong

Question asked by Marco Hess on Dec 8, 2014
Latest reply on Dec 11, 2014 by Marco Hess

I am a little confused or simply don't understand AN4590.

 

I have a system with a K22F where I have 2 ADC channels both sampled at 40kHz rate. On the FRDM-K22F, I used both ADC0 and ADC1 both triggered by PDB and pushing samples into a ping pong buffer.

 

On my custom board, we decided to go with those two channels on the same ADC0 (because we need the ADC1 for a bunch of different channels and a much different sampling rate).

 

I originally aimed to setup the ADC with the Trigger A and the Trigger B mechanism for the different channel selections and was thinking that the DMA would transfer the results as before.

 

I now found out that the DMA can only trigger from the ADC interrupt and can't distinguish between A & B results.

 

So I am now trying to get to grips with what AN4590 is all about but I can't see how I can do what I think I need.

 

What I think I need is two channels sampled right after each other and then each channel result put in a ping-pong buffer for further signal processing.

 

In my previous setup, used the KSDK and has setup two DMA channels (one for each ADC). I used the following (simplified) code for each channel:

 

EDMA_DRV_Init( &edma_state, &edma_config );

EDMA_DRV_RequestChannel( SYS_DMA_CHAN_ADC0_A,

                                                   kDmaRequestMux0ADC0,

                                                  &edma_chn_state_adc0_A );

EDMA_DRV_ConfigLoopTransfer( &edma_chn_state_adc0_A,

                                          edma_transfer_descriptors_adc0_A,

                                          kEDMAPeripheralToMemory,

                                          (uint32_t)&ADC0_RA,

                                          (uint32_t)&edma_buffer_adc0_A,

                                          2, /* size to be transferred on every DMA write/read */

                                          2, /* bytesOnEachRequest */

                                          sizeof( edma_buffer_adc0_A ), /* Total length of Memory in bytes */

                                          2 /* Num Descriptors */);

EDMA_DRV_InstallCallback( &edma_chn_state_adc0_A,

                                       edma_callback_adc0_A,

                                       &edma_chn_state_adc0_A );

EDMA_DRV_StartChannel( &edma_chn_state_adc0_A );

 

Following AN4590 for what I understand from it, I need a DMA channel to transfer the channel selection to the ADC. Then the PDB triggers the ADC and then the DMA tranfers the result. But it looks like the ADC channels are interleaved in the result buffer. This would make it quite awkward for the subsequent processing and I have to copy out the data into separate buffers. Kind of defeats the purpose of the DMA.

 

How do I set the DMA up so the two different ADC channels end up in different ping pong buffers?

 

Can someone point out the sort of building blocks in terms of DMA channels and how they are setup and linked to each other to achieve this dual ping pong buffer?

Outcomes