Untitled
unknown
plain_text
9 months ago
2.9 kB
10
Indexable
function duty = mppt_po(Vpv, Ipv)
% Simple P&O MPPT for Simulink MATLAB Function block
% Call rate: Ts_mppt (e.g., 0.02 s)
persistent V_prev I_prev P_prev step sign
if isempty(V_prev)
V_prev = 0;
I_prev = 0;
P_prev = 0;
step = 0.5; % perturbation in volts (tune 0.2-1.0)
sign = 1; % +1 means increase V, -1 decrease
end
% Current measurements
P = Vpv * Ipv;
% If first valid measurement, just set previous and return nominal duty
if V_prev == 0
V_prev = Vpv; I_prev = Ipv; P_prev = P;
duty = 0.5; % initial guess
return
end
% Decision logic (P&O)
if P > P_prev
% power increased: keep direction
if Vpv > V_prev
sign = 1;
else
sign = -1;
end
else
% power decreased: reverse direction
sign = -sign;
end
% update reference voltage
V_ref = Vpv + sign*step;
% Simple mapping V_ref -> duty (assuming boost converter)
% Duty = 1 - (Vpv / V_ref) (not exact; use closed-loop to control)
% Use PI/clip mapping to keep duty in [0.01,0.99]
duty = 1 - (Vpv / max(V_ref, 0.1));
duty = max(0.01, min(0.99, duty));
% update history
V_prev = Vpv;
I_prev = Ipv;
P_prev = P;
endEditor is loading...
Leave a Comment