Great work and thank you for sharing this. I am pretty new to LTSpice but I am looking to model and emulate the behavior of LiPo batteries in a bigger circuit. And this was a perfect start!
@miketrupiano7232 I have tried it but doesn't quite work. I am trying to use it for an active cell balancing system and I want to see some cells in the string lose charge and others gain charge. I connected two in series but the upper battery produces only 2.5V, while the lowere referenced to ground produces correctly the voltage. Ergo why I asked the question. I am using LTSpice with looser convergence parameters and 3% error rtol to help it. Any ideas?
The battery capacity cap increases by the number of cells. The output voltage sources and impedances increase by the number of cells. You could try just copy-paste more of them and see if it simulates or do the math by hand and change the simulation values. I haven't tried it but maybe it will work.
For this particular simulation it won't matter, but the cool part is they can be changed and the transient load response of the model can be simulated.
@@sampathkumar4773 for the purpose of this simulation the self discharge is not a significant factor. Given that, here is a simplistic way to look at it. Let's say in three months the battery drops from 3.7 to 3.48 volts. If the battery capacity is represented by 18000F and takes 7.8E6 seconds to drop from 3.7 to 3.48 volts then R has to be about 7.4K ohms. You could create your own RC discharge spice simulation to show this or use a calculator like this one. www.circuits.dk/calculator_capacitor_discharge.htm
In general, it is not good to let the battery go below 2V so any remaining capacity can't be used. There is very little charge left there anyhow. So it is common to refer to that a 0% SOC. Also look at RelativeSOC, or useable battery capacity. To make the model shown here work, battery data down to OCV=0 is used.
Hi Mike, Thanks for the video, very informative and helpful! I have some questions, the first one is: What exactly is "state of charge" and can it be measured in reality (like can we know what the soc of a battery is in reality)? how did you determine the values of vsoc and voc for the table? and the second: how did you determine the values of R1, R2, R3, R5, R6 and L1? thx in advance!
I think the short answer is yes. If you want to really go in depth, I put a couple links in the description as a place to start. I'm not a chemist and battery models are getting quite intricate these days. There was a time when the model I show here would have been beyond what most people were even aware of. With batteries having become the biggest area of needed improvement and focus this is not so any longer.
For this video I made up the table for E1 then using Excel I derived a formula fitting the table to use for B2. In real life, this could come from test data or a battery data sheet.
Thank you for explaining and showing the model. 1. Can you please tell me how charging of battery can be simulated using this? This model shows only discharging of battery. 2. Also how can I calculate battery SOC from this? Thank you so much sir.
Hi! I've been searching for a proper battery sim in ltspice for literally ages. Thanks a ton!!!! Is it possible that I can get the spice files from you?
I uploaded a minimal version of the LTspice drawing here: scientist.cloud/LiPo.asc. Enough to get you going hopefully. Not sure if it helps this late, your post is 3 months old, but you never know :)
Great work and thank you for sharing this. I am pretty new to LTSpice but I am looking to model and emulate the behavior of LiPo batteries in a bigger circuit. And this was a perfect start!
Very nice work, thank you!
Thank you !! Great Job !
Thank you for your video. Have you tried putting this model in series to say 2 or 3 in series? Would it work?
It should work, but how well can vary with spice. Sometimes it can be tricky to make a simulation converge. I haven't had problems with this one.
@miketrupiano7232 I have tried it but doesn't quite work. I am trying to use it for an active cell balancing system and I want to see some cells in the string lose charge and others gain charge. I connected two in series but the upper battery produces only 2.5V, while the lowere referenced to ground produces correctly the voltage. Ergo why I asked the question. I am using LTSpice with looser convergence parameters and 3% error rtol to help it. Any ideas?
@@robr8554 I don't think I tried that. Might be tricky. If you have a way to share it, I could take a look. No promise of success though.
@@miketrupiano7232 awesome 👌
Thanks for the informative video, Mike! Any thoughts on how you might connect multiple such models in series to simulate a battery stack?
The battery capacity cap increases by the number of cells. The output voltage sources and impedances increase by the number of cells. You could try just copy-paste more of them and see if it simulates or do the math by hand and change the simulation values. I haven't tried it but maybe it will work.
Thank you. If I make 3,3V*(your expression) how the capacity remains ? Again 5Ah?
thank you.. great work.. just one comment, the C1 and C2 seem on the low side.. a few thousands F makes it more realistic
For this particular simulation it won't matter, but the cool part is they can be changed and the transient load response of the model can be simulated.
Hey! Thanks for the video. Can I know what's the pwr you have included in the formula. Also, vsoc means the different voltages on the discharge curve?
The current set by I1 or I2 is the load. In this case, constant current. Vsoc represent State of Charge.
@@miketrupiano7232 Thanks. Also, how did you get the values of transient R and C?
@@sampathkumar4773 I made up values so the simulation would look about right. They didn't come from a real battery.
@@miketrupiano7232 Thanks. Any idea on how to calculate the self discharge resistor? The datasheet has value in terms of %
@@sampathkumar4773 for the purpose of this simulation the self discharge is not a significant factor. Given that, here is a simplistic way to look at it. Let's say in three months the battery drops from 3.7 to 3.48 volts. If the battery capacity is represented by 18000F and takes 7.8E6 seconds to drop from 3.7 to 3.48 volts then R has to be about 7.4K ohms. You could create your own RC discharge spice simulation to show this or use a calculator like this one. www.circuits.dk/calculator_capacitor_discharge.htm
Sometime manufactors of Li 3,3V Battery says SOC=0 when VOC=2V. How can made this on your model?
In general, it is not good to let the battery go below 2V so any remaining capacity can't be used. There is very little charge left there anyhow. So it is common to refer to that a 0% SOC. Also look at RelativeSOC, or useable battery capacity. To make the model shown here work, battery data down to OCV=0 is used.
Hi Mike,
Thanks for the video, very informative and helpful!
I have some questions, the first one is:
What exactly is "state of charge" and can it be measured in reality (like can we know what the soc of a battery is in reality)? how did you determine the values of vsoc and voc for the table?
and the second:
how did you determine the values of R1, R2, R3, R5, R6 and L1?
thx in advance!
Thanks. Also your last reply sent as its own comment instead of a reply to the person you meant to send it to
Thanks.
Hi Mike,
Interesting work
I can you please send me the LTspice file for this simulation?
I don't know how I could get the file to you.
Does this roughly approximate battery chemistry delay?
I think the short answer is yes. If you want to really go in depth, I put a couple links in the description as a place to start. I'm not a chemist and battery models are getting quite intricate these days. There was a time when the model I show here would have been beyond what most people were even aware of. With batteries having become the biggest area of needed improvement and focus this is not so any longer.
Copy the below text into your favorite text editor (notepad) and save it with the file extention .ASC and it will open into LTspice.
Version 4
SHEET 1 2012 1412
WIRE 48 64 -16 64
WIRE 176 64 112 64
WIRE 288 64 240 64
WIRE 416 64 352 64
WIRE -640 128 -848 128
WIRE -528 128 -640 128
WIRE -432 128 -528 128
WIRE -112 128 -160 128
WIRE -16 128 -16 64
WIRE -16 128 -112 128
WIRE 176 128 176 64
WIRE 240 128 240 64
WIRE 240 128 176 128
WIRE 416 128 416 64
WIRE 560 128 416 128
WIRE 752 128 640 128
WIRE 1552 128 832 128
WIRE -16 176 -16 128
WIRE 48 176 -16 176
WIRE 176 176 176 128
WIRE 176 176 128 176
WIRE 240 176 240 128
WIRE 288 176 240 176
WIRE 416 176 416 128
WIRE 416 176 368 176
WIRE 1552 272 1552 128
WIRE -640 304 -640 128
WIRE -432 304 -432 128
WIRE -848 320 -848 128
WIRE -160 320 -160 128
WIRE -848 480 -848 384
WIRE -640 480 -640 384
WIRE -640 480 -848 480
WIRE -432 480 -432 384
WIRE -432 480 -640 480
WIRE -160 480 -160 400
WIRE -160 480 -432 480
WIRE 288 480 -160 480
WIRE 1552 480 1552 336
WIRE 1552 480 368 480
WIRE -848 512 -848 480
WIRE 64 944 0 944
WIRE 192 944 128 944
WIRE 304 944 256 944
WIRE 432 944 368 944
WIRE -624 1008 -832 1008
WIRE -512 1008 -624 1008
WIRE -416 1008 -512 1008
WIRE -256 1008 -416 1008
WIRE -96 1008 -144 1008
WIRE 0 1008 0 944
WIRE 0 1008 -96 1008
WIRE 192 1008 192 944
WIRE 256 1008 256 944
WIRE 256 1008 192 1008
WIRE 432 1008 432 944
WIRE 576 1008 432 1008
WIRE 768 1008 656 1008
WIRE 1568 1008 848 1008
WIRE 0 1056 0 1008
WIRE 64 1056 0 1056
WIRE 192 1056 192 1008
WIRE 192 1056 144 1056
WIRE 256 1056 256 1008
WIRE 304 1056 256 1056
WIRE 432 1056 432 1008
WIRE 432 1056 384 1056
WIRE 1568 1152 1568 1008
WIRE -624 1184 -624 1008
WIRE -416 1184 -416 1008
WIRE -832 1200 -832 1008
WIRE -144 1200 -144 1008
WIRE -256 1216 -256 1008
WIRE -192 1216 -256 1216
WIRE -192 1264 -256 1264
WIRE -832 1360 -832 1264
WIRE -624 1360 -624 1264
WIRE -624 1360 -832 1360
WIRE -416 1360 -416 1264
WIRE -416 1360 -624 1360
WIRE -256 1360 -256 1264
WIRE -256 1360 -416 1360
WIRE -144 1360 -144 1280
WIRE -144 1360 -256 1360
WIRE 304 1360 -144 1360
WIRE 1568 1360 1568 1216
WIRE 1568 1360 384 1360
WIRE -832 1392 -832 1360
FLAG -848 512 0
FLAG -528 128 vsoc
FLAG -832 1392 0
FLAG -512 1008 vsoc1
FLAG -96 1008 batt1
FLAG -112 128 batt
SYMBOL res 144 160 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R1
SYMATTR Value 0.1
SYMBOL res 384 160 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R2
SYMATTR Value 0.1
SYMBOL res 656 112 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R3
SYMATTR Value 0.1
SYMBOL cap 112 48 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C1
SYMATTR Value 1000p
SYMBOL cap 352 48 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C2
SYMATTR Value 10u
SYMBOL res -656 288 R0
SYMATTR InstName R5
SYMATTR Value 10k
SYMBOL cap -864 320 R0
SYMATTR InstName C3
SYMATTR Value 18000
SYMBOL bi -432 304 R0
SYMATTR InstName B1
SYMATTR Value I=I(R6)
SYMBOL res 384 464 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R6
SYMATTR Value 1m
SYMBOL bv -160 304 R0
WINDOW 3 58 70 Left 2
SYMATTR Value V=(-8.0128*pwr(V(vsoc),5) + 22.509*pwr(V(vsoc),4) - 19.929*pwr(V(vsoc),3) + 4.332*pwr(V(vsoc),2) + 2.0965*V(vsoc) + 0.0026)
SYMATTR InstName B2
SYMBOL ind 736 144 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 5 56 VBottom 2
SYMATTR InstName L1
SYMATTR Value 1n
SYMBOL load 1536 272 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName I1
SYMATTR Value 1
SYMBOL res 160 1040 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R4
SYMATTR Value 0.1
SYMBOL res 400 1040 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R7
SYMATTR Value 0.1
SYMBOL res 672 992 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R8
SYMATTR Value 0.1
SYMBOL cap 128 928 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C4
SYMATTR Value 1000p
SYMBOL cap 368 928 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C5
SYMATTR Value 10u
SYMBOL res -640 1168 R0
SYMATTR InstName R9
SYMATTR Value 10k
SYMBOL cap -848 1200 R0
SYMATTR InstName C6
SYMATTR Value 18000
SYMBOL bi -416 1184 R0
SYMATTR InstName B3
SYMATTR Value I=I(R10)
SYMBOL res 400 1344 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R10
SYMATTR Value 1m
SYMBOL ind 752 1024 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 5 56 VBottom 2
SYMATTR InstName L2
SYMATTR Value 1n
SYMBOL load 1552 1152 R0
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName I2
SYMATTR Value 1
SYMBOL e -144 1184 R0
SYMATTR InstName E1
SYMATTR Value table(0 0, 0.1 0.25, 0.3 0.65, 0.4 0.77, 0.5 0.79, 0.6 0.8, 0.7 0.82, 0.8 0.85, 0.9 0.9, 1 1)
TEXT 200 -72 Left 2 !.tran 18000
TEXT -928 416 VLeft 2 ;Ccapacity
5Ahr battery
TEXT -184 -40 Left 2 ;Short and long time constant transient response, and instantaneous voltage drop, wire inductance.
Randles model can't be done in spice.
TEXT 248 416 Left 2 ;sense resistor
TEXT -136 432 Left 2 ;Voc
TEXT -552 88 Left 2 !.ic V(vsoc)=1
TEXT -768 584 Left 2 ;Ccapacity = 3600*Capacity(Ahr)*f1(Cycle)*f2(Temp)
vsoc initial condition of 1V is 100% SOC, 0V is 0% SOC
cycle number and temperature not factored in here
1amp=1coul/sec
Q=C x V ( coulomb=capacitance x voltage)
so how many Coulombs in a 5Ahr battery?
5Ahr = (5 C/S) x 1Hr = 3600 S/Hr x 5C/S x 1Hr = 18000C = 18000F x 1V
TEXT -680 416 VLeft 2 ;Rselfdischarge
TEXT 928 544 Left 2 ;Polynomial derived from this table
vsoc voc
1 1
0.9 0.9
0.8 0.85
0.7 0.82
0.6 0.8
0.5 0.79
0.4 0.77
0.3 0.65
0.2 0.45
0.1 0.25
0 0
TEXT -120 1312 Left 2 ;Voc
TEXT -544 968 Left 2 !.ic V(vsoc1)=1
Sir, how do you get the formula for B2 voltage source, is it based on experimental test results ?
For this video I made up the table for E1 then using Excel I derived a formula fitting the table to use for B2. In real life, this could come from test data or a battery data sheet.
Thank you for explaining and showing the model.
1. Can you please tell me how charging of battery can be simulated using this? This model shows only discharging of battery.
2. Also how can I calculate battery SOC from this?
Thank you so much sir.
experiment with turn current source I1 the other direction. The voltage on C3 is related to SOC.
en.wikipedia.org/wiki/State_of_charge
Version 4
SHEET 1 2012 1412
WIRE 48 64 -16 64
WIRE 176 64 112 64
WIRE 288 64 240 64
WIRE 416 64 352 64
WIRE -640 128 -848 128
WIRE -528 128 -640 128
WIRE -432 128 -528 128
WIRE -112 128 -160 128
WIRE -16 128 -16 64
WIRE -16 128 -112 128
WIRE 176 128 176 64
WIRE 240 128 240 64
WIRE 240 128 176 128
WIRE 416 128 416 64
WIRE 560 128 416 128
WIRE 752 128 640 128
WIRE 1552 128 832 128
WIRE -16 176 -16 128
WIRE 48 176 -16 176
WIRE 176 176 176 128
WIRE 176 176 128 176
WIRE 240 176 240 128
WIRE 288 176 240 176
WIRE 416 176 416 128
WIRE 416 176 368 176
WIRE 1552 256 1552 128
WIRE -640 304 -640 128
WIRE -432 304 -432 128
WIRE -848 320 -848 128
WIRE -160 320 -160 128
WIRE -848 480 -848 384
WIRE -640 480 -640 384
WIRE -640 480 -848 480
WIRE -432 480 -432 384
WIRE -432 480 -640 480
WIRE -160 480 -160 400
WIRE -160 480 -432 480
WIRE 288 480 -160 480
WIRE 1552 480 1552 336
WIRE 1552 480 368 480
WIRE -848 512 -848 480
FLAG -848 512 0
FLAG -528 128 vsoc
FLAG -112 128 batt
SYMBOL res 144 160 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R1
SYMATTR Value 0.1
SYMBOL res 384 160 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R2
SYMATTR Value 0.1
SYMBOL res 656 112 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R3
SYMATTR Value 0.1
SYMBOL cap 112 48 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C1
SYMATTR Value 1000p
SYMBOL cap 352 48 R90
WINDOW 0 0 32 VBottom 2
WINDOW 3 32 32 VTop 2
SYMATTR InstName C2
SYMATTR Value 10u
SYMBOL res -656 288 R0
SYMATTR InstName R5
SYMATTR Value 1Meg
SYMBOL cap -864 320 R0
SYMATTR InstName C3
SYMATTR Value 18000
SYMBOL bi -432 304 R0
SYMATTR InstName B1
SYMATTR Value I=I(R6)
SYMBOL res 384 464 R90
WINDOW 0 0 56 VBottom 2
WINDOW 3 32 56 VTop 2
SYMATTR InstName R6
SYMATTR Value 1m
SYMBOL bv -160 304 R0
WINDOW 3 58 70 Left 2
SYMATTR Value V=(-8.0128*pwr(V(vsoc),5) + 22.509*pwr(V(vsoc),4) - 19.929*pwr(V(vsoc),3) + 4.332*pwr(V(vsoc),2) + 2.0965*V(vsoc) + 0.0026)
SYMATTR InstName B2
SYMBOL ind 736 144 R270
WINDOW 0 32 56 VTop 2
WINDOW 3 5 56 VBottom 2
SYMATTR InstName L1
SYMATTR Value 1n
SYMBOL current 1552 336 R180
WINDOW 0 24 80 Left 2
WINDOW 3 24 0 Left 2
WINDOW 123 0 0 Left 0
WINDOW 39 0 0 Left 0
SYMATTR InstName I1
SYMATTR Value PWL(0 .1 100 1 15900 1 16000 0)
TEXT 200 -72 Left 2 !.tran 25000
TEXT -928 416 VLeft 2 ;Ccapacity
5Ahr battery
TEXT 248 416 Left 2 ;sense resistor
TEXT -136 432 Left 2 ;Voc
TEXT -552 88 Left 2 !.ic V(vsoc)=0.2
TEXT -680 416 VLeft 2 ;Rselfdischarge
Hi! I've been searching for a proper battery sim in ltspice for literally ages. Thanks a ton!!!! Is it possible that I can get the spice files from you?
Your welcome. I don't know how I would get the files to you. It would take a little time but they can be redrawn from what's in the video.
I uploaded a minimal version of the LTspice drawing here: scientist.cloud/LiPo.asc. Enough to get you going hopefully. Not sure if it helps this late, your post is 3 months old, but you never know :)
@@Torxed Thanks, helped a lot
@@Torxed thank you so much!