Skip to main content
ADG.1
Associate
November 10, 2021
Question

HAL_ADC_GetValue giving wrong values

  • November 10, 2021
  • 8 replies
  • 2915 views

I'm trying to use HAL_ADC_GetValue to get the ADC value from an STM32L082 attached to a battery giving 3.7V. My goal is to use the ADC value to estimate the battery percentage so I need the ADC value when the battery is full and when it's mostly empty. The problem i'm facing is that the HAL_ADC_GetValue always returns 4095 when the battery is above a certain voltage and it wont go below 3600 even though the voltage is lowered (so at 3.25 volt it returns 3600 and also at 2.9 volt). Between these two points it works perfectly.

Does anybody know what could be causing the problem?

This topic has been closed for replies.

8 replies

MM..1
Super User
November 10, 2021

ADC convert values against reference and in normal is ADC reference Vcc. (Vdda)

Then when batt go low Vdda go low and result measure is always TOP for 12bit 4095

Charged 3,7V have 4,2V usw.

STM isnt designed for any voltage then you have more choices here use DC DC , use RC pulse measure , with external reference ...

ADG.1
ADG.1Author
Associate
November 11, 2021

Since altering the hardware isn't an option for me, do you recommend a reliable way to measure the power output of the battery?

MM..1
Super User
November 11, 2021
raptorhal2
Lead
November 10, 2021

What is the reference voltage for the ADC? Is it the battery?

Cheers, Hal

ADG.1
ADG.1Author
Associate
November 10, 2021

reference voltage?

raptorhal2
Lead
November 10, 2021

reference voltage?

As MM..1 pointed out - the voltage applied to the STM32L082 VDDA pin.

Cheers, Hal

ADG.1
ADG.1Author
Associate
November 11, 2021

Then yes, its the battery.

raptorhal2
Lead
November 11, 2021

Since altering the hardware isn't an option for me, do you recommend a reliable way to measure the power output of the battery?

Your problem is like trying to lift yourself up by your shoelaces.

I presume you mean voltage output, not power output.

I haven't worked a problem like this. I suggest you investigate using Comparator 2 to at least detect when the battery voltage has reached some level where the battery should be replaced.

Cheers, Hal