Clear Filters
Clear Filters

Speed of Sfunction builder in Simulink

2 views (last 30 days)
I have a S-function builder in Simulink, which reading and delopy data from/to arduino. I have also set the Fixed-step time(Fundamental sample time) to 0.1s. I would like to know what is the processing speed that executed the S-function. Is it equal to the sample time? If it is equal to the sample time, what is the minumum sample time I could set?
Thank you.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 8 Feb 2023
Edited: Fangjun Jiang on 8 Feb 2023
The execution time of the S-function depends on the processing task and the CPU. Generally, more complex task, more time. More powerful CPU, less time.
In simulation, it doesn't really matter. It could take 1 second to finish the task, and then the simulation moves to the next 0.1 time step. There is no constrain between the sample time and processing time. The speed of the simulation calculation could be faster or slower than the simulation clock. You can use Simulink Profiler to find out the processing time of each block.
In real-time simulation/execution involving hardware, of course, the processing time needs to be smaller (preferably quite smaller) than the sample time. Use the tools supplied by the hardware (arduino, dSPACE RTI, etc.) to find out the worst case execution time and then decide the proper sample time. Some system may report an "overrun" flag if execution time is longer than the sample time. The processing time could vary due to some processing being conditionally executed. So make sure to exercise the worst case processing.

More Answers (0)


Find more on Block and Blockset Authoring 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!