Commit ecadbe2d authored by Martin Vítek's avatar Martin Vítek

Working regulator (on 0)

parent 0757312d
%% Nixie clock boost converter
%
% Nixie clock boost converter
%
clear
......@@ -19,69 +21,95 @@ par.Rout = par.R63 + par.Rload;
Uin = 12;
f = 23437.5;
d = 0.925;
d = 0.98;
Ts = 1/f;
uc_req = 180;
uc_lin = 180;
il_lin = 0.2;
il_lin = 0.83;
% Matrixes
ssm.A = [-par.Rin/par.L3 0 0;
0 -1/(par.Cout*par.Rout) 0;
0 1 1];
ssm.B = [-uc_lin/par.L3;
il_lin/par.Cout;
0];
ssm.C = eye(3);
ssm.D = zeros(size(ssm.B));
% Continuous time matrixes
cssm.A = [-par.Rin/par.L3, 0;
0, -1/(par.Cout*par.Rout)];
X1 = [1/par.L3; 0; 0];
X2 = [0;0;-1];
cssm.B = [-uc_lin/par.L3, 1/par.L3;
il_lin/par.Cout, 0];
cssm.C = eye(2);
cssm.D = zeros(size(cssm.B));
% Discrete system
sys = c2d(ss(ssm.A,ssm.B,ssm.C,ssm.D), Ts);
dssm = c2d(ss(cssm.A, cssm.B, cssm.C, cssm.D), Ts);
% Add error integration
dsys.A = [dssm.A(1,1), dssm.A(1,2), 0;
dssm.A(2,1), dssm.A(2,2), 0;
0, Ts, 1];
dsys.B = [dssm.B(1,1), dssm.B(1,2), 0;
dssm.B(2,1), dssm.B(2,2), 0;
0, 0, -Ts];
dsys.C = eye(3);
dsys.D = zeros(size(dsys.B));
% Simulate system (open loop)
i = 1;
i0 = 0.75;
u0 = 170;
delta0 = 0.9;
tmax = 0.1;
sim.vars(:,1) = [i0, u0, delta0];
sim.t(i) = 0;
for t=dssm.Ts:dssm.Ts:tmax
sim.vars(:, i+1) = dsys.A*sim.vars(:, i) + dsys.B*[1-d; Uin; uc_req];
sim.t(i+1) = t;
i = i+1;
end
% Plot it
plot_sim(sim, "Open loop response");
% Regulator
Q = diag([0.5, 0, 1]);
R = 1;
N = [0; 0; 0];
L = dlqr(ssm.A, ssm.B, Q, R, N);
%K = place(ssm.A', ssm.C', [-50000000, -1800000])';
N = zeros(3);
L = dlqr(dsys.A, dsys.B, Q, R, N);
reg.A = ssm.A-ssm.B*L;
reg.B = zeros(3,1);
ssr = c2d(ss(reg.A, reg.B, ssm.C, ssm.D), Ts);
reg.A = dsys.A - dsys.B*L;
reg.B = zeros(3);
% Simulate system
% Simulate system (open loop)
i = 1;
i0 = 0;
u0 = 0;
delta0 = 0;
i0 = 0.75;
u0 = 170;
delta0 = 0.9;
tmax = 0.2;
sim.vars(:,1) = [i0, u0, delta0];
sim.t(i) = 0;
sim_reg.vars(:,1) = [i0, u0, delta0];
sim_reg.t(i) = 0;
for t=sys.Ts:sys.Ts:tmax
sim.vars(:, i+1) = sys.A*sim.vars(:, i) + sys.B.*(1-d) + X1*Uin + X2*uc_req;
sim.t(i+1) = t;
for t=Ts:Ts:tmax
sim_reg.vars(:, i+1) = reg.A*sim_reg.vars(:, i) + reg.B*[1-d; Uin; uc_req];
sim_reg.t(i+1) = t;
i = i+1;
end
% Plot it
plot_sim(sim, d);
plot_sim(sim_reg, "Regulator");
function plot_sim(sim, d)
figure(1);
title(sprintf("Open loop response of uncontrolled boost converter (d=%4.2f)", d))
function plot_sim(sim, what)
% figure(1);
figure;
sgtitle(sprintf("%s", what));
subplot(1,3,1);
plot(sim.t, sim.vars(1,:));
title("il");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment