Thanks for the additional information Pablo. I can recreate your observations.
Firstly, the variable B is essentially a discrete state and really should only be assigned in the update function. From the PLECS Manual:
> In general, output signals should be continuous and smooth during minor time steps; discontinuities or sharp bends should only occur during major time steps. Whether or not the call is made for a major time step can be inquired with the IsMajorStep macro. For details see "Modeling Discontinuities" below.
> Note It is not safe to make any assumptions about the progression of time between calls to the output function. The output function may be called multiple times during the same major time step, and the time may jump back and forth between function calls during minor time steps. Code that should execute exactly once per major time step should be placed in the update function.
So in your case if the output function is called multiple times during the same major time step, then B will toggle within the same model step, toggling the gate and leading to the cyclical switching error. Changing the direct feedthrough setting (or adding a delay) changes the block ordering, and therefore the solver behavior such that the output function call was only done once.
Attached is an example where we can print to the console each time the output function runs and we can see it's running twice with the direct feedthrough enabled.
A few other observation from my side, again pointing to this being related to the solver behavior:
- I did not observe this error when using PLECS 4.7. I noted your model was in PLECS 4.6 and saw the error message when I down-graded.
- You are using a fixed-step solver. Switching to a variable-step solver eliminates the error message (but not the underlying issue) in PLECS 4.6.