Electronic – STM32L071KZ battery voltage monitoring via ADC

adcbatteriescircuit-designstm32

Sorry for the newbish question. I didn't find here any questions and answers that can help me with this issue so I decided to ask it.

I'm designing my first circuit with STM32L071KZ microcontroller and it powers via VBUS(USB, 5V) as a primary supply and 2xAA alkaline batteries(3V) as secondary supply.

the power supplies are regulated to 3.3V so the microcontroller and the rest of the circuit are powered by regulated voltage and not directly from VBUS or batteries.

I would like to monitor the batteries voltage level and when it drops below the specific threshold(For example, 2.2V) I will indicate it to the user.

I wonder how to wire things up. microcontroller's VDD is 3.3v and it equals to VDDA. If I got it right, when I will sample the voltage of the battery I will get a constant value because the sample is the ratio between the VDD and VDDA.

This is my power circuit block diagram to make things clear:

enter image description here

Thanks alot!

Best Answer

You need to make sure the batteries you use will never exceed 3.3V. If that is a possibility with fresh batteries you should consider adding voltage divider to bring ADC input down to acceptable range. This will increase power consumption from the batteries though. The usual cure for this is to add MOSFET switch between the battery and ADC, controlled by another MCU pin. The MCU will open the switch periodically, measure voltage and close it back. See this question for example.

Also the diode between Boost DC-DC and Vdd will drop some voltage (depending on current and diode), so you might want to adjust boost output to slightly higher voltage.

Note that Boost converter will drain battery even if USB is connected. Furthermore, your LDO must produce higher voltage than DC-DC for diode to close, something like 3.4~3.5V

So, i would suggest either use barrel DC adapter and a jack with mechanical switch that will disconnect battery when power plugged in, or another MOSFET switch that will disconnect battery when USB voltage present. See this question for relevant discussion.

Other than that your circuit looks OK.