cancel
Showing results for 
Search instead for 
Did you mean: 

Many ADC measurements on different ADC

Landroval
Associate II

Hi,

I'm using STM32F207 and I'm trying to make three different ADC measurements on three difeerent ADC.

My purpose is to make 100.000 measurements on each of these signals at the highest speed possible.

With only one signal (so using only one ADC) I can make 100.000 measurements in 3,88 secondes but withg three different signals I need 11,69 seconds to make all these measurements (3 * 100.000 measurements)

Here my code

for (uint32_t i = 0; i<100000; i++)
	  {
		HAL_ADC_Start(&hadc1);
	  	HAL_ADC_PollForConversion(&hadc1, 100);
	  	adcResult_many_ADC1[i] = HAL_ADC_GetValue(&hadc1);
	  	HAL_ADC_Stop(&hadc1);
 
	  	HAL_ADC_Start(&hadc2);
	        HAL_ADC_PollForConversion(&hadc2, 100);
	  	adcResult_many_ADC2[i] = HAL_ADC_GetValue(&hadc2);
	  	HAL_ADC_Stop(&hadc2);
 
	  	HAL_ADC_Start(&hadc3);
	       HAL_ADC_PollForConversion(&hadc3, 100);
	  	adcResult_many_ADC3[i] = HAL_ADC_GetValue(&hadc3);
	  	HAL_ADC_Stop(&hadc3);
	  }

Is there a way to decrease this time by coding it differently ?

Thank you for your help 😊

1 ACCEPTED SOLUTION

Accepted Solutions

>>Is there a way to decrease this time by coding it differently ?

The prescribed mechanism is to use DMA, and put the ADC into a continuous mode, this will be massively more efficient than this kind of polling nonsense.

Triple Simultaneous mode world even provide the measurements on the three channels at the same instant, and not displaced across the time domain.

Ceiling there is around 2 MSps, interleaving offers 6 MSps, but that basically reads the same channel but with staggered starting points across the 3 ADC

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
S.Ma
Principal

Use injected channels, ask each ADC to continuously convert over and over the channel you selected.

Do this to all 3 ADC

Launch all 3.

Read each ADC register whenever you want, the register is updated asap. In the end you might just poll for a conversion complete flag, no wait, no delay.

Above code is sequential so the loop slows with ADC and channels to convert.

Don't know exactly which HAL function to use, check the header files related to HAL_ADC

Landroval
Associate II

Thank you a lot for your answer.

I am not familiar with this but I'm going to dig into it

>>Is there a way to decrease this time by coding it differently ?

The prescribed mechanism is to use DMA, and put the ADC into a continuous mode, this will be massively more efficient than this kind of polling nonsense.

Triple Simultaneous mode world even provide the measurements on the three channels at the same instant, and not displaced across the time domain.

Ceiling there is around 2 MSps, interleaving offers 6 MSps, but that basically reads the same channel but with staggered starting points across the 3 ADC

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Landroval
Associate II

Hi,

Thank you @Community member​ I tried you idea (it took me some time to understand how all this works) but now with a single ADC I have a sampling frequency of 144kHz for each one of my three signals which is much better than before.

Thanks a lot for your help.