Stateflow User's Guide Previous page   Next Page

Sending Multiple Trigger Events to a Stateflow Chart

In Adding Event Triggers to Transitions, you replace the trigger event event with two trigger events: off_switch and on_switch. Even though you added multiple events, the trigger port in the Simulink test interface for the Controller block has the same appearance as before.

Each event requires a trigger signal to generate its event with a rise or fall in signal. However, Stateflow blocks have only one trigger port for receiving trigger signals. This means that each signal must be indexed into an array of two trigger signals.

Provide two trigger signals to the single trigger port of the Controller Stateflow block with the following steps:

  1. Click the signal line from the Manual Switch to the Controller block and press Delete to delete it as shown.

  2. Click on the Manual Switch block label and rename it as follows:
  3. In the Simulink Library Browser, under the Simulink node, in the Signal Routing library, click-drag a Mux block to the right of the Manual Switch block.

  1. By default, the Mux block has two inputs that are joined in an array to a single output.

  1. Connect the output of the Manual Switch to both inputs of the Mux block.

  1. This sends the same signal from the Manual Switch to the input ports on the Mux.

  1. Connect the output side of the Mux block to the trigger port as shown.

  1. The top input port of the mux now connects with the trigger event of index 1, off_switch. The bottom port connects with the trigger event of index 2, on_switch. During simulation, when you toggle the Manual Switch from -1 to 1, you send a rising trigger signal to both signal inputs of the trigger port. Only the on_switch event port reacts by sending an on_switch event to the Controller Stateflow diagram. Likewise, when you toggle the Manual Switch from 1 to -1, you generate an off_switch event.

  1. Save the model (as SFcontrol2).

Previous page  Adding Multiple Trigger Events to a Stateflow Chart Modifying Output Data with Actions Next page

© 1994-2005 The MathWorks, Inc.