Home Examples Multiple Conditions for Stateflow Transitions (and e_clk event)
Coding Tips

Multiple Conditions for Stateflow Transitions (and e_clk event)

This example demonstrates a few of the more common transition conditions that end-users are likely to use and how to combine multiple conditions appropriately. For more information on transitions, refer to the MathWorks Stateflow documentation.

10.16.1   Stateflow Chart for Multiple Conditions for Stateflow Transitions and e_clk Event Example

In the example shown here, we have assumed that the e_clk Stateflow event is defined in Stateflow’s Model Explorer as per the sample Task Programs included with Dexterit-E. Namely, e_clk is the first input Stateflow event and is triggered only on the rising edge. In this manner, e_clk events in a Task Program will occur once every 1 ms.

For the Stateflow chart below, the transition from State1 to State2 occurs after 10 e_clk events have occurred (i.e 10 ms). The transition from State2 to State3 occurs only if the HandInTarget condition is true AND at least 10 e_clk events have occurred (i.e. both conditions must be true). The transition from State3 to State4 occurs if the HandInTarget condition is true OR 10 e_clk events have occurred (i.e. whichever condition occurs first).

Figure 10.25: Stateflow Chart for Multiple Conditions for Stateflow Transitions (and e_clk Event) Example

Note: The use of e_clk is a legacy approach. We now recommend use msec instead, because it is more intuitive (e.g. after(10, msec)). However, the msec option is only available if using MATLAB as the action language in the Stateflow chart.

Related Tasks

Coding Tips
Persistent Variables
Persistent variables are ones that hold their value between calls to the embedded MATLAB code they are defined in.
Coding Tips
Custom Control of the Trial Protocol Order
Normally, Dexterit-E manages and controls the order in which Trial Protocols (TPs) execute based on what is defined in the block table of the Task Protocol (see the Dexterit-E User Guide for more details).