cancel
Showing results for 
Search instead for 
Did you mean: 

Are there a STMF4 or STMF7 ADC overun detection code example?

Geraldo Pereira
Associate II

Hi,

I´m working with a STMF767zi and STMF429zi kits and I´d like detect ADC overrun. Sow I write the callbackup code:

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {

flagOverRunCH1=0;

if (hadc->Instance==hadc1.Instance){

// Overun detection

/* if(overrun){

flagOverRunCH1=1;

}

*/

/* Get the converted value of regular channel */

if ((flagOverRunCH1==0) && (indiceVetorRmsCanal1<TAMANHO_VETOR_RMS_CICLOS)){

if (processarAmostraADC(HAL_ADC_GetValue(hadc))>0){

contadorLeiturasADC1++;

}

else{

// erro

}

}

else{

// Para os ADCs

HAL_ADC_Stop_IT(&hadc1);

vetorRmsCanal1;

// Para o timer 2

HAL_TIM_Base_Stop_IT(&htim2);

}

}

}

I´d like write the code to detect the ADC overrun. I´ve read the documentation, but I could not find a code example. I need code the /* if(overrun) */.

Thanks,

Geraldo.

2 REPLIES 2
TDK
Guru

The OVR interrupt enable flag is set in HAL_ADC_Start_IT:

https://github.com/STMicroelectronics/STM32CubeF4/blob/4aba24d78fef03d797a82b258f37dbc84728bbb5/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c#L1111

And the OVR flag is checked in HAL_ADC_IRQHandler:

https://github.com/STMicroelectronics/STM32CubeF4/blob/4aba24d78fef03d797a82b258f37dbc84728bbb5/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c#L1330

And if set, it will call HAL_ADC_ErrorCallback:

https://github.com/STMicroelectronics/STM32CubeF4/blob/4aba24d78fef03d797a82b258f37dbc84728bbb5/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_adc.c#L1346

So you just need to implement HAL_ADC_ErrorCallback in your program and within it, detect overrun by checking for

if (hadc->ErrorCode & HAL_ADC_ERROR_OVR) {
 
  // there was an overrun
 
}

 You could also just do that last check in your main loop to detect it.

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

Thanks TDK.

I´ll read, test and update this thread soon.

Thanks,