every

Control chart execution with the every operator

Description

example

every(n,E) returns true at every nth occurrence of the base event E since activation of the associated state. Otherwise, the operator returns false.

In a chart with no input events, every(n,tick) returns true if the chart has woken up an integer multiple of n times since activation of the associated state.

The every operator resets the counter for E to 0 each time the associated state reactivates.

example

every(n,time_unit) returns true every n units of time since activation of the associated state. Otherwise, the operator returns false. Specify time_unit as seconds (sec), milliseconds (msec), or microseconds (usec).

The every operator resets the counter for sec, msec, and usec to 0 each time the associated state reactivates.

Use of every as an absolute-time temporal logic operator is supported only in standalone charts for execution as MATLAB® objects.

Examples

expand all

A status message on appears every 5 CLK cycles after activation of the state.

on every(5,CLK): status('on');

A status message is displayed every 2 seconds after activation of the state.

on every(2,sec): disp('Hello!');

Tips

  • You can use quotation marks to enclose the keywords 'tick', 'sec', 'msec', and 'usec'. For example, every(5,'tick') is equivalent to every(5,tick).

  • Use of every as an absolute-time temporal logic operator is supported only in standalone charts for execution as MATLAB objects. In a Simulink® model, use an outer self-loop transition with the after operator instead. For more information, see Use an Outer Self-Loop Transition with the after Operator to Replace the every Operator.

  • The timing for absolute-time temporal logic operators depends on the type of Stateflow® chart:

    • Charts in a Simulink model define temporal logic in terms of simulation time.

    • Standalone charts in MATLAB define temporal logic in terms of wall-clock time.

    The difference in timing can affect the behavior of a chart. For example, suppose that this chart is executing the during action of state A when the condition guard is true.

    • In a Simulink model, the function call to f executes in a single time step and does not contribute to the simulation time. The chart completes the function call to f before it takes the transition from state A to state B and calls function g.

    • In a standalone chart, the function call to f can take several seconds of wall-clock time to complete. If the call lasts more than two seconds, the chart takes the transition to state B and calls function g before the function f finishes executing.

Introduced in R2014b