Showing results for 
Search instead for 
Did you mean: 

ADC for battery voltage monitor

Associate III


I am using a STM32L4ZIT6 MCU. I want to monitor 4.2V Lipo battery voltage on an ADC pin. 

I have experimented two approaches:


I used a 332k - 820k divider in order to drain low queiescent current. This is an high impendance measurement, where RIN = 236k (equal to the parallel of the resistors). According to AN2834, I increased the sample time (640 cycles) and I added by software 50ms of delay between measurements. 

However, I always get about +50mV offset compared to real value.



I used a 100k - 100k divider for a lower impedance with switch mosfet closed only at measurement time, where RIN = 50k. In this case I always get lower values than real values. In this case I reduced sample time. 


In both case, a calibration is run at MCU startup. Reference voltage is 3,24V.

How can I improve accuracy? which is the better strategy?

Senior III

To measure the battery voltage, I use an R-R divider with 10k resistors and C=220n between the analog pin and GND. To achieve minimum consumption, I turn on the voltage on the divider with a pair of FET transistors in one case. P+N. I activate them by GPIO before measuring, if there is not enough PIO, then the transistors are switched on by the power supply (VDD is pesent).

ST Employee

In previous threads of yours it was about the STM32L4R9ZI, so presumably it's the same one now?

In addition to the information from @ONadr.1: at what frequency you are clocking the ADC, because the measurement time results from its period duration (see RM0432, section 21)?


In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I will try it. However, why have you used a capacitor, since impedance is lower than maximum reccomended, that is 50k?

You are right, the code is STM32L4R9ZI. 

ADC clock is 12 MHz

It is only for filtering some noise from analog line. The voltage is nearly constant, then use analog filtering is better then digital.

Associate III

Very strange behavior!

I mounted partinion 10k + 10k. Battery voltage is at about 4V, and by voltage tester I read about 2 V between two resistors. On the firmware, the ADC read about 850 on 4096, that is about 0,6V. Vref is at 3,24V. I tried simply ADC polling function with ADC clock at even 8MHZ and different sample times, but measures are always the same. What is going wrong?


Try to measure MCU internal reference voltage. If there will be a big error here, is something wrong with VDDA or code.Is it some Nucleo or Discovery kit or your own design? In this case helps schematics and PCB layout. And put here your code and configuration to check is it correct.