LiPo Voltage detection circuit

Detecting LiPo voltage is not the best way to check charge level but it’s the easiest.

I was using a PR2040-Zero (works like a Pico), all analog pins were in use.
I wanted to indicate when the LiPo needed a charge so came up with this circuit using a LM393 op amp. The onboard LDO voltage regulator is used as the reference voltage. (3V3)
See discussion below, the original circuit had a few problems which have been fixed in this pic.

The main problem was the LM393 does not work with a 3V3 supply, it stops working at 3.522V. The output remains low even though the non inverting input is greater than the inverting input. The solution was to use VSYS as the supply even though it is changing as the battery discharges.

I wanted to indicate when the battery had reached about 3.5V. The values of the high and low trigger points were calculated using a web page provided by @Robert93820. Comparator Hysteresis Calculator

The VSYS resistor divider was calculated to bring it to the low voltage calculation.

The circuit I built triggers at 3.58V, which is above the point where the LM393 output remains low.

Note: The hysteresis points change slightly as VSYS changes but no enough to affect circuit operation.

This circuit has now worked through a number of charge and discharge cycles. The assistance by @Robert93820 was invaluable and help me better understand analog circuits and op amps. This little circuit will feature in future LiPo projects to indicate when the battery needs charging. It is better than wasting a ADC pin on just measuring the supply.

Cheers
Jim

EDIT: original has been edited due to problems discussed below.

3 Likes

Hi James
Yes, a classic comparator with hysteresis (10k, 100k).
But, as VSYS is the variable you are monitoring I don’t think this should be the supply for the LED and 2k2 resistor. The 393 is open collector so is independent of the supply to the 393. The problem arises as you show it because the voltage VSYS is variable and thus the voltage on pin 1 and the hysteresis will vary in sympathy so altering the low threshold switching voltage. This makes the switching point a bit unpredictable and hard to calculate. You would have to build it and measure the switching points

Maybe a better idea would to return the LED to 3.3V (as a steady voltage) which would somewhat remove the moving goal post effect.

Have a look at this web site and plug in some numbers and you will see what I mean.
https://daycounter.com/Calculators/Comparator-Hysteresis-Calculator.phtml
Cheers Bob

2 Likes

Thanks for your insight Bob.
Digital has always been easy for me, Analog not so.

What you have described is what I observed as the battery discharged.
I will change the LED to 3.3V and see how it goes. (and edit the circuit diagram)

Cheers
Jim

1 Like

Hi James

Seems to be pretty normal these days although the basics apply to both.

Those 339 (dual) and 393 (quad) are pretty useful chips. Being open collector and the only common bit being the Ground (emitter) enables several of these outputs to be joined in an OR (or NOR, That is active LOW) configuration.
Can be very useful at times.

Connecting to a steady supply will allow you to calculate switching points with pretty good accuracy.

Don’t forget when figuring this out you are using the NON Inverting input. That is when the input goes LOWER than the reference (in this case the non inverting input) he output transistor is ON thus a low (near ground) output. The hysteresis offset will be the same it is just a bit easier sometimes to juggle numbers and resistor values when using the inverting input.

A very useful circuit for lots of things.
Cheers Bob

2 Likes

Hi James
Another simple basic circuit using LM393
This is a window comparator. The output will be LOW while the input is OUTSIDE the limits set by R!, R2, R3. An example of the versatility of the common collector configuration.


Cheers Bob

2 Likes

Ran it with the change over the life of the battery, and all good.
Measured 3.546V not triggered, 3.508V triggered.
Changed the original post circuit pic.

Had another thought, the GPIO pin voltage should never be greater than 3V3.
Another reason the LED should connect to 3V3.

Pretty happy with how this has turned out, will be kept in mind for for other projects.
Thanks for your help BoB.

Cheers
Jim

1 Like

Hi James
There is something wrong here.
Consider the action with no hysteresis (disconnect the 100k resistor). The 393 Wii switch with VSYS at 3.3V (same as reference).

