The simulation always stops with the compare unit

I run the simulation model and it always remind me as Fig.I. When I change the setting according to the reminder as Fig.II the simulation still stuck there but no reminder shows anymore.

2 Likes

The attached simple model demonstrates your problem: Whenever the input signal of the Compare to Constant block crosses zero, the change of the output signal immediately causes the input signal to change its direction and cross the zero line again. And again. And again.

This behavior will bring the simulation to a virtual standstill (notice the small time steps in the scope above). This is why PLECS by default flags an error after 1000 repetitions. You can disable the error message itself (by setting the corresponding parameter to “0”), but this will not solve the actual problem. (As a side note, it is almost never a good idea to simply silence error or warning messages.)

To solve the problem, you must limit the switching frequency of the Compare to Constant block in one way or another. Here are two possibilities:

Add some hysteresis by replacing the Compare to Constant block with a Relay block with suitable upper and lower thresholds (e.g. “1e-6” and “-1e-6”).Set the switching frequency explicitly by inserting a Zero Order Hold with a suitable sample time in front of the Compare to Constant block.

ZeroCrossingProblem.plecs (7.62 KB)