constant compare only drives one reset

2 次查看(过去 30 天)
In the attached simple test I have a simple step counter from -5000 to +5000. The constant compare block drives the 'Delay' reset and the 'Stop' However, the stop never triggers but the delay reset does as shown by the scope. Is this a bug or do I need to somehow split the output of the constant compare?
  2 个评论
Jonas
Jonas 2021-5-7
Why would you want to reset the Delay block when you are stopping the simulation anyway?
I recreated your model but I am getting algebraic loop errors.
MJ
MJ 2021-5-7
Just set the albegraic loop error to none. There may be a more effective/efficient way to implement a step counter but I serached the internet everyone seems to do it the same way. This test is a snippet from a much larger model. The second output is an output port from the subsystem. The stop is there to show that it never triggers. If it triggered the scope would show a single sequence.

请先登录,再进行评论。

采纳的回答

Jonas
Jonas 2021-5-7
The root-cause is because the Delay block is Direct Feedthrough. This means that it processes its inputs and directly sets the new outputs in one timestep.
What happens is the Delay block will output a value for which the condition '>5000' is true. This condition resets the Delay block, and within the same cycle, the output of the delay block resets to zero, which renders the '>5000' condition to false again. After this has happened, the STOP block will be executed, which never sees a 'true' input.
This mechanism is also the root-cause why you are getting an algebraic loop error.
When you display the execution order you see the 'STOP' block is executed last, and because of the algebraic loop, the brief moment the condition is true is removed again.
  2 个评论
MJ
MJ 2021-5-7
Thanks! Still learning this tool and did not know about execution order display. This explains the behavior I'm seeing but does not solve my original problem of driving two outputs.
Jonas
Jonas 2021-5-10
If you add another Delay block before the compare to constant, the value will be '>5000' for one cycle time which you can use to drive another signal. Also, it breaks the algebraic loop.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

产品


版本

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by