Maker Pro
Maker Pro

Measuring battery voltage with an MCU while charging and discharging

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
At this point, all I can tell you is that unless you have a common ground, your voltage divider scheme won't work. And if you have a common ground the series connection won't work.

Perhaps you need to describe exactly what you want to do so we can suggest how you can do it rather than you chase two mutually incompatible ideas in separate threads.

Why do you need to separate the batteries?

I fugured this much (it wont work). Thats why its such a problem. I need to seprate the batteries, so I can charge them separately with 2 charges. In this block diagram I explain the problem well. Also the comparator circuit picture for 2 batteries is uploaded. I have the same problem on it. The switch will separate the batteries and connect them in series. But this will affect the dividers of the comparator circuits?

There will be no ground! The bottom battery's "-" can be taken as ground.
 

Attachments

  • 2.batteries.off.on.block.diagram.jpg
    2.batteries.off.on.block.diagram.jpg
    210.8 KB · Views: 55
  • Switch.batteries.comparators.pdf
    106.7 KB · Views: 33
Last edited:

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Why do you need to separate them to use the two chargers? Do they have a common outputs connection (is one side grounded)?
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
You need to check if either output lead is connected to any input connection. The most likely one would be the earth connection.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Do you have a multimeter?

With the charger unplugged, but the power switch turned on, use the resistance range to measure between each battery charge terminal and each power cord terminal. That will be 6 readings in total.

Ensure you do not see continuity (or a low resistance) on any of these.
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
I think I can make it clearer of what I was thinking and what the problem is:

To calirify my original idea and problem, I make this post:

Originally I knew that I could not measure the batteries both in series and disconnected one from another because I would have to measure compared to ground (ground was taken as the lower battery’s “-” and I knew that would not work. So I started thinking what would the PCB layer for ground do, can it be used in order to measure compared to it or not, I guess it can not, because its connected to the lower battery’s “-”, even if there are 2 layers for ground they will be connected at 1 point and then connected to the lower battery’s minus. I decided I cant have 2 layers to each of the battery’s “-” because the 2 batteries will be connected in series also and that will be a short circuit if the 2 gorund layers have to connect to each other. (this is from where my ground concept lack of knowledge come).

I finally found the answer here:
http://forum.arduino.cc/index.php?topic=21526.0

On post 2, they mention a virtual ground used for the MCU in order to compare each battery to the MCU virtual ground. This is what I needed, like I though before a separate ground might work.
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
This is my last thinking. If possible :D. And I intend to shoot myself :D.
 

Attachments

  • Last.idea.jpg
    Last.idea.jpg
    140.2 KB · Views: 79

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Obviously you need 2 ADC pins for that circuit, and the common ground is the because of the bottom battery.

Both voltage dividers present approx 1/10 of the voltage to the ADC. I'm not sure why you used different value resistors.

You can calculate the voltage on the bottom battery, and the voltage on both batteries using this circuit. Subtracting one from the other will give you the voltage on the top battery.
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
This is the idea, to substract the voltage of the lower battery from the whole bank. But can it work? Will it be a problem if the batteries are charging at the moment with 2 charger?
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
What do you think about the second idea?
 

Attachments

  • Circuit.with.relays.png
    Circuit.with.relays.png
    103.7 KB · Views: 59

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
What do you think about the second idea?

Awful for more reasons than I can probably fit into a single reply.

You're powering the relays from different batteries leading to the need for a much higher voltage being needed to switch one transistor than the other.

A side effect of the same thing is that you would likely have the base emitter junction of one transistor reverse biased to the point of it being in breakdown.

One relay is not even powered.

You leave the voltage dividers connected to the batteries when they're not in use (and have multiple voltage dividers -- there may be safety reasons to do something like this, but you're not doing it.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
This is the idea, to substract the voltage of the lower battery from the whole bank. But can it work? Will it be a problem if the batteries are charging at the moment with 2 charger?

Subtraction is a mathematical operation which has been proven effective over many years as a method of getting the difference between two values.

You need to take the readings as close as possible to simultaneously so there is the smallest chance that the voltage across the batteries will change during the measurement process.
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
I changed the relay circuit a bit maybe now its better :D.

Here is the circuit for isolated power supplies (if the power supplies are isolated, the batteries can be charged while still connected in series). It should work. However I am certain that it willl not be that good, most likely both chargers are plugged to 1 extender, so I dont hope for isolated power supplies. What should I do in that case? (Maybe something like a rail splitter, so I can have a second ground compared to which to measure. Or some OPAMP in order to measure only the voltage drop over the resistor of the upper battery.

I post the files as an external link, because they are too big.

https://www.dropbox.com/s/r6hrg1h8k0xatms/66.V.1.2.jpg?dl=0
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
No, that won't work.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
I'll try to draw something up later
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
Here is the simplest way:

upload_2018-4-1_21-31-25.png

If you use 2 ADC ports then you can either simultaneously read them both, or read them one after the other VERY quickly. This will give you the bottom battery voltage and the total battery voltage . Subtracting the bottom battery voltage from the total battery voltage gives you the upper battery voltage.

Note that the MCU and the bottom battery share the same ground.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
The other (simple) way is to have a completely independent power source for the MCU. This MUST have a separate (i.e. not connected) ground. In the diagram they are shown in different colours.

upload_2018-4-1_21-52-15.png

For simplicity I've shown relays being used, but you could do this in other ways.

Note that with both relays off, no current will flow through the voltage divider and the ADC pin will show 0V.

Pulling in relay 1 will show the voltage on the top battery. Pulling in relay 2 will show the voltage on the bottom battery. Pulling in both relays will show you the total battery voltage. No combination of actions will short anything out.

Note that Vmcu CANNOT be derived from the batteries to the left.
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
Thank you very much for the help!

Which part will not work, the my new relay circuit, the isolated power supplies, the rail splitter?

As for your second circuit: Its the only option since I have 1 ADC pin and 9 digital I/O pins.
I thought of this too, but how to make a separate ground (not connect the MCU ground to anything)? At first I was thinking of making a separate not connected to anything PCB layer only for this ground, than I was thinking of connecting a wire to the MCU ground and the metal frame of the battery bank, or somehow implement a rail splitter, or somehow measure only the voltage drop over the resistor of the divider of the upper battery, so no matter if they are in series or not, the voltage drop over the resistor will be the same?
 

YoTech

Mar 21, 2018
41
Joined
Mar 21, 2018
Messages
41
This is my power supply for the MCU and if I need something else. Its tested and it works.
 

Attachments

  • Power.supplies.3.3V.5V.12V.24V.adjustable.LM2576-1.jpg
    Power.supplies.3.3V.5V.12V.24V.adjustable.LM2576-1.jpg
    129 KB · Views: 36
Top