Skip to main content
Visitor II
January 20, 2024
Solved

Reading ADC issues multichannel

  • January 20, 2024
  • 1 reply
  • 1263 views

Hi everyone,

 

I am trying to use multichannel ADC. I have a panel and an ntc for which I have to read the voltage vlaues. I have disabled the continuous conversion.

 

sConfig.Channel = ADC_CHANNEL_0; // Select channel for NTC
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);

HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 2000);
uint32_t ntc = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);

 

sConfig.Channel = ADC_CHANNEL_1;    // Select channel Solar panel
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_239CYCLES_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
 
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, 2000);
uint32_t sol_vltg = HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);

Even after selecting channel I get value of channel 0 in channel and if i dont select any channel then i get the same channel 0 value in channel one. I also tried not selecting channel 0 and only selecting channel 1 then in first run after restart i get channel 0 value in channel 0 and channel 1 value in channel 1 but since I have selected channel 1 and this code is in while loop i get channel 1 value in channel 0 in the continuous rus. Can anyone please help me out..

 

 

    This topic has been closed for replies.
    Best answer by Purnima_wbe

    Hi this worked for me

     

    HAL_ADC_Start(&hadc);
    HAL_ADC_PollForConversion(&hadc, 1000); //Poll for NTC
    uint32_t ntc = HAL_ADC_GetValue(&hadc);

    HAL_ADC_PollForConversion(&hadc, 1000); //Poll for solar panel
    uint32_t sol_vltg = HAL_ADC_GetValue(&hadc);
    HAL_ADC_Stop(&hadc);

    1 reply

    Purnima_wbeAuthorAnswer
    Visitor II
    January 20, 2024

    Hi this worked for me

     

    HAL_ADC_Start(&hadc);
    HAL_ADC_PollForConversion(&hadc, 1000); //Poll for NTC
    uint32_t ntc = HAL_ADC_GetValue(&hadc);

    HAL_ADC_PollForConversion(&hadc, 1000); //Poll for solar panel
    uint32_t sol_vltg = HAL_ADC_GetValue(&hadc);
    HAL_ADC_Stop(&hadc);