With hysteresis the switching point with LOWERING VSYS will be somewhat lower and according to the calculator I linked will be a VSYS of 3.19V. When VSYS is RISING again the switching point back again will be VSYS of 3.63V. That is a hysteresis of 0.44V which is quite a lot. I understand using hystereses to get a clean switching action but that is quite a bit. You only need a few mV for that. If you increased your 100k to 1MΩ your VSYS switching points should be 3.28V and 3.33V respectively which is a hysteresis of only 50mV. You could try 500k to get somewhere in between but I think 100k is too low.

I think the LED could be modifying the hysteresis as well. The calculations assume a resistive load from the output to +V. The diode could well be modifying this. Fit a 10k resistor across the LED. This will allow the full 3.3V to appear at pin 1 so allowing correct hysteresis and should not affect LED operation.

What happens to the 3.3V when VSYS gets down close to it. Is the 3.3V derived from the battery directly. If so and the device with the GPIO is directly powered from the battery this circuit can not work properly with the values shown.

Can you see what I am getting at. Even without hysteresis the switch does not operate until VSYS gets down to 3V3 as the divider resistors are the same on both sides. I think when the battery gets close to 3V3 the on board regulator will stop working properly and the reference V is likely to do some funny things. Unless you have done something different to what I am thinking.

In a nutshell I think for this arrangement to work the 3V3 has to remain at 3V3.

Or another scenario could be the circuit is not wired as shown. I still can’t see how it switches with the VSYS above 3V3. It should switch BELOW 3V3 with VSYS falling, that is starting high. Ir will switch the output HIGH (LED OFF) again at a point ABOVE 3V3 when VSYS is RISING. That is what the hysteresis is all about.
Cheers Bob

I am using a RP2040-Zero board (similar to a Pico) which has a low dropout voltage regulator (0.25V at 500mA). As long as the LiPo is 3.5V or higher and less than 500mA, it will produce 3.3V output. (RT9013-33).
The Pico has a Buck/Boost regulator and will work down to 1.8V input. (RT6150B-33GQW)

Originally I was going to use a LM336-2.5 2.5V Voltage Reference but the 3.3V resistor divider maintains 2.49V on pin 2 of the comparator over the life of the LiPo.

I did breadboard testing finding numerous dead ends.
I found a web page which had formulae to calculate hysteresis resistor values and high/low triggering voltages for a non inverting op amp. The formulae for the high voltage included only the reference, the low voltage included the reference and the supply.

As I write this I am beginning to think I fluked the result. As I said my analog theory is not as solid as my digital. I think I have the high and low voltage levels mixed up.
The observed measurements do not match the calculations.

Going to go some more testing.

Device Operation.
It is a hand controller for an RC Cart. All 4 analog ports are used by two joysticks.
So no port available to check the battery voltage.

I wanted to give the user a visual indication of low battery. There is a LED on the controller that remains solid until the Pico GPIO pin goes low. Then the LED flashes.

At that point the controller should be turned off and connected to a USB charge source. It uses a Makerverse LiPo USB-C charger board. When the green light on the board turns off it is fully charged and can be used again.

Thanks for your help BoB.
Regards
Jim

EDIT: Fixed voltage regulator reference, RP2040-Zero has LDO, Pico has Buck/Boost.

Hi James

That is good. That means the 3V3 should remain and the circuit should be OK.
I haven’t had a chance to see what the LED does to the actual voltage at pin 1 when the output transistor turns off yet. I have never had a reason to but a 10k resistor across the LED as I suggested might be required. I will try to do this tomorrow.

As I said above according to the calculator I linked, when the battery is discharging and VSYS is going down the 393 output should switch LOW at 3.19V and switch high again at 3.63V. I might have time to check this I hope. If you want to tighten this up a bit increase the value of the 100k resistor as I mentioned above.

By the way. The voltage at pin 2 should be (3.3/13.3)*10 = 2.48V. If you are measuring 2.49 you have a small measurement error (assuming you are using 1% resistors, if not you should be for this application) or your 3V3 is a fraction high. This is not going to make a great difference, not the sort of difference you measured previously anyway.

According to hoyle the values you have chosen should be OK except for the 100k. you probably need to tighten this up a bit so the 393 output will switch LOW with a VSYS (battery ??) of a bit below 3V3 and high again (charging) a bit above 3V3. You can really make it do what you like by juggling the 3k3 and 10k values on the VSYS side. Or the reference, it does not matter. But not both.
Cheers Bob

1 Like

