cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 ADC voltage calculations

ARai
Associate II

I have been trying to calculate voltage of the battery connected to ADC_IN7 of STM32L010K8. I have connected a battery to it via voltage divider. When I read the ADC I get raw values of 1948 for applied voltage of 3.7V. After going through the datasheet and posts on the community I tried calculating the voltage using 2 different formulas:

  1. Battery Voltage = 3.3 * Vrefint / ADC_rawvalues
  2. Battery voltage = 1.23 * 4096 / ADC_rawvalues

I get Vrefint by calling memory location 0x1FF80078.

Both the formulas are giving incorrect answer. Is there something I am missing? Is there a different way to do it?

4 REPLIES 4
TDK
Guru

> via voltage divider

A R1/R2=1 divider? If so:

battery voltage = 2 * VDDREF * ADCRAW / VREFINT_CAL

VDDREF depends on your board. Typically this is the same as VDD. If you don't know it, you need to calculate it.

90% sure this is right. Double check.

If you feel a post has answered your question, please click "Accept as Solution".
VPraj.2
Associate II

Hello @Community member​ 

As i can see your question, ADC_IN7 pin is 5V tolerant GPIO pin as per the details i checked in datasheet (Refer below snap). You probably would have to refer AN4899 section "4.3.6 I/O usage for the five-volt ADC conversion" for FT pin usage with ADC. You will always get garbage value without taking care of this FT_PAD connections. I'm using the same STM32L0 series MCU and facing issue. If you already did some additional GPIO connection to work PA7 pin as ADC pin, let me konw as well. I am looking for perfect solution for same sort of issue with my STM32L0 eval kit.

Hi,

I have not been working on this board for months, I might work on it next week and get back to you.

Thank you.

VPraj.2
Associate II

Thanks for the reply. Please let me know once you resume work on STM32. Thanks!