S-Function Logical Modelisation

Hello Every Body,
I'm starting to develop in Matlab Language to translating some Simulink code into S-Function. My first library is to check the varaition of my input signal. In the picture, I check if the old value of the input is for exemple False, and the new alue of the input is True, then the output is true. If the old input is an other value, and the new input is True then the output is false because I just Check if the Input change False to True.
The picture in my post is my simulink model. Here is the Simulink S-Function
function [output, oldInput_Out, change, FlagDetectChange_Out]= fcn(Init,input,oldInput_In, FlagDetectChange_In)
INITIAL_VALUE = 0;
FINAL_VALUE = 1;
OTHERS_VALUE = 2;
Changed = 1;
NoChanged = 0;
False = 0;
True = 1;
if (Init)
output = 0;
oldInput_Out = 0;
change = uint8(NoChanged);
FlagDetectChange_Out = False;
else
if (((oldInput_In==INITIAL_VALUE) || (oldInput_In==FINAL_VALUE))&&((input==INITIAL_VALUE)||(input==FINAL_VALUE)))
change = uint8(xor(input, oldInput_In));
else
change = uint8(OTHERS_VALUE);
end
if (FlagDetectChange_In== False && change==NoChanged && oldInput_In==INITIAL_VALUE && input==INITIAL_VALUE)
output = 0;
FlagDetectChange_Out = False;
elseif (FlagDetectChange_In== False && change==Changed && oldInput_In==INITIAL_VALUE && input==FINAL_VALUE)
output = 1;
FlagDetectChange_Out = True;
elseif (FlagDetectChange_In== True && change==Changed && oldInput_In==INITIAL_VALUE && input==FINAL_VALUE)
output = 1;
FlagDetectChange_Out = True;
elseif (FlagDetectChange_In== True && change==NoChanged && oldInput_In==FINAL_VALUE && input==FINAL_VALUE)
output = 1;
FlagDetectChange_Out = False;
elseif (FlagDetectChange_In== False && change==NoChanged && oldInput_In==FINAL_VALUE && input==FINAL_VALUE)
output = 1;
FlagDetectChange_Out = False;
elseif (change==OTHERS_VALUE)
output = 5;
FlagDetectChange_Out = False;
else
output = 5;
FlagDetectChange_Out = False;
end
oldInput_Out = input;
%FlagDetectChange_Out = double(change);
end
end

Respuestas (0)

Categorías

Más información sobre General Applications en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 3 de Abr. de 2015

Comentada:

TAB
el 6 de Abr. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by