To guarantee that the Outport executes after all filter calculation in code generation, you should take extra steps beyond setting “First”/”Last” execution order because code generation optimization may otherwise reorder blocks. You can follow the steps to ensure correct execution order:
1. Group your blocks into a subsystem and place the Outport block in its own subsystem.
2. For each subsystem:
- Open Block Parameter -> Code Generation tab
- Set Function packaging to Nonreusable function.
- To prevent code generation optimizations reordering these operations, mark the subsystem for late inling using the following MATLAB command:
set_param(‘model_name/subsystem_name’, 'RTWSystemCode', 'Inline');
3. In the Simulink model, ensure that your blocks execute before Outport subsystem. You can do this by :
- Adjust your block priorities.
- Using Model Configuration Parameter -> Simulink Order
Hope this helps!