Skip to main content
ChristenTen
Associate II
October 17, 2020
Question

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

  • October 17, 2020
  • 4 replies
  • 1099 views

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.

This topic has been closed for replies.

4 replies

ChristenTen
Associate II
October 17, 2020

Here is the measurement :

0693W000004K8IJQA0.png

TDK
October 17, 2020

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
October 17, 2020

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

TDK
October 17, 2020

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""."