Is there a workaround to referenced models causing an algebraic loop

4 views (last 30 days)
In short, is there a way to have a block that updates all instances when a single instance is changed without causing an algebraic loop in a real-time simulation.
In more detail, this concerns a simulink real-time simulation with a speedgoat baseline as the target with a IO397 I/O module.
The simulation runs normally without any errors or warnings and gives the expected behaviour.
When the simulation is built for the target machine it first gives a warning that an algebraic loop exists in the model and then gives an error stating that algebraic loops are not supported in generated code.
When the "Simulink.BlockDiagram.getAlgebraicLoops()" command is used no algebraic loops are found.
The simulation consists of 5 instances of a referenced model block that form a loop. To prevent an algebraic loop unit delay blocks are added on the ports inside the referenced model.
By using a copy instead of the referenced model or by moving the unit delay blocks outside of the model the algebraic loop gets resolved.
However using referenced models gives me an easy way to keep all instances up to date without a lot of copy pasting.
Is there a way to have the simulation run with reference model blocks without a clutter of unit delay blocks in the top level simulation?

Answers (1)

Karanjot
Karanjot on 13 Sep 2023
Hi Michiel,
I understand that you want to resolve an algebraic loop during a real-time simulation on target hardware. If possible, kindly share the files associated with the error.
An algebraic loop occurs when a signal loop in a model contains only blocks that have direct feedthrough. Direct feedthrough refers to blocks that use the input value for the current time step to calculate the output value for the current time step. Feedback loops can create algebraic loops in a model.
Model references might be atomic in nature, which means they must be treated like black boxes. If you have references that feed each other's inputs with their outputs, there is a possibility of algebraic loops.
Since a copy of the referenced model resolves the algebraic loop, I recommend using virtual subsystems coupled with unit delay blocks instead. A virtual subsystem is a type of subsystem that provides graphical hierarchy in a model but does not affect the execution order or data flow of the blocks inside it.
To learn more about this, you can refer to the below documentation:
I hope this helps!
Regards,
Karanjot Singh

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!