Enabled Component
The following example implements a component similar to a Simulink® enabled subsystem:
component EnabledComponent
inputs
enabled = 0; % control signal
u = 0; % input signal
end
variables (Event=true)
x = 0; % state to hold output if necessary
end
outputs
y = 0; % output
end
parameters
held = true; % set true for held or false for reset
y_init = 0;
end
events
when edge(held && ~(enabled>0))
x = u; % if necessary, hold input on falling edge
end
end
equations
if enabled > 0
y == u;
elseif held==true
y == x;
else % not enabled and not held
y == y_init;
end
end
end
The component has two inputs: control signal enabled
and
data signal u
.
The block operation depends on the value of the held
parameter:
if it is true
, then the event variable x
assumes
the value of the input data signal u
on the falling
edge of the control signal.
As long as the control signal has a positive value, the output y
matches
the input data signal u
. When the control signal
is negative:
If
held
istrue
, the output porty
outputs the most recent held value of the event variable.If
held
isfalse
, the output resets to the initial value, specified by they_init
parameter.