I knew how to set a a while loop in Mikrocontroller, but when I tried to Implement it in matlab /simulink, my computer gets stuck and never get out of the while loop and does not do anything. here is my code:
function [tout,valueP,valueI] = fcn(tin,Vout)
persistent dp; %local variable
persistent di; %local variable
if isempty(di)
di=0;
end
if isempty(dp)
dp=0;
end
while 1 % infinite loop
if tin==30 %at time t=30s, take Vout value
if Vout==300 %during this time, compare Vout to 300V
di=10;
dp=40;
else
di=20;
dp=10;
end
end
if tin==60 % break the loop at time 60s
break
end
end
tout=tin; % output
valueP=dp;
valueI=di;
my objective is: run the model, then watch the Vout and then at time 30s, take the value of Vout, then use it for comparaison that will result in vlaueP,valueI.
here is my model as pic(could not add it)
t
variable in the linet==60
? where is it defined ? What changes its value ? Your code ? \$\endgroup\$ – AJN Sep 24 '20 at 13:28t==60
tot>=60
. That way, if Simulink skips over exact60s
, the loop will still break. \$\endgroup\$ – AJN Sep 24 '20 at 13:33