cancel
Showing results for 
Search instead for 
Did you mean: 

Reading ADC Channels at once Callback

hasan16
Associate

Hello Team,

I'm pretty new to the field of the embedded systems. I want to read two adc channel at once Callback function. The ADC conversion should start at every timer8 update event. I wrote a code below for that but adc channels are read two different calls there. I want to read both channels at the same call. Is there any way to do that?

 
 
 
void HAL_ADC_ConvCpltCallback (ADC_HandleTypeDef* hadc) // ADC Interrupt function
{
if(hadc == &hadc1)
{
 
switch (count)
{
 
case 0:
adcValue[0] = HAL_ADC_GetValue(&hadc1);
break;
case 1:
adcValue[1] = HAL_ADC_GetValue(&hadc1);
break;
 
}
 
count ++;
 
if(count == 2) count = 0;
 
HAL_ADC_Start(hadc); // start adc
 
}
 
}
 
hasan16_0-1692079929422.pnghasan16_1-1692080073702.png

 

 
4 REPLIES 4
KnarfB
Principal III
  • TIM8 needs a clock source enabled
  • ADC End of Conversion should be set to single channel
  • the different channels must be selected for the ranks (not visible)

hth

KnarfB

 

 

Hello KnarfB,

Thank you for reply. I sent the wrong settings, sorry. The code is working now. But I can get two adc value with two different sequential Timer 8 trigger signal. Am i right? First Pwm is generated and Timer 8 event occurs. Then adcValue[0] takes the IN0 adc values. After that second pwm signal is generated and adcValue[1] takes the IN1 adc values. As you see i can get the all values in two pwm period. Can i get them in only one pwm period?

TDK
Guru

You can get them in one period if you use DMA. Otherwise you probably can't read the first value fast enough before the second value comes in, leading to an overflow condition.

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

You may have 2 or more ADCs in your chip, so you can sample 2 channels by 2 ADCs in parallel, both triggered by the same TIM8 update.

hth

KnarfB