Can a model that uses referenced models be 'flattened' for code generation?
Show older comments
Firstly some observations I have with model referencing and code generation:
In order to get good maintainability, model referencing is indeed a good way to set up the models. However, when designing control loops with local feedback across one or more referenced models, artificial algebraic loops occur.
Normally in a flat model, simulink solves this for automatically. With model referencing, simulink loses track of the states and can no longer determine the correct execution order.
One must manually keep track of the direct feedthrough blocks that make up the output equation, and the blocks that compute the new states in order to solve this. (aka state space). The only proper way to do this (I found), was using the simulink debugger to retrace the execution order, and using function calls or stateflow to force the model to be executed the same way, and moving the internal delays that make up the local feedback loop to the root level to indicate the states.
Simply putting extra delay blocks in between as some suggest will change the dynamic behaviour and can even cause instability in extreme cases. It would be nice if simulink could give better assistance in solving these artifically algebraic loops. I was confronted with all these algebraic loop errors when there in fact were none!
Secondly, when we do performance measurements, the generated code on the embedded processor takes 30% less ticks with a manually 'flattened' model compared to the code generated from with a heavily referenced model. The cause seems to be that the flat model benefits from function packing over multiple subsystems and has no function calls.
As performance is critical, is there a way to generate 'Flat' code from a referenced model? One option is to manually create normal subsytems for each referenced model and then generate code, but this is pretty labour intensive. I was hoping that there would be an easier way.
The benefit would be that the model is easily maintainable, but faster code can be generated.
%When compiling from C, does one care if the ASM looks nice? So why would this be different for Model to C?%
Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!