cancel
Showing results for 
Search instead for 
Did you mean: 

Why my convertion time is not correct when the sampling time is less than 84 Sampling time ?

ChristenTen
Associate II

Hello,

I'm using STM32f411RE with ADC and I would like to know why when the sampling time is less than 84, I don't find by calculation the same expected conversion frequency/time?

My calculation is Tconv = (3+12)/210000Hz = 714 ns so a frequency of 1.4 MHz. But in the measurement, I find a frequency of 260 kHz:

Here is my program:

/* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
	HAL_ADC_Start(&hadc1);
 
	HAL_ADC_PollForConversion(&hadc1, 1);
	HAL_GPIO_TogglePin(GPIOA, LD2_Pin);
	res = HAL_ADC_GetValue(&hadc1);
	res = res * 3.3/4095;
  }
  /* USER CODE END 3 */

I use a led with the toggle function after each conversion.

Thank you in advance for your help.

4 REPLIES 4
ChristenTen
Associate II

Here is the measurement :

0693W000004K8IJQA0.png

TDK
Guru

You're not continuously converting. You're starting the conversion, waiting for it to finish, then doing some other stuff. There is overhead associated with these tasks.

You'll need DMA hooked up to sample that fast without losing data.

If you feel a post has answered your question, please click "Accept as Solution".
ChristenTen
Associate II

In STM32CubeIDE, i enable the "Continuous Conversion Mode", so he is continuously converting no? Am I wrong ?

TDK
Guru

If you're continuously converting, then you should only call HAL_ADC_Start once. It might work if you move HAL_ADC_Start before the while loop, if the CPU can keep up, depending on how HAL_ADC_PollForConversion is written. I'm not digging into it.

See the CubeMX examples for how to use ADC+DMA:

https://github.com/STMicroelectronics/STM32CubeF4/tree/b5abca20c9676b04f8d2885a668a9b653ee65705/Projects/STM32F411E-Discovery/Examples/ADC/ADC_RegularConversion_DMA

If you feel a post has answered your question, please click "Accept as Solution".