2021-12-17 05:43 AM
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.
2021-12-17 06:43 AM
The OVR interrupt enable flag is set in HAL_ADC_Start_IT:
And the OVR flag is checked in HAL_ADC_IRQHandler:
And if set, it will call HAL_ADC_ErrorCallback:
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.
2021-12-17 12:36 PM
Thanks TDK.
I´ll read, test and update this thread soon.
Thanks,