N1-Simulating Battery Packs
N1-Simulating Battery Packs
N1-Simulating Battery Packs
! Hysteresis voltage:
! ˇ ˇ" ! ! ˇ ˇ""
ˇ !k ik #"t ˇ ˇ !k ik #"t ˇ
hkC1 D exp " ˇ Q ˇ hk C 1 " exp " ˇ Q ˇ sgn.ik /.
■ Note that the circuit can contain more than a single parallel
resistor-capacitor pair. We can define vector valued
2 ! " 3 2! ! "" 3
""t ""t
exp R1 C1 0 ### 1" exp R1 C1
6 ! " 7 6! ! "" 7
6 7 6 7
iR;kC1 D 4 5 iR;k C 4 1" exp R2 C2 5 ik .
""t ""t
0 exp R2 C2
::: ::: :::
„ ƒ‚ … „ ƒ‚ …
ARC BRC
! ˇ ˇ"
ˇ !k ik #"t ˇ
■ Then, if we define AHk D exp " ˇ Q ˇ ,
2 3 2 32 3 2 3
´kC1 1 0 0 ´k 0 " # " !kQ"t
6 7 6 76 7 6 7 ik
i D
4 R;kC1 5 4 0 A RC 0 i C
5 4 R;k 5 4 RC
B 0 5 .
sgn.ik /
hkC1 0 0 AHk hk 0 .1"AHk /
„ ƒ‚ … „ ƒ‚ …
A.ik / B.ik /
h iT
■ If we define xk D ´k iRTk hk , then we have
xkC1 D A.ik /xk C B.ik /ik .
■ This is the ESC “state equation”, and describes all dynamic effects.
■ The “output equation” is
X
vk D OCV.´k / C M hk " Ri iRi ;k " R0ik .
i
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–4
h i
■ We can define C D 0; "R1; "R2; : : : M and D D "R0 to arrive
at
vk D OCV.´k / C C xk C Dik .
■ So, we conclude that the ESC model looks similar to, but not identical
to, a linear state-space system of the form
xkC1 D Ak xk C Bk ik
yk D Ck xk C Dk ik .
! The dependencies of Ak and Bk on ik , and the OCV term in the
output make the equations nonlinear.
! Still, the nonlinear state-space form is conducive to applying
control-systems concepts, which we do in the following chapters.
■ ECE5710 talked about how to find the unknown model parameter
values, so we omit that discussion here.
! Finding the model:
Cell
Current
Initial Predicted
simCell.m
State Voltage
ESC Cell
Model
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–5
2.2: Modeling approach #2: Physics-based
■ Continuum porous-electrode models use physics to derive equations
for all internal cell processes using coupled PDEs.
Negative electrode Positive electrode
Current collector
Current collector
Separator
r
x
r # .%effr$s / D as F j .
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–6
r # .&effr$e C &D;effr ln ce / C as F j D 0.
1
In simulations, we have found that the second assumption is quite good. The first
assumption is less good, but nonlinear corrections help improve linear predictions.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–7
■ A pictorial overview of the two process steps is:
Computational process
Data
Analytic derivations
System Physics Execute Linear SS
ID/tests parameters DRA model
Lab process
Step 1: Step 2: Step 3: Step 4: hŒn' to
H.s/ to h.t / h.t / to hstep .t / hstep .t / to hŒn' b B,
A, b C b, D
b
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–8
2.3: Simulating an electric vehicle
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–9
■ The vehicle task is characterized by a “drive cycle”: a profile of
desired vehicle speed versus time. Some examples:
■ These four drive cycles are provided to you on the course web site.
They have a 1 Hz profile rate, which will be assumed below.
80 80
Speed (km h )
Speed (km h )
−1
−1
60 60
40 40
20 20
0 0
0 5 10 15 20 25 0 2 4 6 8 10 12 14
Time (min) Time (min)
Speed (km h )
100
−1
−1
30
80
20 60
40
10
20
0 0
0 2 4 6 8 10 0 2 4 6 8 10
Time (min) Time (min)
■ All drive cycles are simulated using the same basic equations.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–10
■ The approach is to compute, on a second-by-second basis, desired
accelerations to match the desired speed profile, therefore desired
road forces, therefore desired motor torques and power values.
■ These desired torques and power values are restricted by the
specifications of the motor chosen for the vehicle, and thus
achievable torques and power values may be of lesser magnitude.
■ Achievable torques are computed, and therefore achieved road force,
and achieved velocity (this will not always match the desired velocity).
■ Battery power is computed based on motor power, and battery SOC
is updated.
■ Over the course of the driving profile, the battery SOC is depleted a
certain amount, and the projected range of the vehicle is extrapolated
from this data.
Typical AC induction motor characteristic
■ We use a three-phase AC 300
Constant Constant power region
induction motor model, which 250
torque
region
Torque (N m)
200
limits torque and power based on
150
three design constants: 100
maximum torque, rated RPM, and 50
Rated RPM Maximum RPM
maximum RPM. 0
0 2000 4000 6000 8000 10000 12000
Speed (RPM)
■ Overall simulation flowchart calculations:
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–11
2.4: Equations for vehicle dynamics
■ The equivalent mass combines the maximum vehicle mass and the
equivalent mass of the rotating inertias
2
Vehicle modeling equations are from T. Gillespie, “Fundamentals of Vehicle Dynamics,”
Society of Automotive Engineers Inc, 1992.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–12
■ Other forces acting on the vehicle are assumed to comprise:
1
aerodynamic force ŒN' D .air density ( Œkg m"3'/$.frontal area Œm2'/$
2
.drag coefficient Cd Œunitless'/ $ .prior actual speed Œm s"1'/2
! If prior actual motor speed is less than rated motor speed, then the
maximum available torque is the rated maximum available torque;
! Otherwise, the maximum available torque is computed as (rated
maximum available torque ŒN m') $ (rated motor speed ŒRPM') /
(prior actual motor speed ŒRPM').
■ When negative torque (deceleration) is demanded, torque demand is
split between friction brakes (assumed infinitely powerful) and motor.
■ Energy recovered from the motor replaces energy depleted from the
battery (less inefficiency losses) in a “regeneration” event.
■ The maximum motor torque available for regeneration (in an unsigned
sense) is calculated as the minimum of the maximum available torque
for acceleration and a “regen fraction” times the rated maximum
available torque.
■ The limited torque at the motor is the lesser of the demanded motor
torque and the maximum available torque (in an unsigned sense).
■ Now that the motor torque limits have been established, we can
compute the actual acceleration force that is available, the actual
acceleration, and the actual velocity.
■ We can now compute the actual acceleration:
actual acceleration force ŒN' D limited torque at motor ŒN m' $
rolling force ŒN' " grade force ŒN' " brake drag [N]
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–14
■ The actual acceleration as just calculated may cause the motor to
spin at a higher angular velocity than it is rated for.
■ Therefore, we cannot compute actual speed as simply as follows:
actual speed Œm s"1' D prior actual speed Œm s"1' C
■ Instead, we must compute a motor RPM first, then limit that RPM,
and then compute the actual vehicle speed.
test speed Œm s"1' D prior actual speed Œm s"1'C
■ The full circuit from desired to actual speed has now been described.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–15
2.5: Vehicle range calculations, example
where overhead power is the constant power drain from other vehicle
systems, such as air conditioners, “infotainment” systems etc.
■ If motor power is negative (regen), battery power is calculated as:
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–16
■ Assuming for now a constant battery voltage (a poor assumption),
battery SOC Œ%' D prior battery SOC Œ%' " battery current ŒA' $ 1 Œs'=
.max. rated battery SOC Œ%' " min. rated battery SOC Œ%'/=
Sample code
EV simulation results
■ Some example results from the EV simulator using “Chevy Volt”
parameters and US06 drive profile:
US06 Battery Power Profile US06 Battery Current Profile
150 400
300
100
Battery power (kW)
200
50
100
0
0
−50 −100
−100 −200
0 2 4 6 8 10 0 2 4 6 8 10
Time (min) Time (min)
US06 Motor Demanded Power
US06 Motor Torque versus RPM
300
80
200
60
Torque (N m)
Frequency
100
40 0
−100
20
−200
0 −300
−100 −50 0 50 100 0 2000 4000 6000 8000 10000 12000
Demanded Motor Power (kW) Speed (RPM)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–18
2.6: Simulating constant power and voltage
xk D Ak"1xk"1 C Bk"1ik"1
■ Note that xk does not depend on ik —it depends on ik"1, ik"2; etc.
■ So, cell voltage comprises the “fixed” part, which does not depend on
the present cell current, and the “variable” part, "R0ik , which does
depend on present cell current.
■ Defining the fixed part to be vf;k , we have vk D vf;k " R0 ik .
■ Power equals voltage times current
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–19
■ This quadratic equation can be solved every time sample to
determine cell current to meet the power demand
q
2
vf;k ˙ vf;k " 4R0pk
ik D .
2R0
■ Sign of radical must be negative for positive overall cell voltage, so
q
2
vf;k " vf;k " 4R0pk
ik D .
2R0
Constant voltage simulation
Voltage (V)
SOC (%)
80
4.05
70
4
60
50 3.95
0 500 1000 1500 2000 2500 3000 0 500 1000 1500 2000 2500 3000
Time (s) Time (s)
Cell current versus time Cell power versus time
0 0
CC/CV CC/CV
CP/CV CP/CV
−2
−10
Current (A)
Power (W)
−4
−20
−6
−30
−8
−10 −40
0 500 1000 1500 2000 2500 3000 0 500 1000 1500 2000 2500 3000
Time (s) Time (s)
% --------------------------------------------------------------------
% Get ESC model parameters
% --------------------------------------------------------------------
maxtime = 3001; T = 25; % Simulation run time, temperature
q = getParamESC('QParam',T,model);
rc = exp(-1./abs(getParamESC('RCParam',T,model)));
r = (getParamESC('RParam',T,model));
m = getParamESC('MParam',T,model);
g = getParamESC('GParam',T,model);
r0 = getParamESC('R0Param',T,model);
maxV = 4.15; % maximum cell voltage of 4.15 V
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–21
% --------------------------------------------------------------------
% First, simulate CC/CV
% --------------------------------------------------------------------
storez = zeros([maxtime 1]); % create storage for SOC
storev = zeros([maxtime 1]); % create storage for voltage
storei = zeros([maxtime 1]); % create storage for current
storep = zeros([maxtime 1]); % create storage for power
z = 0.5; irc = 0; h = -1; % initialize to 50% SOC, resting
CC = 9; % constant current of 9 A in CC/CV charge
for k = 1:maxtime,
v = OCVfromSOCtemp(z,T,model) + m*h - r*irc; % fixed voltage
time = 0:maxtime - 1;
figure(1); clf; plot(time,100*storez); hold on
figure(2); clf; plot(time,storev); hold on
figure(3); clf; plot(time,storei); hold on
figure(4); clf; plot(time,storep); hold on
% --------------------------------------------------------------------
% Now, simulate CP/CV
% --------------------------------------------------------------------
z = 0.5; irc = 0; h = -1; % initialize to 50% SOC, resting
CP = 35; % constant power limit of 35 W in CP/CV charge
for k = 1:maxtime,
v = OCVfromSOCtemp(z,T,model) + m*h - r*irc; % fixed voltage
% try CP first
ik = (v - sqrt(v^2 - 4*r0*(-CP)))/(2*r0);
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–22
if v - ik*r0 > maxV, % too much!
ik = (v - maxV)/r0; % do CV instead
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–23
2.7: Simulating battery packs
Series-connected cells
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–24
3 Parallel Cells
Cell Cell Cell
connected in parallel.
Cell Cell Cell
(SCMs) in Parallel
Again, if cells differ, we will need to
3 Cell Groups
■ Cell Cell Cell SCM
Cell Cell Cell
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–25
■ By re-arranging, we find the PCM voltage
PNp vj;k
j D1 R0;j " ik
vk D PNp .
1
j D1 R0;j
■ All terms in this equation are known, so we can find vk and then from
it we can find all the ij;k .
■ Once we have the independent branch currents ij;k , we can update
the cell models associated with each cell.
■ When simulating SCM, the approach is very similar to simulating
PCM.
■ Each cell in a SCM has its own “fixed” and
“variable” parts.
■ All “fixed” parts sum together to get an
equivalent voltage source; all “variable” parts
sum together to get an equivalent resistance.
■ Each SCM collapses to something that looks
like a single high-voltage cell.
■ Then, the total lumped voltage of an SCM is v
j;k and the total lumped
resistance is R0;j .
■ The bus voltage is
PNp vj;k
j D1 R0;j " ik
vk D PNp .
1
j D1 R0;j
■ The SCM currents are then found as ij;k D .vj;k " vk /=R0;j .
■ With the currents through all cells now known, we can update all cell
models.
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–26
Example: Simulation of PCM
■ Here we look at an example simulation with Ns D 2 and Np D 3.
■ Cell SOCs are randomly initialized between 30 % and 70 %.
■ Cell R0 values are randomly initialized between 5 m* and 25 m*.
■ Cell capacities are randomly initialized between 4:5 Ah and 5:5 Ah.
■ The pack is repeatedly discharged until lowest cell hits 5 % and then
charged until highest cell hits 95 %. After 45 min, the pack rests.
■ Individual cell SOCs and PCM-average SOCs are shown below:
Cells in PCM 1 Cells in PCM 2
100 100
80 80
SOC (%)
SOC (%)
60 60
40 40
20 20
0 0
0 10 20 30 40 50 60 0 10 20 30 40 50 60
Time (min) Time (min)
Cells in PCM 3 Average SOC for each PCM
100 80
PCM 1
PCM 2
80 PCM 3
60
SOC (%)
SOC (%)
60
40
40
20
20
0 0
0 10 20 30 40 50 60 0 10 20 30 40 50 60
Time (min) Time (min)
50 50
Current (A)
Current (A)
0 0
−50 −50
−100 −100
0 10 20 30 40 50 60 0 10 20 30 40 50 60
Time (min) Time (min)
Cells in PCM 3 Max.-avg. SOC minus min.-avg. SOC
100 14
0 12
−50 11
−100 10
0 10 20 30 40 50 60 0 10 20 30 40 50 60
Time (min) Time (min)
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–28
Appendix: setupSimVehicle.m
% setup simulation of vehicle - pass on to simVehicle.m
function results = setupSimVehicle
global cell module pack motor drivetrain vehicle cycle results
files = {'nycc.txt','udds.txt','us06col.txt','hwycol.txt'};
fprintf('\n\nStarting sims...\n');
for theCycle = 1:length(files),
cycle = dlmread(files{theCycle},'\t',2,0);
results = simVehicle(vehicle,cycle,0.3);
range = (vehicle.drivetrain.pack.socFull - ...
vehicle.drivetrain.pack.socEmpty) /...
(vehicle.drivetrain.pack.socFull - ...
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–29
results.batterySOC(end)) * ...
results.distance(end);
fprintf('Cycle = %s, range = %6.1f [km]\n',files{theCycle},range);
end
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–30
pack.vmax = numSeries*module.numSeries*module.cell.vmax;
pack.vnom = numSeries*module.numSeries*module.cell.vnom;
pack.vmin = numSeries*module.numSeries*module.cell.vmin;
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–31
vehicle.Cd = Cd; % drag coeff
vehicle.A = A; % frontal area, m2
vehicle.weight = weight; % kg
vehicle.payload = payload; % kg
vehicle.overheadPwr = overheadPwr; % W
vehicle.curbWeight = weight + drivetrain.pack.weight;
vehicle.maxWeight = vehicle.curbWeight + payload;
vehicle.rotWeight = ((drivetrain.motor.inertia + ...
drivetrain.gearInertia) * ...
drivetrain.gearRatio^2 + ...
drivetrain.wheel.inertia*wheels)/...
drivetrain.wheel.radius^2;
vehicle.equivMass = vehicle.maxWeight + vehicle.rotWeight;
vehicle.maxSpeed = 2 * pi * drivetrain.wheel.radius * ...
drivetrain.motor.RPMmax * 60 / ...
(1000 * drivetrain.gearRatio); % km/h
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–32
Appendix: simVehicle.m
% results = simVehicle(vehicle,cycle,grade)
% - simulate a vehicle defined by "vehicle", perhaps created using
% setupSimVehicle.m
% - cycle is Nx2, where first column is time in seconds and second
% column is desired speed in miles per hour
% - grade is road grade in percent - either a constant grade for all
% time, or a different grade value for every point in time
function results = simVehicle(vehicle,cycle,grade)
rho = 1.225; % air density, kg/m3
results.vehicle = vehicle;
results.cycle = cycle; % time in s, desired speed in miles/hour
results.time = cycle(:,1); % s
if isscalar(grade),
results.grade = repmat(atan(grade/100),size(results.time)); % rad
else
results.grade = atan(grade/100); % rad
end
results.desSpeedKPH = cycle(:,2) * 1.609344; % convert to km/h
results.desSpeed = min(vehicle.maxSpeed,...
results.desSpeedKPH*1000/3600); % m/s
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–33
results.actualSpeedKPH = zeros(size(results.desSpeed)); % km/h
results.distance = zeros(size(results.desSpeed)); % km
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–34
vehicle.drivetrain.gearRatio / ...
vehicle.drivetrain.wheel.radius - ...
results.aeroForce(k) - ...
results.rollGradeForce(k) - ...
vehicle.roadForce;
results.actualAccel(k) = results.actualAccelForce(k) / ...
vehicle.equivMass;
results.motorSpeed(k) = min(vehicle.drivetrain.motor.RPMmax,...
vehicle.drivetrain.gearRatio * ...
(prevSpeed + results.actualAccel(k) * ...
(results.time(k) - prevTime)) * 60 / ...
(2*pi*vehicle.drivetrain.wheel.radius));
results.actualSpeed(k) = results.motorSpeed(k) * ...
2*pi*vehicle.drivetrain.wheel.radius / ...
(60 * vehicle.drivetrain.gearRatio);
results.actualSpeedKPH(k) = results.actualSpeed(k) * 3600/1000;
deltadistance = (results.actualSpeed(k) + prevSpeed)/2 *...
(results.time(k) - prevTime)/1000;
results.distance(k) = prevDistance + deltadistance;
if results.limitTorque(k) > 0,
results.demandPower(k) = results.limitTorque(k);
else
results.demandPower(k) = max(results.limitTorque(k),...
-results.limitRegen(k));
end
results.demandPower(k) = results.demandPower(k) * 2*pi * ...
(prevMotorSpeed + results.motorSpeed(k))/2 / 60000;
results.limitPower(k) = max(-vehicle.drivetrain.motor.maxPower,...
min(vehicle.drivetrain.motor.maxPower,...
results.demandPower(k)));
results.batteryDemand(k) = vehicle.overheadPwr/1000;
if results.limitPower(k) > 0,
results.batteryDemand(k) = results.batteryDemand(k) + ...
results.limitPower(k)/vehicle.drivetrain.efficiency;
else
results.batteryDemand(k) = results.batteryDemand(k) + ...
results.limitPower(k)*vehicle.drivetrain.efficiency;
end
results.current(k) = results.batteryDemand(k)*1000/...
vehicle.drivetrain.pack.vnom;
results.batterySOC(k) = prevSOC - results.current(k) * ...
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–35
(results.time(k) - prevTime) / ...
(36*vehicle.drivetrain.pack.module.capacity);
prevTime = results.time(k);
prevSpeed = results.actualSpeed(k);
prevMotorSpeed = results.motorSpeed(k);
prevSOC = results.batterySOC(k);
prevDistance = results.distance(k);
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–36
Appendix: Code to simulate PCM
% ------------------------------------------------------------------------
% simPCM: Simulate parallel-connected-module packs (cells are connected in
% parallel to make modules; these modules are connected in series to make
% packs).
%
% The parameters for each cell may be different (e.g., capacity,
% resistance, etc.)
% ------------------------------------------------------------------------
% ------------------------------------------------------------------------
% Initialize some simulation configuration parameters...
% ------------------------------------------------------------------------
maxtime = 3600; % Simulation run time in simulated seconds
t0 = 2700; % Pack rests after time t0
storez = zeros([maxtime Ns Np]); % create storage for SOC
storei = zeros([maxtime Ns Np]); % create storage for current
% ------------------------------------------------------------------------
% Initialize states for ESC cell model
% ------------------------------------------------------------------------
z = 0.25*ones(Ns,Np);
irc = zeros(Ns,Np);
h = zeros(Ns,Np);
% ------------------------------------------------------------------------
% Default initialization for cells within the pack
% ------------------------------------------------------------------------
kvec = [0; maxtime+1]; % Iteration (time) vector for temp. profile
tvec = [25; 25]; % Default temperature profile
q = getParamESC('QParam',25,model)*ones(Ns,Np);
rc = exp(-1./abs(getParamESC('RCParam',25,model)))'*ones(Ns,Np);
r = (getParamESC('RParam',25,model))';
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–37
m = getParamESC('MParam',25,model)*ones(Ns,Np);
g = getParamESC('GParam',25,model)*ones(Ns,Np);
r0 = getParamESC('R0Param',25,model)*ones(Ns,Np);
rt = 0.000125; % 125 microOhm resistance for each tab
% ------------------------------------------------------------------------
% Modified initialization for cell variability
% ------------------------------------------------------------------------
% Set individual random "initial SOC" values
if 1, % set to "if 1," to execute, or "if 0," to skip this code
z=0.30+0.40*rand([Ns Np]); % rand. init. SOC for ea. cell
end
% ------------------------------------------------------------------------
% Add faults to pack: cells faulted open- and short-circuit
% ------------------------------------------------------------------------
% To delete a PCM (open-circuit fault), set a resistance to Inf
%r0(1,1) = Inf; % for example...
% To delete a cell from a PCM (short-circuit fault), set its SOC to NaN
%z(1,2) = NaN; % for example, delete cell 2 in PCM 1
Rsc = 0.0025; % Resistance value to use for cell whose SOC < 0%
% ------------------------------------------------------------------------
% Get ready to simulate... first compute pack capacity in Ah
% ------------------------------------------------------------------------
totalCap = min(sum(q,2)); % pack capacity = minimum module capacity
I = 10*totalCap; % cycle at 10C... not realistic, faster simulation
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–38
% ------------------------------------------------------------------------
% Okay... now to simulate pack performance using ESC cell model.
% ------------------------------------------------------------------------
for k = 1:maxtime,
T = interp1(kvec,tvec,k); % cell temperature
v = OCVfromSOCtemp(z,T,model); % get OCV for each cell: Ns * Np matrix
v = v + m.*h - r.*irc; % add in capacitor voltages and hysteresis
r0(isnan(z)) = Rsc; % short-circuit fault has "short-circuit" resistance
V = (sum(v./r0,2) - I)./sum(1./r0,2);
ik = (v-repmat(V,1,Np))./r0;
z = z - (1/3600)*ik./q; % Update each cell SOC
z(z<0) = NaN; % set over-discharged cells to short-circuit fault
irc = rc.*irc + (1-rc).*ik; % Update capacitor voltages
fac = exp(-abs(g.*ik)./(3600*q));
h = fac.*h + (1-fac).*sign(ik); % Update hysteresis voltages
minz = min(z(:)); maxz = max(z(:)); % Check to see if SOC limit hit
if minz < 0.05, I = -abs(I); end % stop discharging
if maxz > 0.95, I = abs(I); end % stop charging
if k>t0, I = 0; end % rest
storez(k,:,:) = z; % Store SOC for later plotting
storei(k,:,:) = ik; % store current for later plotting
end % for k
% ------------------------------------------------------------------------
% In Figure 1, plot the individual SOC vs. time for all cells in all
% series PCMs. There is one subplot for each PCM.
% ------------------------------------------------------------------------
nonocPCMs = ~isinf(sum(r0,2)); % modules that are not open-circuit faulted
figure(1); clf; t = (0:(length(storez(:,:,1))-1))/60;
xplots = round(1.0*ceil(sqrt(Ns))); yplots = ceil(Ns/xplots); means = [];
for k = 1:Ns,
zr=squeeze(100*storez(:,k,:));
subplot(yplots,xplots,k); plot(t,zr); axis([0 ceil(maxtime/60) 0 100]);
title(sprintf('Cells in PCM %d',k));
ylabel('SOC (%)'); xlabel('Time (min)');
zr(isnan(zr))=0; % exclude dead cells (failed short) from mean
if nonocPCMs(k), % exclude from average if open-circuit!
means = [means; mean(zr,2)']; %#ok<AGROW>
end
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett
ECE5720, Simulating Battery Packs 2–39
% ------------------------------------------------------------------------
% In Figure 2, plot the average SOC vs. time for all PCMs
% ------------------------------------------------------------------------
figure(2); clf; plot(t,means'); grid on
xlabel('Time (min)'); ylabel('SOC (%)');
title('Average SOC for each PCM');
legendstrings = [];
for k=1:Ns,
if nonocPCMs(k),
legendstrings = [legendstrings; ...
{ sprintf('String %d',k) }]; %#ok<AGROW>
end
end
legend(legendstrings);
% ------------------------------------------------------------------------
% In Figure 3, plot the (maximum average SOC) minus (minimum average SOC)
% ------------------------------------------------------------------------
figure(3); plot(t,(max(means)-min(means))); grid on
xlabel('Time (min)'); ylabel('Difference in SOC (%)');
title('Maximum-average SOC minus minimum-average SOC');
% ------------------------------------------------------------------------
% In Figure 4, plot the individual cell current vs. time for all cells in
% all series PCMs. There is one subplot for each PCM.
% ------------------------------------------------------------------------
figure(4); clf; t = (0:(length(storei(:,:,1))-1))/60;
for k = 1:Ns,
zr=squeeze(storei(:,k,:));
subplot(yplots,xplots,k); plot(t,zr);
axis([0 ceil(maxtime/60) -101 101]);
title(sprintf('Cells in PCM %d',k));
ylabel('Current (A)'); xlabel('Time (min)');
end
Lecture notes prepared by Dr. Gregory L. Plett. Copyright © 2013, 2015, Gregory L. Plett