Stateflow Timer issue, if else loop not working properly

5 views (last 30 days)
Dear all
I am facing a small issue with implementing manual timer in stateflow using an if-else loop
My model executes the entire loop in a simgle sample time and it does not delay the output which is what I want
Can anyone throw some light on this?
I have implemented timer logics in simulink and they work fine, i.e. the count increases every sample time
But in stateflow it somehow does not work
I want the out to become TRUE only after the triangular loop finishes executing, till then I want the out to be FALSE
Sample time of my model is 5ms (0.005)
The model implementation looks like this:
Top Level Model
Inside implementation:
actual logic
Observed output:
Expected output:

Answers (1)

Yash
Yash on 30 Sep 2023
Hi Ganesh,
I understand that you are facing difficulties in creating a loop with certain conditions in Stateflow. The issue you are experiencing is likely due to the usage of junctions, which causes the entire loop to be simulated in a single time step. To resolve this, I recommend replacing the junctions with states.
Using states instead of junctions ensures that there can only be one transition between states in a single time step, whereas multiple transitions can exist between junctions. This change will help you achieve the desired behavior for your loop.
Refer to the example below to implement the loop:
Note that not all junctions are replaced with states in this example, as doing so would result in multiple time steps for a single iteration.
Additionally, you can utilize the "after" function to introduce delays between states. This simplifies the implementation of delays without the need for complex timer and loop logics. An alternative implementation of your model without any timer logic using the "after" function is shown below.
Refer to the following MATLAB documentation to get more details about the "after" function:
I hope this addresses your query.
Best Regards
Yash

Categories

Find more on Complex Logic in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!