Guy on Simulink

Simulink & Model-Based Design

Data Dependency Violation Errors and Subsystem Semantics

Did you ever receive a "data dependency violation" error message from a Simulink model?

Input data dependency violation due to function-call or action susbsystems.  See Subsystem Examples in the Simulink library for valid and invalid examples of function-call and action subsystems.

I will try to explain why this happens and what you need to do to avoid this error by introducing my favorite set of Simulink examples.

Function-Call Subsystems

To begin, let's explain how aFunction-Call Subsystemis executed.

In the following example model, I display the blockssorted order. You can notice that the Function-Call Subsystem is noted "0:F{1}". The "F" means that this subsystem is Function-Call and you should look at the call generator to see its sorted order. In this case, it is "0:1".

Example model involving function call

If we generate code, we can see that the Function-Call Subsystem is executed in that order:

Generated code involving a function call

Invoking a Function-Call Subsystem from an Atomic Subsystem

Now let's place the Function-Call Generator inside an Atomic Subsystem.

Example model involving function call generated form an Atomic subsystem

The same principle as in the previous example applies. Since the source is now inside an Atomic Subsystem, the Function-Call Subsystem is pulled inside the Atomic Subsystem.

Generated code involving a function call generated from an Atomic Subsystem

Data Dependency Violation

Now, what happens if the Function-Call Subsystem takes an output of the Atomic Subsystem as input.

Problematic example model involving function call data dependency violation

If you try to update this model, you will receive the following errors:

Input data dependency violation due to function-call or action subsystems. See Subsystem Examples in the Simulink library for valid and invalid examples of function-call and action subsystems
Input ports (1, FcnCall) of 'fcnCallExample1c/FcnCallSS' are involved in the loop
Input ports (1) of 'fcnCallExample1c/GainBefore' are involved in the loop

I hope that based on the previous example, you can visualize why this semantics is impossible. On one hand, I specified thatAtomicSSis atomic, includingFcnCallSSthat gets pulled in as shown above. On the other hand,FcnCallSSneeds the output ofGain3. ButGain3cannot execute untilAtomicSSis completed.

What to do?

To get help on this topic, search for the Simulink example titledSimulink Subsystem Semantics. It can be opened by usingsl_subsys_semantics.

Simulink Subsystem Semantics

This example is a collection of models showing good and bad practices for the different types of subsystems available in Simulink. For function-call subsystems, you will find a large set of models. The green examples show the correct way to connect function-call subsystems and the red examples explain common errors.

Simulink Subsystem Semantics

For the example above,sl_subsys_fcncallerr7is the one you are looking for.

Now it's your turn

I hopesl_subsys_semanticswill be as useful for you as it is for me! Give that a look and leave us acomment below.

|

Comments

To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.