STM32h747 ADC sampling problem
Hi!
I am currently working with the stm32h747, trying to sample current and voltage using the internal ADC with its analog pins. My samples are wrong, the values sampled are coming out with a wierd offset (for example: 0 voltages is samples as ~1.87v). i can see that aplying votage on the pins or shorting them to GND gives some effect but the values are still wrong.
the init code is standard and generated by cubeMX, My cube defenitions look like this:
Here is an example of how i sample:
the following function is called and i configure the specific pin i want to sample.
float CAdc::GetAnalogIn(void)
{
float val, Result;
ADC_ChannelConfTypeDef sConfig = {0};
sConfig.Channel = ADC_CHANNEL_18; //set MNTR_APD_Pin channel
sConfig.Rank = ADC_REGULAR_RANK_1; //Work with one channel
sConfig.SamplingTime = ADC_SAMPLETIME_16CYCLES_5; //number of cycles
HAL_ADC_ConfigChannel(&hadc1,&sConfig);
val = ADC_Get_Channel_Val(&hadc1,10);
Result = (((val * 3.3) / 4096) * 1);
return Result;
}
This function makes the actual sampling operation and called after proper config.
float CAdc::ADC_Get_Channel_Val(ADC_HandleTypeDef* hadc,uint8_t Avg_Count)
{
float value = 0;
HAL_StatusTypeDef retCode;
retCode = HAL_ADC_Start(hadc);
if(retCode != HAL_OK)
return -1;
retCode = HAL_ADC_PollForConversion(hadc, Avg_Count);
if(retCode != HAL_OK)
return -1;
uint32_t raw = HAL_ADC_GetValue(hadc);
value = raw;
retCode = HAL_ADC_Stop(hadc);
if(retCode != HAL_OK)
return -1;
return value;
}
Thanks in advance to those who can help resolve this issue :)