And now we come to the part where the theory and calculations do not match the real world observations.

Did all the calculations using the formulae, built the circuit with the calculated components and it does not work correctly. 2.49v on -ve pin, 2.819v on +ve pin and the output is still low. It should change at 2.516v according to the calculations.

My guess is I am trying to operate the comparator below the minimum voltage it was designed for, 5V. I think I need the low voltage version, LMV393, it works from 2.7 to 5V.

When my circuit did work it was just a fluke.

Regards
Jim

Hi James

The LM393 (no"V") works 2V to 36V.

Your original circuit should have worked but not switch at the levels you quoted.
I will try to build your original circuit and check today.

You are going in circles now and seem to have changed component values. To what value, you don’t say so is impossible to check. BUT you seem to be measuring right on the IC pins and you are correct the output should be HIGH with that + and - pin readings.

Don’t forget that output is open collector and unless it is returned to some pos V it will read nothing. Your original circuit returned this via a resistor and LED. I said before I don’t know what effect the LED has on all this and suggested a 10k resistor across it to make sure you get 3V3 at pin 1 in the HIGH state.
Cheers Bob
PS:
There are not too many “flukes” in this business. There is always a reason and the fun (and sometimes frustrating) bit is finding it.

2 Likes

Hi Bob,

This the circuit I built today, measured voltages in Red.
It is on a small piece of vero board. If I continue it will need to go back to a breadboard.
Soldering and desoldering is not a good way or easy way to test components.

I calculated the hysteresis values using the web page you linked. And backed up with other formulae.
Hysteresis is pretty simple and doing all this has helped me understand it better.
I have been over the board with a ‘fine tooth comb’ all the connections are as per the circuit and no shorts. I really expected it to work.

I am using 1% resistors, the LED has been removed, the open collector has a 1k pull up.
The 3k3 and 1k add up to 4k3 which puts the voltage at 2.447v when VSYS is 3.5V.
The measured voltages are what I would expect, the comparator is just not switching to High output.

As I said to find out further it will be back to the breadboard and use some 10 turn pots to see where it switches. Anyway appreciate your help and words of wisdom.

Cheers
Jim

image

1 Like

Hi James
Got it.
Built up what you originally posted. The results were as you first stated which on paper seem to be not possible but I just confirmed it IS so. I did not have a ready 3v3 available so used 2 X AA for 3.215V. Close enough for this exercise.Removed the hysteresis and similar result.

Checked TI data sheet and definitely says operates 2V to 36V.

Maybe the third line here is the clue.

Tried 5V on the Chip.
That did it. now with 100k reconnected . The circuit now works as predicted in my above post allowing for the slightly lower 3V3.
Results. Switches at VSYS = 3.09V with VSYS falling and 3.59V with VSYS rising which is very close to my original prediction.

So there is nothing wrong with your original circuit. The 1k you added in series with 3k3 just moves the switching point, the amount of hysteresis remains the same.

I did not try with 3V3 on the IC as it seemed to misbehave at about 3V5 VSYS I did not bother.

It would seem that TI have led us astray somewhat. The data sheet covers LM393"N" and the chip I used was a LM393"N". So I don’t know

Maybe the LM"V"393 might perform at the lower voltage. I don’t have one to try. But it looks as if you need to find 5V from somewhere for this variety to be really successful.

Bu the way the LED DOES affect the open circuit voltage at Pin 1 but a 10k resistor across the LED as I suggested fixed that potential problem.

Be a bit careful with a load resistor at Pin 1 as the max allowable current for the transistor is 16mA. But at 3V3 you are not likely to run into any problem. You should be aware of this for future use though.

You may notice that I recorded VSYS switching points and not Pins 2 & 3. After switching has occurred what voltage is on pin 3 does not mean much as the Hystereses has taken over and modified this. It is very quick and pretty impossible to record the actual switching voltage with a multimeter as the positive feedback in pretty much instantaneous.

If the hystereses is too much increasing the 100k resistor will lessen it. I would not go below 100k as if you try for too much other odd things can happen.

