MATLAB: Do both enabled subsystems execute in the same 4ms step function

simulinkstateflow

Why do both enabled subsystems execute in the same 4ms step function?
I have a multirate model and a Stateflow chart which should only enable one subsystem at a time. I do not want both enabled subsystems to run in the same step because I expect the system to only be in one state at a time.

Best Answer

  • This behavior is related to the design of the model.
    The key point here is that the enabling logic occurs every 100μs, for example, for both the 100μs rate and the 4ms rate. Since each rate is a separate task, the decision logic is able to interrupt the 4ms task and change the state during its execution. As a result, the system can be in both states during the course of the 4ms task.
    There are many ways to resolve this issue depending on your use case. I believe that the most obvious way is to change the Stateflow chart to only execute every 4ms (the slower rate). Since some of the control code is only executing every 4ms, you could argue that the state is not actually changing every 100μs, so the Stateflow logic should reflect that.