Stateflow different timesteps for an embedded application

6 views (last 30 days)
I am new to Stateflow and need more information on timesteps.
My system wakes up every second to run the state chart ( rt_OneStep() ) yet some state chart transitions rely on waiting a number of milliseconds before taking a transition. This all occurs before going back to sleep. The exectution time of the state machine, most of the time, would be less than a millisecond....not that this matters.
So basically, rt_OneStep() is called every second yet I have transitions that use after(10, milliseconds)...how do I implement the millisecond part since my timestep is 1 second?
Thanks

Answers (1)

Jeevan Thomas
Jeevan Thomas on 7 Nov 2013
It appears that you already have a model from which you generated code and trying to run it on a platform by attaching rt_OneStep() to give the base tick (similar to sample time configured in Simulink configuration parameters. All functions that map to your implementation in Simulink model is called from rt_OneStep() [including the one from Stateflow]. So it is not possible to call your rt_OneStep() every second and do switching of transitions in Statechart (since this is part of the same model) unless you make the statechart as an standalone function and call it individually from your ISR scheduler. But in this case, be ready to compromise on functionality between MiL and PiL.
Else the only option is to bring down the sampling time to milliseconds as in your requirement.
  1 Comment
Duane
Duane on 19 Nov 2013
I am having a hard time believing that, for embedded development, you cannot have multiple time periods. How then, do developers with battery operated systems wake up every second, perform what they need to perform (which is running a statechart dependent on mSec timing for delays) and then go to sleep for the remaining part of the one second? I currently use VisualSTATE from IAR. It has an API that adds events to the queue which could be a mSec event. I was really hoping to use Superstep and an API for a mSec event that occurred in an ISR. My intention is to use Stateflow only and not Simulink (functions etc).
Thanks...it seems I am missing something very basic and/or am used to a different structure.

Sign in to comment.

Categories

Find more on Simulink Coder 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!