How can I use sample time internally in Stateflow
Show older comments
Hello,
My fixed solver discrete type model has sample time of 20ms.
I want to use this sample time in Stateflow to start a counter and increment it in 20ms time.
How can I use this sample time in Stateflow?
Thank you.
Note: If sample time changes, the counter should take the updated sample time.
Accepted Answer
More Answers (2)
Krishna Anne
on 17 Jun 2019
0 votes
At the init trigger of your SF diagram start an independent counter and increment it by 1 (loop around). This way even if your solver settings change will be aligned with the counts as that many time samples.
Also, please remember that this is not the real definition of sample time, Simulink only mimics as per your solver settings. See the documentation about solver carefully.
Todd
on 17 Oct 2024
0 votes
Came here to look for a better solution. Here are two imperfect solutions.
1) Use temporal logic, ex. after(5,sec). This makes the chart much easier to read, but in my simple case generates way more code than necessary. Also, duration seems to always generate doubles. I would use temporal logic for anything more complicated than a debounce.
2) Input the task rate and use the Weighted Sample Time block. Look out for unintended doubles.
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!