after

Control chart execution with the after operator

Description

example

after(n,E) returns true if the base event E has occurred at least n times since activation of the associated state. Otherwise, the operator returns false.

In a chart with no input events, after(n,tick) returns true if the chart has woken up n times or more since activation of the associated state.

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

example

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

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

Examples

expand all

A status message appears during each CLK cycle, starting 5 clock cycles after activation of the state.

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

A transition out of the associated state occurs only on broadcast of a ROTATE event, but no sooner than 10 CLK cycles after activation of the state.

ROTATE[after(10,CLK)]

After 12.3 seconds since activation of the state, temp variable becomes LOW .

on after(12.3,sec): temp = LOW;

After 8 milliseconds since activation of the state, a transition out of the associated state occurs.

after(8,msec)

Tips

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

  • 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.

    • 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