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”…
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.
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.
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
In 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.
What is the c code for merge block…..?
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.
Hi Michael, in our team, we had a lot of discussion around the question why we need the merge-block if we can use a switch-block to route the outputs of the active subsystem to the output port. Is there any good reason not to use the switch-block instead of the merge block?
Use of the merge block is for when you have enabled / triggered sub-systems. When this is the case the upstream code (in the subsystem) does execute.
Additionally the merge block allows some optimizations in the code generation.