My matlab code for PV P&O tracking algorithm has an error
Show older comments
Hello
I'm writing the code for P&O tracking as I want the output to be Power and Voltage where the max point is located. From the figure, I expected the max power to be at 51.53 W at 16.32 V.

But when I run the code, it always gives the result to the open-circuit voltage (last point of the curve) which is not correct, it gives me the result of 30.01 W at 19 V.
The code that I write is here, not sure I've done something wrong or not (I'm pretty new to matlab). The outputs are P and Vmpp
function [Vmpp,P] = PandO(V,I)
persistent Vold Pold Iold dV dI dP Power;
if isempty(Vold)
Vold =0; Iold = 0;
Pold = 0; dV = 0; dI = 0; dP = 0; Power = zeros(1000,1);
end
deltaV = 0.0001; % initialize
for i = 1:size(V,1)
Power(i) = V(i) .* I(i);
dV = V(i) - Vold;
dI = I(i) - Iold;
dP = Power(i) - Pold;
if dP ~= 0
if dP < 0
if dV <0
Vmpp = V(i) + deltaV;
else
Vmpp = V(i) - deltaV;
end
else
if dV < 0
Vmpp = V(i) - deltaV;
else
Vmpp = V(i) + deltaV;
end
end
else
Vmpp = V(i);
P = Power(i);
break
end
Vold = V(i);
Iold = I(i);
Pold = V(i).*I(i);
end
end

Any suggestion for me? thank you so much in advance
Answers (3)
Roshan Reji
on 21 Oct 2019
0 votes
Did you find the solution please reply asap. I have the same problem.
mehmet salih fidaner
on 9 Jan 2020
0 votes
Did you find the solution please reply asap. I have the same problem.
1 Comment
VENKATA ARAVINDA SATVIK MUVVALA
on 10 Jan 2020
if you find any solution, please comment here ASAP. I also have same problem.
M.Saud Khan
on 26 Jan 2020
I think the problem is in deltaV. For some reason, my simulation worked with deltaV = 0.04. Decreasing below this value, resulted in Vmpp = open circuit voltage. I have disabled the "zero crossings" in the solver settings & simulated the system using ode23t solver (my system used power electronics blocks; ode23t & ode23tb are mostly used with power electronic blocks).
I'm not a fan of using array indexing & for-loops inside the simulink MATLAB function block. That's why I used the following code:
function [step, flag,Vmpp] = fcn(V,V_old, P,P_old)
flag = 5; % Arbitrary
Vmpp = 35; % Arbitrary
dV = 0.04;
% persistent Pold Vold dV
if isempty(V_old) || isempty(P_old)
V_old = 30; P_old = 800; % Initial conditions
end
delta_P = P - P_old;
delta_V = V - V_old;
if delta_P > 0
flag = 1;
if delta_V > 0
Vmpp = V + dV; % Increase voltage
elseif delta_V < 0
Vmpp = V - dV; % Decrease voltage
end
elseif delta_P < 0
flag = -1;
if delta_V > 0
Vmpp = V - dV; % Decrease voltage
elseif delta_V < 0
Vmpp = V + dV; % Increase voltage
end
elseif delta_P == 0
flag = 0;
Vmpp = V;
end
step = dV;
end
For V_old & P_old, I used the delay block & to produce the gate signal (duty ratio) of a MOSFET/IGBT, I used a PI controller. The PI gains were selected by hit & trial. All of this is in the picture below:

I have used a flag variable to note the state of delta_P. Results are not very accurate, however, it is working for me..
Hope this helps somebody..
9 Comments
VENKATA ARAVINDA SATVIK MUVVALA
on 26 Jan 2020
is it working for any value of irradiance?
M.Saud Khan
on 26 Jan 2020
Yeah, I have checked with Irr = 1200, 1000, 500, 200 Wb/m2. I don't think the value of irradiance has anything to do with the P&O algorithm. If you are receiving errors on irradinace value, probably check your PV model. I'm using the default Simulink PV model..
VENKATA ARAVINDA SATVIK MUVVALA
on 26 Jan 2020
Edited: VENKATA ARAVINDA SATVIK MUVVALA
on 26 Jan 2020
I am also using the default simulink model but i m getting wrong output. so, Can you please mail me your simulation file. It would be a great help for me to do my assignment.
My mail id: aravindmuvvala@gmail.com
Pavani
on 2 Apr 2020
Sir, can you please mail me your simulation file.my mail id : pavani.vinnakota@gmail.com
santosh jaiswar
on 7 Sep 2020
can you please mail me that simulation model
santoshjaiswar67@gmail.com
mehmet salih fidaner
on 18 Sep 2020
can you please mail me that simulation model
m.fidaner@hotmail.com
At?l COSGUN
on 15 Jan 2021
Could you pls mail me your this study. My mail adress is atilcosgun@gmail.com
MUSTAFA MOHAMMED
on 29 May 2021
can you plese mail me daldoulmustafa3@gmail.com
shobha
on 11 Aug 2025
could you please mail this file
Categories
Find more on Aerospace Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!