You don’t have to use a dedicated comparator here. A Rail to Rail OP Amp will do the job. An LM6482 might do the job. Very low power CMOS and is happy at 3V3 I have tried it as a Schmidt trigger (what is exactly what you are doing) at 3V3 to clean up rotary encoder switching and it appears OK. Readily obtainable at the right price. You will have to rethink your output, it id NOT open collector and the output is DRIVEN high and low. Your circuit and pin connections are exactly the same.
Cheers Bob

2 Likes

Hi Bob,

Built the most recent circuit on a breadboard, it performed the same as the vero board. ie not working properly.

The circuit stopped working correctly when I decided to connect the LM393 positive supply to 3v3 rather than VSYS, because VSYS changes as the LiPo discharges. I connected it back to VSYS and the comparator now switches correctly. VSYS = 4.1v.

Using a 10 turn pot I was able to move the voltage, on pin 3, past the trigger points and it switched high and low at the calculated voltages. (or close enough)

As you mentioned, the datasheet lists supply voltage as 2v to 36v. Maybe it’s the particular chip I am using but it does not want to work at 3.3v but seems to work ok above 3.5v. I will edit my original post to reflect this.

I agree with you about the LED, it definitely has an effect on the circuit operation and I will remove it in my post.

Thanks for helping me work though this.
Cheers
Jim

Hi James

That is what I found.
Switching at 4V1 will not be much good will it?? That is almost a fully charged Lipo (4V2). I would try the suggested LM6842 as it is readily available (Jaycar) and a drop in replacement with no changes except to the output circuitry required.
Cheers Bob
Add on
No real changes to the output circuitry either if you want some sort of indicator. The LED and /or pull ups not required to drive the GPIO as the output is driven high and low.

1 Like

Hi James
Just tried an LM6482. Works perfectly at 3V3 on the IC (or 2 x AA). Switches at exactly the same points as the LM393 did with 5V on the IC.
That one would work for you.
Cheers Bob

1 Like

Hi Bob,

Thanks for checking.
I will get a LMC6482 and LM358 next time in Jaycar. Usually buy 2 or 3 for parts bin.
The LMC6482 is expensive at $13.95, if the low power LM358 works ($2.95) it will be my go to.

The LM393 stops working at 3.522V supply, works ok at 3.523V, interesting.
The LM393 is triggered when the LiPo reaches reaches 3.58V. I didn’t check the pin voltages.
This will work well for what I want to do.
Also, using the higher value feedback resistor places the trigger points where they should be.

Thanks for your help.
Cheers
Jim

Hi James

Last time I bought these it was $5.95. Seems to have gone up radically. Interestingly the Quad version (LM6484) is only $5.97. I wonder if it s a mistake.

The data sheet for a LM393 says the working input voltage is max V+ - 1.5 so your circuit would fall outside that range. You could operate the chip at 3V3 and lower the reference and input voltages to fall within the stated range.

The centre point of the trigger range with your original values will be 3V3 as both resistor dividers are the same. Raising the feedback value brings the hysteresis points closer to the centre. To change the centre point change the VIN resistor divider ratio.

I doubt if it will. Even if it does it will be marginal driving GPIO. The data sheet says max output voltage with 5V VCC is 3V5 which is 1V5 below VCC. That means with VCC at 3V3 the max output will be 1V8. Methinks not high enough for reliable operation.
Cheers Bob

1 Like

You are right, checking data sheets RP2040 GPIO Voltage High minimum is 2V.
LM358 3.3V -1.5 = 1.8V.

Think I will save my money and not worry about this one.
The LMC6482 you tested is the one.
Will see what Jaycar charge for it, their web site could be wrong.

Cheers
Jim

Hi James
I had a look at Altronics a while ago and they don’t seem to stock this LM6482. Not on their web site anyway. If you are near one of their stores the web site might be wrong.

This Op Amp has a very high input resistance, 10TΩ, so ground the unused inputs (5 & 6) and be a little careful with input layouts. I don’t think you need to go to the extremes as suggested in the Data sheet though. I had it operating quite OK on a breadboard.

If you want another output for any reason connecting the 2nd amp as a voltage follower will give you another low impedance output without interfering at all with the GPIO input. You could even connect your LED indicator to this output leaving nothing but the GPIO pin (and Pin5 if you go down this path) connected to Pin 1.

Connect VCC to 3V3, not VSYS and you should all be good.
Cheers Bob
EDIT. Sorry James that is LMC6482.

1 Like