cancel
Showing results for 
Search instead for 
Did you mean: 

Reading ADC issues multichannel

Purnima_wbe
Associate II

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..

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Purnima_wbe
Associate II

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);

View solution in original post

1 REPLY 1
Purnima_wbe
Associate II

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);