Strange Problem - variable is filled with strange values.

1 view (last 30 days)
Hello,
I'm using a simulink model with a Matlab FCN block which receives for input 2 signals from his own output. Basically this:
The code from matlab function:
function [out] = blocoControlador2( il_in,il_k,psi_in,psi_k,state)
%Parameters:
a= 7.3421E-6;
b= 6.2343;
c= 457.8311;
d= 25.1627;
Icc= 10;
Isat= 694;
N= 350;
Af=(Isat/N)/(cos((pi/2)*((Isat/N)/Icc)));
Bf=(pi/2)*(1/Icc);
f= Af*cos(Bf*il_in);
lambAsc= a*N*(il_in-f) + (b*N*(il_in-f))./(c+d.*N*abs(il_in-f));
lambDesc = a*N*(il_in+f) + (b*N*(il_in+f))./(c+d*N*abs(il_in+f));
%=====================================================================
%****************CORRENTE CRESCENTE*****************
if il_in>=il_k && psi_in>=psi_k && il_in<=(Isat/N)&& psi_in==0
psi=0;
st=0;
%psi= psi_k;
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in<(Isat/N) && state==0
psi=psi_k;
st=0;
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in~=(Isat/N) && state==0
psi=psi_k;
st=1; % HERE!!
out= [ psi ; st] ;
elseif il_in>il_k && psi_in>psi_k && il_in>(Isat/N) && state==1
elseif ...
elseif ...
elseif ...
...
else
disp('==========default==========')
disp(il_k)
disp(il_in)
disp(psi_k)
disp(psi_in)
disp(state)
psi=psi_k;
st=state;
out= [ psi ; st];
end
end
The strange behaviour starts in the 3rd IF.
'st' variable and 'out' vector gets the right value but the function don't send outputs correctly for the next iteration.
Instead, is given strange values to input 'state' (that should be the same as 'st').
I've already did several debugging tests and really don't understandt why this is happenning.
Can anybody help, please?!?!?
Thanks in advance!
  1 Comment
F
F on 7 Apr 2014
I was thinking about it.... Should I store the outputs values in a buffer?
Maybe, I'm not reading the input while data is available in the bus...
Does anyone suggest a memory block to store a single integer?? [0,1,2,3,4]
Thanks!

Sign in to comment.

Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!