Skip to main content
areify
Associate III
June 10, 2019
Question

Analog read is not returning the maximum value

  • June 10, 2019
  • 9 replies
  • 2094 views

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 ~

This topic has been closed for replies.

9 replies

Tesla DeLorean
Guru
June 10, 2019

Perhaps scope wrt VREF+

Try a pin you don't have other circuitry hanging from it.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
areify
areifyAuthor
Associate III
June 10, 2019

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.

David SIORPAES
ST Employee
June 10, 2019

Try increasing 'sConfig.SamplingTime' and check if something is changing.

areify
areifyAuthor
Associate III
June 11, 2019

Hi David, it did not work, the readings did not vary...

David SIORPAES
ST Employee
June 11, 2019

Have you run the calibration process beforehand ?