Matlab Function Block in a Simulink Model
Mostra commenti meno recenti
I have a Matlab Function Block within a Simulink model that I am using to control some of the switches I have in the model. The function takes real-time voltage measurments from the model, and outputs switching signals.
When I run the model, it seems that it enters an infinite loop(it says "Running" without showing any progress in the execution). And by "Ctrl + C", I get it to forward one step and it is stuck again unless I keep clicking "Ctrl + C". I am not sure what it is behaving this way.
Here is the part of the code that gets stuck:
function [GR, GS, GT] = fcn(DcVolt, VA, VB, VC, VR, VS, VT, limit)
%INITIALIZE OUTPUTS
GR = 0;
GS = 0;
GT = 0;
% INITIALIZE THE PERSISTENT VARIABLE TO STORE THE PREVIOUS VALUE OF VDC
persistent prev_VDC;
if isempty(prev_VDC)
prev_VDC = 0;
end
prev_VDC = DcVolt;
function [ARM,DISARM] = ARM_SWITCH (VAN,VDC,V_PREV, V_NEXT)
if (VDC >= VAN) || (V_PREV >= V_NEXT)
DISARM = 1; ARM = 0;
else
DISARM = 0; ARM = 1;
end
end
function [DISABLE] = DISABLE_SWITCH (VDC, VDCPREV)
if (VDC > (VDCPREV+15))
DISABLE = 1;
else
DISABLE = 0;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while DcVolt < limit
[ARM_R, DISARM_R] = ARM_SWITCH (VA, DcVolt, VC, VB);
[ARM_S, DISARM_S] = ARM_SWITCH (VB, DcVolt, VA, VC);
[ARM_T, DISARM_T] = ARM_SWITCH (VC, DcVolt, VB, VA);
if (ARM_R==1)
GR = 1;
else
GR = 0;
end
if (ARM_S==1)
GS = 1;
else
GS = 0;
end
if (ARM_T==1)
GT = 1;
else
GT = 0;
end
[DISABLE_R] = DISABLE_SWITCH (DcVolt, prev_VDC);
if (DISABLE_R == 1)
GR = 0;
end
[DISABLE_S] = DISABLE_SWITCH (DcVolt, prev_VDC);
if (DISABLE_S == 1)
GS = 0;
end
[DISABLE_T] = DISABLE_SWITCH (DcVolt, prev_VDC);
if (DISABLE_T == 1)
GT = 0;
end
end
end
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Naming Conventions in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!