2019-06-09 11:33 PM
Hi there.
I was making some tests and I have observed that, when I shortcircuit 3V3 into my analog pin (in this case PA0), the reading I'm having is 4022 instead of 4095.
Why this difference? I'm using HAL libraries as follows:
//Function to obtain ADC value
uint32_t adc_get_value(uint8_t channel)
{
uint32_t value;
uint32_t adcChannel;
ADC_ChannelConfTypeDef sConfig;
GPIO_InitTypeDef GPIO_InitStruct;
//Returns ADC channel and sets up GPIO port
adcChannel = adc_get_channel(channel, &GPIO_InitStruct);
/* Configuration of channel on ADCx regular group on sequencer rank 1 */
sConfig.Channel = adcChannel; /* Sampled channel number */
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; /* Minimum sampling time */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
if (HAL_ADC_ConfigChannel(&adc_handle_, &sConfig) != HAL_OK)
{
/* Channel Configuration Error */
return -1;
}
if(HAL_ADC_Start(&adc_handle_) != HAL_OK)
{
/* Enables ADC Error */
return -1;
}
if (HAL_ADC_PollForConversion(&adc_handle_, 10) != HAL_OK)
{
/* Poll for conversion Error */
return -1;
}
value = HAL_ADC_GetValue(&adc_handle_);
if (HAL_ADC_Stop(&adc_handle_) != HAL_OK)
{
/* Stop ADC conversion Error */
return -1;
}
return value;
}
Thank you in advance!
Areify ~
2019-06-09 11:46 PM
Perhaps scope wrt VREF+
Try a pin you don't have other circuitry hanging from it.
2019-06-10 01:45 AM
Sorry, but it is not possible to me at this moment to try that solution, due to the current design of the PCB in which it is installed... Do you have any other idea?
Another time, sorry. :(
And thank you for your help.
2019-06-10 06:59 AM
Try increasing 'sConfig.SamplingTime' and check if something is changing.
2019-06-11 04:27 AM
Hi David, it did not work, the readings did not vary...
2019-06-11 04:36 AM
Have you run the calibration process beforehand ?
2019-06-11 04:46 AM
No. It's neccesary with STM32F105VC? I thought it wasn't
2019-06-11 05:50 AM
Yes, it's better to calibrate ADC with
HAL_ADCEx_Calibration_Start()
in order to have best accuracy.
See section 11.4 of RM0008.
2019-06-11 06:28 AM
Yes, it worked!
I don't know exactly where, but I read it wasn't neccesary in this uC, so I was sorrounding the solution all time!
Thank you, David!
2019-06-12 12:14 AM
OK it seems to be not working with all values...
I'm trying to measure 2,1 volts generated with a divisor and I'm obtaining a value around 1400. When I stop the code with a breakpoint just after the calibration function I obtain a different value: around 2000.
This is so strange...