constant compare only drives one reset
2 views (last 30 days)
Show older comments
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 Comments
Jonas
on 7 May 2021
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.
Accepted Answer
Jonas
on 7 May 2021
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 Comments
Jonas
on 10 May 2021
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.
More Answers (0)
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!