cancel
Showing results for 
Search instead for 
Did you mean: 

ADC halts for long time when changing TIM autoReload Register on runtime

JJ.5
Associate III

Hello,

I'm working on a NUCLEO-H743ZI2 development board.

I was trying to change ADC sampling rate based on the frequency. The ADC is set to DMA mode and triggered by TIM2.

The problem is when I use "TIM2->ARR = 4800-1; " or "__HAL_TIM_SET_AUTORELOAD() ", ADC and DMA halt for a long time. 

I attached a simple code that can reproduce the problem.

 

int main(void)
{
  HAL_Init();
 
  SystemClock_Config();
 
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_USB_DEVICE_Init();
  MX_TIM2_Init();
  MX_ADC1_Init();
  HAL_TIM_Base_Start(&htim2);
 
  for(float freq = 100; freq <= 1000; freq += 10)
  {
  val = freq; // monitor this value in debug
  
  if(freq < 500)
  TIM2->ARR = 4800-1;
  else
  TIM2->ARR = 2400-1; // change ARR causes halt
  
  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buf, BUF_LEN);
  while(!proceed)
  {
  //wait until adc_iteration reaches 10
  }
  proceed = 0;
  HAL_ADC_Stop_DMA(&hadc1);
  adc_iteration = 0;
  }
 
  while(1){}
}
 
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
{
    adc_iteration++;
    if(adc_iteration == 10)
        proceed = 1;
}
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
    adc_iteration++;
    if(adc_iteration == 10)
        proceed = 1;
}
 
From Freq = 100 to Freq = 490, it's pretty fast.
When Freq reaches 500, the value stays unchanged for a long time when I was monitoring it in the debug mode.
Then, from Freq = 510 to Freq = 1000, its fast again.
Is this because I'm changing the ARR registor in a bad way?
 
Thanks!
0 REPLIES 0