MATLAB: Do I receive an infinite cycle error when a broadcast event is fired in a state exit action using Stateflow

stateflow

I have a Stateflow chart that implements a counter that resets after it hits the maximum count. The state that resets the counter is entered after a broadcast counter stop event is fired from the exit action of a parallel state. When the parallel state that fires this event is higher in the decomposition order than the state that resets the counter, I see the following error in the Stateflow Debugger:
Runtime error: Infinite cycle detected

Best Answer

The infinite cycle that results from a broadcast event being fired in a state exit action is expected behavior according to the specifications of Stateflow. An event fired in the exit action causes an infinite recursion because the state has not yet been exited. To work around this issue, you can try any one of the following:
-- Use directed event broadcast as suggested in the documentation (search for: directed event broadcast).
This will ensure that the event is not processed by the state that throws it.
-- Use an Implicit event.
An example of the usage of implicit events can be found in the following documentation, as well by searching for: implicit event example.
-- Pass events in transition actions.