cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ADC_GetValue giving wrong values

ADG.1
Associate II

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?

8 REPLIES 8
MM..1
Chief III

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 ...

raptorhal2
Lead

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

Cheers, Hal

reference voltage?

raptorhal2
Lead

reference voltage?

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

Cheers, Hal

Then yes, its the battery.

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

raptorhal2
Lead

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