2020-10-17 06:03 AM
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.
2020-10-17 06:05 AM
Here is the measurement :
2020-10-17 07:26 AM
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.
2020-10-17 07:28 AM
In STM32CubeIDE, i enable the "Continuous Conversion Mode", so he is continuously converting no? Am I wrong ?
2020-10-17 08:26 AM
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: