cancel
Showing results for 
Search instead for 
Did you mean: 

Detecting current channel in ADC interrupt callback

Mohammad A
Senior
Posted on April 13, 2017 at 00:00

I have enabled analog watchdog in multi channel continues mode and now I'm trying to figure out how to find out which channel has triggered HAL_ADC_LevelOutOfWindowCallback. I have examinedhadc->NbrOfCurrentConversionRank but it seems this parameter is always 0 when it reaches to AWD callback.

void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef* hadc){
if(hadc->NbrOfCurrentConversionRank == 1)
__NOP;
else if(hadc->NbrOfCurrentConversionRank == 2)
__NOP;
}�?�?�?�?�?�?

How can I find number of the channel triggered AWD?

#hal #adc
2 REPLIES 2
ColdWeather
Senior
Posted on April 13, 2017 at 10:06

You dont't write, what CPU you use. Read the reference manual (RM) and you'll probably find out, there is no ADC register/bits that would display the number of a channel just finished. At least F1xx and F0xx, I work with, have not. Having the ADC running in the multichannel continuous mode it is strongly recommended by RM to use DMA to gather the data to avoid overrun conditions.

My experience shows, though, even using the DMA does not completely avoid the overrun condition in a noicy enviroment. Anyway, should you deside to use the DMA implement the DMA interrupt upon TC (transfer complete) and check there, if the overrun condition is marked. If so, ignore the gathered data and reinit the ADC and the DMA channel completely to restart them from the very beginning to get them synchronized again.

Posted on April 13, 2017 at 18:56

Overrun is not a problem in my application. I am using Analog Watchdog to detect activities, because I don't want constantly check and compare gathered values.