2021-11-10 06:12 AM
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?
2021-11-10 07:03 AM
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 ...
2021-11-10 07:03 AM
What is the reference voltage for the ADC? Is it the battery?
Cheers, Hal
2021-11-10 07:57 AM
reference voltage?
2021-11-10 08:56 AM
reference voltage?
As MM..1 pointed out - the voltage applied to the STM32L082 VDDA pin.
Cheers, Hal
2021-11-11 12:25 AM
Then yes, its the battery.
2021-11-11 12:28 AM
Since altering the hardware isn't an option for me, do you recommend a reliable way to measure the power output of the battery?
2021-11-11 06:06 AM
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
2021-11-11 07:30 AM