Understanding the merge block

In Simulink, the merge block is documentation states

“The Merge block combines its inputs into a single output line
whose value at any time is equal to the most recently computed
output of its driving blocks.”

As clear as that statement is there are still questions about the behavior of the merge block.  This post attempts to clarify those questions.

Quiet night

The first and most common question is “what happens when none of my subsystems are enabled/triggered?”  In this example, we have 3 subsystems “A”, “B”, and “C” which are enabled when the driving signal is equal to their enumerated namesake.  The output from the subsystems is a simple enumerated constant equal to the subsystems name.  E.g. subsystem A outputs a value of “A”…

merge_1

However, the way I have configured the driving signal it includes an enumerated value of “abcs.D” in addition to the A,B,C values.

mergeOut

In this example when the value of the driving signal is equal to abcs.D none of the subsystems are enabled.  In this case, the merge block simply outputs the last value input into the system.

Default merge subsystems

In the example above there is an unpredictable behavior due to the lack of a “default” subsystem.

download.jpg

merge_3

The “Default” subsystem should execute every time step when the other systems are not running.  In this example, it is enforced through simple logical operations.

Multiple execution

In versions of Simulink from 15a and on (it could be earlier but that is the latest I had installed on my laptop) if you try and execute more then one subsystem during the same time step you will get an error message

merge_2In this case, I tried driving my two subsystems “LiveCat” and “DeadCat” with a “Schrodinger Waveform”™ vector.  When the vector was in the “Both” mode then both subsystems were active and the error message was triggered.

wave

 

2 thoughts on “Understanding the merge block

    1. Sorry for the delay in getting back to you. The code for a merge block will depend on the type of signals fed into the block and how they are consumed. The merge block is a virtual block and, as such may or may not produce any code. If the signals do pass through an atomic boundary (such as a model reference) then most of the time the signals are converted into an array.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.