MATLAB Answers

constant compare only drives one reset

조회 수: 1(최근 30일)
MJ
MJ 2021년 5월 6일
댓글: Jonas 2021년 5월 10일
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
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
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개)

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by