| Contents | Index |
| On this page… |
|---|
Blocks for Manipulating Events Creating a Union of Multiple Events |
You can manipulate events to accomplish any of these goals:
To invoke a function-call subsystem, MATLAB Function block, or Stateflow block upon entity departures or signal-based events.
Note You can invoke triggered subsystems, MATLAB Function blocks, and Stateflow blocks upon trigger edges, which are a type of signal-based event. However, you will need to translate the trigger edges into function calls if you want the invocations to occur asynchronously, to be prioritized among other simultaneous events, or to occur more than once in a fixed time instant. |
To create a union of events from multiple sources. See Creating a Union of Multiple Events.
To prioritize the reaction to one event relative to other simultaneous events. See Translating Events to Control the Processing Sequence.
To delay the reactions to events. See the Function-call time delay parameter on the Signal-Based Function-Call Generator blocks reference page.
To conditionalize the reactions to events. See Conditionalizing Events.
The term event translation refers to the conversion of one event into another. The result of the translation is often a function call, but can be another type of event. The result of the translation can occur at the same time as, or a later time than, the original event.
The table below lists blocks that are useful for manipulating events.
| Event to Manipulate | Block |
|---|---|
| Entity advancement | Entity Departure Function-Call Generator Event |
| Signal-based event | Signal-Based Function-Call Generator |
| Function call | Signal-Based Function-Call Generator |
| Mux |
If you connect the Entity Departure Counter block's #d output port to a block that detects sample time hits or rising value changes, then you can view the counter as a mechanism for converting an entity advancement event into a signal-based event. Corresponding to each entity departure from the block is an increase in the value of the #d signal.
To generate a function-call signal that represents the union (logical OR) of multiple events, use this procedure:
Generate a function call for each event that is not already a function call. Use blocks in the Event Generators or Event Translation library.
Use the Mux block to combine the function-call signals.
The multiplexed signal carries a function call when any of the individual function-call signals carries a function call. If two individual signals carry a function call at the same time instant, then the multiplexed signal carries two function calls at that time instant.
Examples are in and below.
The example below (open model) illustrates different approaches to event translation and event generation. This example varies the approach for illustrative purposes; in your own models, you might decide to use a single approach that you find most intuitive.
The goal of the example is to plot the number of arrivals at a bank of three servers at each value of time. Entities advance to the servers via one or two FIFO Queue blocks. To count arrivals and create the plot, the model translates each arrival at a server into a function call; the Mux block combines the three function-call signals to create an input to the Instantaneous Event Counting Scope block.
The three server paths use these methods for translating an entity arrival into a function call:
One path uses the Entity Departure Function-Call Generator block, treating the problem as one of event translation.
One path uses the Entity-Based Event Generator block, treating the problem as one of event generation. This is similar to the approach above.
One path uses the Signal-Based Function-Call Generator block to translate an increase in the value of the server block's #n signal into a function call. This approach uses the fact that each arrival at the server block causes a simultaneous increase in the block's #n signal.


You can configure a Function-Call Subsystem block to detect function calls from one or more sources. The following model fragment uses an event translation block to convert a signal-based event into a function call. When you perform this conversion, you create a subsystem that detects a function call from a Stateflow block and a signal-based event from another source. When either the Stateflow block generates a function call, or the signal connected to the vc port of the Signal-Based Function-Call Generator block changes, the model executes this subsystem. If both events occur simultaneously, the model executes the subsystem twice.

A similar example is in .
In some situations, event translation blocks can help you prescribe the processing sequence for simultaneous events. The examples below illustrate how to do this by taking advantage of the sequence in which an event translation block issues two function calls, and by converting an unprioritized function call into a function call having an event priority.
In the next model, entity generation and the execution of a function-call subsystem can occur simultaneously. At such times, it is important that the entity generation occur first, so that the entity generator updates the value of the w signal before the function-call subsystem uses w in its computation. This model ensures a correct processing sequence by using the same Signal-Based Function-Call Generator block to issue both function calls and by relying on the fact that the block always issues the f1 function call before the f2 function call.

In this example, the Signal-Based Function-Call Generator block has this configuration:
Generate function call only upon = Function call from port fcn
Generate optional f2 function call selected
In this example, the Function-Call Split block in the Simulink libraries is not an alternative because it cannot connect to SimEvents blocks.
The next model uses an event translation block to prioritize the execution of a function-call subsystem correctly on the event calendar, relative to a simultaneous event. In the model, a Stateflow block and an entity generator respond to edges of the same trigger signal. The Stateflow block calls an event translation block, which in turn calls a function-call subsystem. The subsystem performs a computation using the w output signal from the entity generator.

As in the earlier example, it is important that the entity generator update the value of the w signal before the function-call subsystem uses w in its computation. To ensure a correct processing sequence, the Signal-Based Function-Call Generator block replaces the original function call, which is not scheduled on the event calendar, with a new function call that is scheduled on the event calendar with a priority of 200. The Event-Based Entity Generator block schedules an entity-generation event on the event calendar with a priority of 100. As a result of the event translation and the relative event priorities, the entity generator generates the entity before the event translator issues the function call to the function-call subsystem whenever these events occur at the same value (or sufficiently close values) of the simulation clock.
The Entity Departure Function-Call Generator Event and Signal-Based Function-Call Generator blocks provide a way to suppress the output function call based on a control signal. If the control signal is zero or negative when the block is about to issue the function call, then the block suppresses the function call. You can use this feature to
Prevent simulation problems. The example in Example: Detecting Changes in the Last-Updated Signal uses conditional function calls to prevent division-by-zero warnings.
Model an inoperative state of a component of your system. See the next example.
The example below (open model) uses Event-Based Entity Generator blocks to generate entities when a pulse signal changes its value. The top entity generator generates an entity upon each such event. The bottom entity generator responds to a function call issued by an event translation block that detects changes in the pulse signal's value. However, the event translation block issues a function call only upon value changes that occur while the e1 input signal is positive. In this model, a nonpositive value of the e1 signal corresponds to a failure or resting period of the entity generator.



![]() | Generating Function-Call Events | Managing Simultaneous Events | ![]() |

Model electronic system architectures, process flows, and logistics as queuing systems or agent-based systems.
Get free kit| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |