Skip to main content
Visitor II
August 15, 2023
Question

Reading ADC Channels at once Callback

  • August 15, 2023
  • 2 replies
  • 2042 views

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

 

 
    This topic has been closed for replies.

    2 replies

    Super User
    August 15, 2023
    • 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

     

     

    hasan16Author
    Visitor II
    August 15, 2023

    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?

    Super User
    August 15, 2023

    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

     

    Super User
    August 15, 2023

    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.