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

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Aman Banthia
Aman Banthia am 5 Sep. 2023
Bearbeitet: Aman Banthia am 5 Sep. 2023
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 Kommentar
Jack Smith
Jack Smith am 5 Sep. 2023
Bearbeitet: Jack Smith am 5 Sep. 2023
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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by