Info

This question is closed. Reopen it to edit or answer.

how to give delay in matab embedded function

1 view (last 30 days)
Akshaya Pati
Akshaya Pati on 20 Mar 2013
Closed: Sabin on 11 Jan 2023
Hi, I am using MATLAB embedded function to Maximum power point tracking algorithm. In this algorithm in each second i am giving a voltage(Vref) to the SImulink model and corresponding power(P) compared with previous power accordingly Vref will change Let Vref i have given at 2sec to get the actual power for that P it takes 0.002sec so it is taking previous Vref Power . Can you advise how i will give delay inside the matlab embedded function I attached my program here for your reference
function Vref=fcn(T,P,Enable) persistent k v4 v3 v1 v2 n V P1 P2 P6 P4; if isempty(k) k=2; end if isempty(v4) v4=132; end if isempty(v3) v3=0; end if isempty(v1) v1=50; end if isempty(v2) v2=81; end if isempty(n) n=0.2; end if isempty(V) V=80; end if isempty(P1) P1=P; end if isempty(P2) P2=P; end if isempty(P6) P6=zeros(1,20); end if isempty(P4) P4=zeros(1,20); end Vref=V; % P5=P6; % X=zeros(1,60); % P9=V1*I1; if(T<=0.1) T; P1=P; end if(T>0.1 & T<=0.2) T; P2=P; end T; if(Enable~=0) if(T<=(n+.1)) F=[1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393]; m=size(F,2); if P2>P1 T v3=v1; v1=v2; v4=v4; L=F(m-k-1)/F(m-k+1); v2=v4-F(m-k-1)/F(m-k+1)*(v4-v3); V=v2; Vref=v2; P1=P2; P2=P else T v4=v2; v2=v1; v3=v3; v1=v3+F(m-k-1)/F(m-k+1)*(v4-v3); V=v1; Vref=V; P2=P1; P1=P
end
k=k+1;
n=n+.1;
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!