% This file is used to compute the values of Kp and Ki for the current regulator.
% Place this file in the same folder than the Simulink file.


% PARAMETERS
fs = 20e3;              % Sampling, interrupt and switching frequency [Hz]
Ts = 1/fs;              % Sampling period [s]

Lb = 2.5e-3;            % Inductance used for the boost [H]
Rb = 22e-3;             % Resistance of the inductor used for the boost [Ohm]


C = 260e-6;             % Capacitance of the DC bus [F]
Vb = 100;               % Battery voltage [V]
Rload = 79;             % Load resistance [Ohm]

Vdc0 = 100;             % Inital DC bus voltage [V]
Ib0 = 5;                % Inital boost current [A]


% BOOST CURRENT REGULATOR -------------------------------------------------

K1 = 1/Rb;
T1 = Lb/Rb;

Td1 = (1/2 + 1/2 + 1/3)*Ts; % 1/2Ts of sampling, 1/2Ts of computation, 1/3 for the triangle carrier

Tn1 = T1;
Ti1 = 2*K1*Td1;

Kp1 = Tn1/Ti1;
Ki1 = 1/Ti1;


% BOOST CASCADED VOLTAGE REGULATOR ----------------------------------------
T2 = C;
Tdeq = 2*Td1;

a = 4;
Tn2 = a^2*Tdeq;
Ti2 = a^3*Tdeq^2/T2;

Kp2 = Tn2/Ti2;
Ki2 = 1/Ti2;