Filter löschen
Filter löschen

constant compare only drives one reset

1 Ansicht (letzte 30 Tage)
MJ
MJ am 6 Mai 2021
Kommentiert: Jonas am 10 Mai 2021
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 Kommentare
Jonas
Jonas am 7 Mai 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.
MJ
MJ am 7 Mai 2021
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jonas
Jonas am 7 Mai 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 Kommentare
MJ
MJ am 7 Mai 2021
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 am 10 Mai 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by