MATLAB: Does converting the subsystem to an S-function with Real-Time Workshop introduce an algebraic loop

algebraicloopreal times-functionsimulinksimulink codersubsystemtargetworkshop

I have a model, which contains a subsystem, that simulates without any problems. However, when I use the Real-Time Workshop S-function target to convert the subsystem to an S-function, the resulting S-function adds an algebraic loop into the model.

Best Answer

The algebraic loop added to the model is a false algebraic loop. This addition is a limitation related to how Simulink handles atomic subsystems. The generation of an S-function from a subsystem makes that subsystem an atomic unit.
This phenomenon typically occurs because S-functions cannot specify direct feedthrough I/O configurations. If an input has a direct feedthrough connection to an output, the entire block is designated as a direct feedthrough block. Thus, a false algebraic loop may be detected due to the feedback connections between the S-function block and an input-output path that is not a direct feedthrough path.
The following options are available to avoid introducing the false algebraic loops.
- For Simulink 6.0 (R14) and later, before creating the S-function, make the subsystem atomic and simulate the system.
1. Right-click the subsystem.
2. Select "Subsystem Parameters." A dialog appears.
3. In the dialog, select "Treat as Atomic Unit." In most cases, if the S-function exhibits a false algebraic loop, it will be generated for an atomic subsystem as well.
4. Check whether the false algebraic loop occurs with the atomic subsystem.
5. Open the "Subsystem Parameters" dialog again.
6. Select the "Minimize algebraic loop occurences" option. If this eliminates the algebraic loop, this same process may work for S-functions, although this is not always the case.
- Eliminate direct feedthrough paths from the subsystem that generates the S-function. You can do this by placing a block that does not exhibit direct feedthrough immediately after each inport of the subsystem that generates the S-function.
- Move delay elements outside the boundary of the generated S-function. Delay elements include dynamic blocks, such as integrators, transfer functions, memory blocks, and other blocks that do not exhibit direct feedthrough. Often, this requires a large change in the dynamic modeling of the system.
- Break the algebraic loop outside the generated S-function, possibly by inserting a memory block somewhere in the loop. This option can change the dynamics of the system.
In many cases, it might be acceptable to keep the false algebraic loop in the system. Although this results in increased overhead incurred from calling the algebraic loop solver, the solver converges on the correct solution in one iteration. However, this is not an option if you are using a Real-Time Workshop target that does not support algebraic loops.