STM32F334R8: ADC with DMA too slow

Viewed 166

I can measure signals and write in memory with DMA but speed is too slow (60 KSPS) while the ADC clock (same as system clock) is at 16 MHz.. I measure the speed but measuring a square signal at the ADC input.

I use a vary basic code with HAL easy to find on the internet but doesn't work for me !

Could someone give a code that you're sure it works so I can compare it to mine please ?

Thank you !

  */

int main(void) {

HAL_Init();

SystemClock_Config();

/* USER CODE BEGIN SysInit */
stop = 0;
i = 0;
a = 0;

MX_USART2_UART_Init();
MX_ADC1_Init();
MX_DMA_Init();
MX_ADC2_Init();
MX_GPIO_Init();
/* USER CODE BEGIN 2 */
HAL_ADCEx_Calibration_Start(&hadc1, adcVal);
//HAL_ADC_Start_IT(&hadc1);
HAL_ADC_Start_DMA (&hadc1, (uint32_t*)adcVal, 100);
while (1)
{

}

}

enter image description here

1 Answers

It's likely your ADC sample rate is too slow. DMA is pretty quick at transferring values out of the ADC peripheral, and since you're seeing results, I'd presume it's configured properly.

In Cube, you can configure the ADC sample rate to something higher by changing cycles per measurement. If you aren't using Cube, you can set the sample time manually using the family reference or (likely preferred) setting the sampling time in the initialization structure.

Sample rate can be set directly by modifying the ADC_SMPR1 register. Doing something like ADC1->SMPR1 |= rate << chan_idx * 3; to set the sample rate for a specific channel (chan_idx). The quickest configuration (sample rate of 2.5 cycles per sample) would have a rate of 0. This line can be run after HAL ADC initialization

Related