%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Application Note AN006
% Parameters for the 'Central PV inverter (three-phase grid-tied) v2' system
% Copyright imperix ltd, 2024
% dev@imperix.ch
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% SETPOINTS

VdcRef = 700; % DC bus voltage reference setpoint [V]
Vdc0 = 500;   % Initial DC bus voltage [V]

%% SYSTEM PARAMETERS

SwitchingFreq = 20e3;           % Switching frequency [Hz]
Deadtime = 700e-9;              % Deadtime [s]

ControlFreq = SwitchingFreq;    % Control frequency [Hz]
ControlPeriod = 1/ControlFreq;  % Control period [s]

MpptFreq = 200;                 % MPPT execution frequency [Hz]
MpptPeriod = 1/200;             % MPPT execution period [s]

%% PLANT PARAMETERS

Vpvmin = 20; % Lower treshold solar panel voltage
Vpvmax = 600; % Upper treshold solar panel voltage

wmin = 308; % Lower treshold grid angular frequency
wmax = 320; % Upper treshold grid angular frequency

Vg_rect_min = 20; % Lower treshold grid voltage detection

%PV
PvShortCircuitCurrent = 40; % PV panel's short-circuit current [A]
PvOpenCircuitVoltage = 300; % PV panel's open-circuit voltage [V]

Rpv = 6; % Parallel equivalent resistance of the PV [ohm]
Rs = 6;  % Serial equivalent resistance of the PV [ohm]

% Boost
Lb = 2.2e-3; % Boost-side inductor value [H]
Rb = 33e-3;  % Series equivalent resistance of Lb [ohm]

% Grid
GridFreq = 50; % Grid frequency [Hz]
Vg = 230;      % RMS Grid voltage [V]
Lg = 2.2e-3;   % Grid-side inductor value [H]
Rg = 33e-3;    % Series equivalent resistance of Lg [ohm]
Rp = 47;       % Grid precharge resistance [ohm]

%% BOOST CURRENT CONTROLLER PARAMETERS

% Optimum magnitude criterion
K1 = 1/Rb;
T1 = Lb/Rb;

% Total delay: 1/2 period of control delay,1/2 period of modulator delay
Td1 = ControlPeriod; 

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

KpIpv = Tn1/Ti1;
KiIpv = 1/Ti1;

%% GRID CURRENT CONTROLLER PARAMETERS (DQ)

% Optimum magnitude criterion
K2 = 1/Rg;
T2 = Lg/Rg;

% Total delay: 1/2 period of control delay,1/2 period of modulator delay
Td2 = ControlPeriod;

Tn2 = T2;
Ti2 = 2*K2*Td2;

KpIg = Tn2/Ti2;
KiIg = 1/Ti2;

%% CASCADED VOLTAGE CONTROLLER

KpVdc = 0.1;
KiVdc = 2;
