Electrical – Battery voltage select and ADC measurement (OpAmp + uC)

adcbatteriesmicrocontrolleroperational-amplifiervoltage measurement

I need to measure battery voltage which supplies my electronics.

Vbat supplies buck-boost DC/DC converter then goes to uC and other ICs (3,3V).
I want to use 3×2 goldpins in conjunction with OpAmp to select Vbat voltage range: U1 (3,6V Li-Ion) or U2 (7,2 2x Li-Ion) or U3 (12V Pb) which generate 0V to 3,3V on uC ADC input / OpAmp output.

That is clear.

Now I would like to feedback uC through GPIO some way that I will know which jumper / battery type has been selected (I need to know that in software).
I imagine some additional OpAmps connected to R2/R2'/R2'' but I have no idea how to do it.

I'll appreciate your help šŸ™‚

schematic

simulate this circuit ā€“ Schematic created using CircuitLab


Edit 1:

The device is used to measure water pH and conductivity. It needs temperature feedback for pH and conductivity ICs and communicates through GSM. It will be powered by batteries so it needs to be energy-saving. Most of time it sleeps and every 5 minutes it makes the measurements. GSM is turned on (GSM sleep or DC/DC sleep mode) only for daily report or when measurements are out of range.
When it sleeps sub-ICs takes: 1mA (pH) + 0,4mA (conductivity) + 1mA (GSM sleep mode) or 1uA (GSM DC/DC power down quiescent current) + ??mA (PT1000 – not yet determined) + ??mA (uC – not yet determined but low).

Battery's voltage ADC measurement is need to calculate battery percentage of capacity and time-to-live (based on past statistics), additionaly raw voltage display.
For above I need OpAmp or voltage divider. Selecting battery type (input voltage) is mandatory to make calculations more detail. I dont want to do software computing and if-else to figure out if battery is 12V or 3.6V, because it is possible to plugin any battery combination which summed voltage is from 3V to 15V. Of course it is easy to determine from one voltage divider the battery type: 3.2-4.2V for one-pack Li-Ion, 6.4-8.4V for two-pack, and 10.8-12.6V.
Just thinking out loud šŸ™‚

Getting back to merritum: I need to choose between OpAmp and voltage divider based on energy-saving. Voltage divider (mega ohms) will consume uA the same for OpAmp's quiescent current in shutdown mode.
Im puzzled because at first I thought OpAmp will be more energy-saving.
Whant do you think guys and gals? šŸ™‚


Edit 2:

Accuracy and resolution.
The ADC is from STM32F091 and it is 12bit so cutting off the noise lets assume it is 10bit.
The worst case is Li-Ion battery which voltage ranges from 3.4V to 3.7V. That give 300mV delta. To represent the percentage I need 0,5% step so the resolution is 1.5mV per step. That is when using dedicated voltage divider.

When using single voltage divider for all batteries types:
The maximum battery voltage might be about 13V (for lead) so I need to scale it to 3.3V => div = 4. When using single Li-Ion I will get with this divider values from 925mV to 850mV so delta is 75mV. The needed resolution is 75mV/200 = 0.375mV. Step for 0V-3.3V 10bit is 3.2mV so 10 times too small. Even if I use all 12bit the step is too small – 0.8mV.

I think I need dedicated voltage divider for battery type or again OpAmp?
Whichever would be more energy-saving??

Best Answer

Since the jumpers have to be set manually, a simple solution might be to use a second jumper that indicates the selected gain to the microcontroller. So the user have to set two jumpers to identical positions. Or just use a rotary switch with two poles and three positions (e.g.: SS-10-23NPE).

A completely different approach would be to implement a autoranging function, where the microcontroller selects the gain factor automatically. Just use a small analog switch that will be controlled by the microcontroller. Now it is possible to auto gain the input signal: start with the lowest gain factor and work your way up just one step before saturation of the ADC input would occur. If neccessary protect the ADC input from overvoltage: just add a clamping zehner or TVS diode (important: low leakage current!) to the output of the amplifier.