cancel
Showing results for 
Search instead for 
Did you mean: 

ADC multiple Channel with DMA - Reading of multiple scan sets with signe DMA transfer possible?

Curtis B.
Senior

Hi everyone,

I have configured my ADC on STM32F405 in Scan mode to read 5 channels. What I like to do ist to make a single DMA transfer to sample the 5 channels more than one time (e.g. 10x5channels = 50 elemet DMA transfer) To average the data after the transfer.

However, I could only run a DMA Transfer with more than 5 elements if I set the ADC to contonious mode. But in Continiues mode, the beginning of the channel order is not aligned to the first element of the DMA buffer (first channel in the sampling order is not necessarily in DMA_Buffer[0]).

Is there any solution to this problem, or is the ADC not intended to be used in that way.

Best regards

 

1 ACCEPTED SOLUTION

Accepted Solutions
LCE
Principal

And there isn't any possibility to do it in a discontinous way, like triggering an acquisition of 50 samples by software on demand?

I haven't used the ADC in this way, but I would be surprised if that is not possible, but maybe not with HAL.

I think the correct way to configure & use the peripherals would be:

- set up ADC in continuous mode, but do not yet enable it
- set up DMA in non-circular mode 
- start DMA
- enable ADC
- when DMA has finished, disable ADC

BUT I'm not sure about the validity of the first samples, I remember these being quite crappy - but maybe I did something wrong.

View solution in original post

4 REPLIES 4
RomainR.
ST Employee

Hello @Curtis B. 

You can feed your DMA_Buffer[] by using DMA in circular mode (and ADC in continuous as well) and count the number of DMA transfert in the DMA Xfer complete callback.

Then perform the averaging outside based and depending on the value of this number.

BR

Romain,

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Romain,

so assuming I have 5 channels and I want so average 10 samples, I define a Buffer with 100 elements, put the ADC in continious and continious DMA mode, create a circular dma channel und start the conversion in DMA mode with buffer length of 100. In the half and complete dma callback I can average the channels. Would that be a proper aproach? And there isn't any possibility to do it in a discontinous way, like triggering an acquisition of 50 samples by software on demand?

 

BR

 

LCE
Principal

And there isn't any possibility to do it in a discontinous way, like triggering an acquisition of 50 samples by software on demand?

I haven't used the ADC in this way, but I would be surprised if that is not possible, but maybe not with HAL.

I think the correct way to configure & use the peripherals would be:

- set up ADC in continuous mode, but do not yet enable it
- set up DMA in non-circular mode 
- start DMA
- enable ADC
- when DMA has finished, disable ADC

BUT I'm not sure about the validity of the first samples, I remember these being quite crappy - but maybe I did something wrong.

Hi LCE,

I tried your suggestion. It seems to work. But thanks to Romain as well, that could be another approach if I should face some problems with the current solution.

 

BR