| Stateflow User's Guide | ![]() |
Binding a Function-Call Subsystem
The control of a Stateflow state that binds a function-call subsystem trigger is best understood through the creation and execution of an example model. In the following example, a Simulink model triggers a function-call subsystem with a function-call trigger event E bound to state A of a Stateflow diagram.
The function subsystem contains a trigger port block, an input port, an output port, and a simple block diagram. The block diagram increments a count by 1 each time, using a Unit Delay block to store the count.
The Stateflow diagram contains two states, A and B, and connecting transitions, along with some actions. Notice that state A binds and event E to itself with the binding action bind:E. Event E is defined for the Stateflow diagram in the example with a scope of Output to Simulink and a trigger type of Function Call.
Double-click the trigger port block for the function-call subsystem
to display the Block Parameters dialog for the trigger port as shown.
Notice that the States when enabling field is set to the default value reset. This resets the state values for the function-call subsystem to zero when it is enabled. The alternative value for this field, held, tells the function-call subsystem to retain its state values when it is enabled. This feature, when coupled with state binding, gives full control of state variables for the function-call subsystem to the binding state.
Notice also that the Sample time type field is set to the default value triggered. This sets the function-call subsystem to execute only when it is triggered by a calling event while it is enabled.
Setting Sample time type to periodic enables the Sample time field below it, which defaults to 1. These settings force the function-call subsystem to execute for each time step specified in the Sample time field while it is enabled. To accomplish this, the state that binds the calling event for the function-call subsystem must send an event for the time step coinciding with the specified sampling rate in the Sample time field. States can send events with entry or during actions at the simulation sample rate. Therefore, for fixed step sampling, the sample time you enter in the Sample time field must be an integer multiple of the fixed step size. For variable step sampling, there are no limits on what you enter in the Sample time field.
| Using Bind Actions to Control Function-Call Subsystems | Simulating a Bound Function-Call Subsystem | ![]() |
© 1994-2005 The MathWorks, Inc.