How to read 4.2V cell voltage by 3V STM32 ADC - Page 1
Forum section: electronics / projects

author: Wilson__
author_rank: Frequent Contributor
timestamp: May 30, 2024, 11:31:44 pm
content: Any idea on how to read 4.2V lithium cell by ADC on 3 volts STM32?Two resistor voltage divider will be constant drain for the cell. Can high resistance be used? Say 1M ohm is 3uA drain. The ADC specification is 50k ohm source resistance. May be ok to use higher R for slow sampling?? The ADC input pin leakage (offset) current is not specified.May be two MOSFETs, N and P type, can make a high side switch for the voltage divider.Many thanks

author: moffy
author_rank: Super Contributor
timestamp: May 31, 2024, 12:39:44 am
content: Quote from: Wilson__ on May 30, 2024, 11:31:44 pmYour solution of the N type switching the P type into a resistive divider sounds reasonable as long as they have suitable threshold voltages, or the N type could be replaced with an NPN whichever is preferred.

author: Geoff-AU
author_rank: Frequent Contributor
timestamp: May 31, 2024, 01:32:32 am
content: 1Meg voltage divider and a capacitor across the lower resistor to provide low impedance for the ADC’s sample and hold.

author: ArdWar
author_rank: Frequent Contributor
timestamp: May 31, 2024, 03:11:51 am
content: You probably only need low side switch, provided that you set the ADC pin as open drain OUT by default and only switch to analog INafterthe divider is pulled down. ADC pin in most STM32 are FT (5V tolerant) structure. You can even use an open drain output to switch the lower leg directly.For reference:https://www.st.com/resource/en/application_note/an4899-stm32-microcontroller-gpio-hardware-settings-and-lowpower-consumption-stmicroelectronics.pdf

author: mariush
author_rank: Super Contributor
timestamp: May 31, 2024, 04:02:30 am
content: You could try adding 2-3 diodes in series.... at that ultra low current a 1n400x (1n4001 to 1n4007) should still have a voltage drop of at least 0.5v so with 3 diodes, maybe you'll have around 1.5v drop.You'd have to "calibrate" it in software or measure your diodes before hand, and the readings may be affected by temperature of diodes but otherwise ....More expensive would be to use an actual fuel gauge IC which would also measure how much energy goes into the battery and how much it goes out and give you a remaining battery life in percentages .. but usually such ICs are at least half a dollar or so.exSTC3115https://www.lcsc.com/product-detail/Battery-Management-ICs_STMicroelectronics-STC3115AIQT_C2688637.htmlBQ27426https://www.lcsc.com/product-detail/Battery-Management-ICs_Texas-Instruments-BQ27426YZFR_C165137.htmlBQ27546https://www.lcsc.com/product-detail/Battery-Management-ICs_Texas-Instruments-BQ27546YZFR-G1_C528629.htmlBQ27427https://www.digikey.com/en/products/detail/texas-instruments/BQ27427YZFR/17748369etc etc

author: Doctorandus_P
author_rank: Super Contributor
timestamp: June 03, 2024, 11:52:10 am
content: Using a high impedance voltage divider combined with a capacitor as Geof-AU mentioned is a common technique. Input is mostly capacitive (the sampling capacitor has to be charged)I once did a test on a breadboard with an ATmega. I connected a small capacitor to an ADC pin, had the uC sample it and put it on a display. I saw only very slow drift of the capacitor voltage with only the ADC connected. It drifted slowly to around half the supply voltage. If you alternately sample a grounded pin and the capacitor, then the capacitor is drained quickly, because it has to fully charge the sampling capacitor on each sample. It's easy to build something similar on a breadboard and do some measurements with your own uC.If your inputs are 5V tolerant as ArdWar mentioned, then you can also use a second I/O pin to switch the "GND" level of the voltage divider between GND and open drain.Putting a bunch of diodes in series sounds like a bad idea. too much trouble with temperature coefficents etc.You could use an TL431, then a resistor on the bottom side, and switch that with an I/O pin. If the I/O pin is grounded, then the node between the Anode of the TL431 and the resistor is 2.5V lower then the supply voltage, when the I/O pin is floating... I'm not sure what happens. TL431 goes out of regulation and the result may be brand and specific. Maybe there are some other more suitable zener diodes.