2019-05-08 09:21 AM
Good morning,
I have a problem with the adc converter of the microcontroller stm32L053. I am in the prototype state and am using the Discovery Board.
I only have the analog AN0 pin connected to ground. When I execute the reading the converter does not return 0 and I have ./- 5LSB of noise. Is there something I'm wrong about?
Below the ADC Configuration:
/* ADC init function */
static void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV16;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.SamplingTime = ADC_SAMPLETIME_39CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_VREFINT;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
2019-05-08 09:44 AM
Do not look at the translated values. Look at the digits. If the steps in tour diagramm translate to digit and are not by some calculation clipping that is +/- 4 LSB max. That does not sound to bad.
2019-05-08 11:09 PM
You should do an ADC Calibration (on time) before start a conversion. This will remove ADC Offset Error.
Take a look in your STM32Cube Repository ADC example.
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
Also, if you use STM32L0538DISCOVERY kit, note thay WakeUp Blue user button is shared with PA0 pin.
Best regards
rrom
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2019-05-09 01:39 AM
I try the calibration and the offset return to 0. The noise is alwais +/-5 digit.
I try to implement a mean to 8 sample, but i don't like this solution.
2019-05-11 08:16 AM
Hello Pablito,
I've tried to reproduce by using NucleoL053, and PA0 wired to GND.
My code use the same ADC setup (but without VREF_INT Channel) and perform ADC conversion on PA0 and fill a buffer of 64 samples.
Below my resuts are 0 with +2 lsb max .
Could you share your code please ?
BR
rrom
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.