Stateflow Timer issue, if else loop not working properly

5 次查看(过去 30 天)
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:

回答(1 个)

Yash
Yash 2023-9-30
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

类别

Help CenterFile Exchange 中查找有关 Complex Logic 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by