2023-07-28 07:00 AM
I am trying to read Analog voltage from two different channel one is mains supply and another is battery voltage.But I am getting both values same in live expression window.Does my config wong.Pls help
void ADC_Mains(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
void ADC_Vbat(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_12;
sConfig.Rank = ADC_REGULAR_RANK_2;
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
// MAINS INPUT
ADC_Mains();
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,1000);
MainsVge=HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
HAL_Delay(100);
//Battery operation
ADC_Vbat();
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,1000);
Vbat=HAL_ADC_GetValue(&hadc1);
HAL_ADC_Stop(&hadc1);
HAL_Delay(100);
2023-07-28 07:14 AM
> sConfig.Rank = ADC_REGULAR_RANK_2;
If you're converting a single channel, this should be ADC_REGULAR_RANK_1.
Probably also need:
sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;