STM32F051C8 ADC Accuracy Problem
Hello,
I've been using STM32F051C8 on some of my projects and I recently realised that, my ADC is not converting accurately. I connected my Vdda to Vdd, that is 3,3VDC and tried conversation routine below.
Here is the initialisation: Single Channel conversation of ADC2 and I enabled interrupt after conversation.
static void MX_ADC_Init(void)
{
/* USER CODE BEGIN ADC_Init 0 */
/* USER CODE END ADC_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC_Init 1 */
/* USER CODE END ADC_Init 1 */
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
Error_Handler();
}
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC_Init 2 */
/* USER CODE END ADC_Init 2 */
}
Here is ADC interrupt routine:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if (__HAL_ADC_GET_FLAG(hadc, ADC_FLAG_EOC))
{
ADC_BUF[0] = HAL_ADC_GetValue(hadc);
}
}
By the way, I enable ADC interrupt every 2msec:
HAL_ADC_Start_IT(&hadc);
With this routine, I got those conversation values:
Vadc = 0,33V --> ADC Value: 341
Vadc = 0,67V --> ADC Value: 759
Vadc = 1V --> ADC Value: 1176
Vadc = 1,32V --> ADC Value: 1576
Vadc = 1,66V --> ADC Value: 1993
Vadc = 2V --> ADC Value: 2411
I think these values are enough to show, ADC values are not accurate and linear.
Are there anything I missed? What's wrong with the configuration?
Thanks in advance for your help.