How to create a time signal that resets to zero once a set amount of simulation time is reached?

조회 수: 4 (최근 30일)
I'm trying to create an adjusted time signal that resets to zero once a set amount of simulation time passes. The block diagram below shows my current method of achieving this behaviour.
I compare the simulation time to a constant where I want the reset to occur (Cycle_Time). Once this is satisfied, the boolean is used as an input to a MATLAB function block which counts up and saves the output each time the condition is satisfied. The output of the function block is then mutiplied by the Cycle_Time constant and subtratced from the total simulation time to give the adjusted time. The adjusted time signal needs to be used as an input to the larger system model.
My issue is that after the first time the Cycle_Time condition is satisfied, I need to use the adjusted time as an input to the function block if I want to reset the simulation time more than once.
I tried adding an OR gate and repeating the logic used for the initial reset with the adjusted time signal instead of the simulation time signal but it caused an algebraic loop error. See figure below for reference.
Is there a better way to achieve the desired time resetting behaviour?

채택된 답변

Aman Banthia
Aman Banthia 2023년 9월 5일
편집: Aman Banthia 2023년 9월 5일
Hi Jack,
I understand that you are trying to make the time signal reset after the simulation time is reached while using a unit delay block and logical operator OR block.
Here's an alternative approach :
  1. You can use a "Switch" block in place of the "OR" block.
  2. Establish a connection between the output of the MATLAB Function block (the adjusted time signal) and both the "Unit Delay" block and one input of the "Switch" block.
  3. Link the output of the Unit Delay block to the other input of the "Switch" block.
  4. Establish a relationship between the comparison block (simulation time compared to Cycle_Time) and the control input of the "Switch" block.
  5. Direct the output of the "Switch" block to the "multiplication" and "subtraction" blocks to calculate the adjusted time.
  6. Integrate the adjusted time signal into the larger system model.
By using the Switch block, you can select between the adjusted time from the previous cycle (stored in the Unit Delay block) and the adjusted time from the current cycle (output of the MATLAB Function block) based on the comparison result. This avoids the algebraic loop error because the Switch block breaks the loop and allows for proper signal propagation.
You can refer to the below documentation to know more about the usage of Simulink Switch Block:
Hope the above solution helps you.
Best Regards,
Aman Banthia
  댓글 수: 1
Jack Smith
Jack Smith 2023년 9월 5일
편집: Jack Smith 2023년 9월 5일
Hi Aman,
Thanks for the response.
I understand how the 'Switch' block approach solves the algrebraic loop error but I'm struggling to see how the 'Switch' block is incorporated into my existing model so that the first time reset is still accounted for.
If both of the inputs to the 'Switch' block are the adjusted time signal, where does the first time reset signal connect?
Would it be possible to explain your alternative approach with a Simulink block diagram for clarity?
Many Thanks
** Edit
Actually, I ended fixing this issue by using your 'Switch' block approach on the output of the MATLAB but I kept the 'OR' gate to take the initial reset into account as well.
Thanks for the help!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Generation에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by