Karlo
Karlo

Reputation: 1708

Is it possible to stop a Simulink simulation when a certain condition is met?

Assume that you have a Simulink simulation where a certain signal is first positive and after some time t in a given interval, it becomes negative. Your goal is to find the zero-crossing.

A first approach would be to plot the signal over the given interval, save it and calculate the zero-crossing.

When repeating this simulation numerous times for varying parameters, it would be beneficial to be able to stop the simulation after the signal has become negative. Then there is already enough information for the calculation of the zero-crossing in Matlab. How could you do that?

Upvotes: 4

Views: 12105

Answers (3)

Mikhail_Sam
Mikhail_Sam

Reputation: 11238

Another ways:

  1. You can use Hit Crossing Block in Simulink to find time at the moment of hitting zero.

  2. Another way - use any Trigger or Resettable system. It detects the zero crossing too. For example: this question at SO.

  3. Of course you can also use User Defined function to detect zero crossing by your hand and do whatever you want with the signal at the same time.

About making a lot of simulations and then stops: you can use Check Upper Static Bound for automatically stops simulation at the moment when zero will be crossed in nth time. For example: enter image description here

I set upper bound = 10 for this block and this stops at 10th crossing. There are a lot of ways to save function values in this points or just array of times but this is an another question :)

Upvotes: 3

am304
am304

Reputation: 13886

Yes, use the Stop Simulation block with the appropriate logical input to the block:

enter image description here

Upvotes: 3

Stewie Griffin
Stewie Griffin

Reputation: 14939

You can use an if / else block to control the flow in the Simulink model. In the if / else block, you can choose the condition if u > 0, continue as normal if it's true, and use the else-option to bypass the rest of the flow you would otherwise run. For instance jump directly to the scope.

enter image description here

Upvotes: 3

Related Questions