- You can use a "Switch" block in place of the "OR" block.
- 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.
- Link the output of the Unit Delay block to the other input of the "Switch" block.
- Establish a relationship between the comparison block (simulation time compared to Cycle_Time) and the control input of the "Switch" block.
- Direct the output of the "Switch" block to the "multiplication" and "subtraction" blocks to calculate the adjusted time.
- Integrate the adjusted time signal into the larger system model.
How to create a time signal that resets to zero once a set amount of simulation time is reached?
5 views (last 30 days)
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 on 5 Sep 2023
Edited: Aman Banthia on 5 Sep 2023
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.
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:
Switch output between first input and third input based on value of second input - Simulink - MathWorks India
Hope the above solution helps you.