Writing S-Functions    

Sample Times

Simulink supports blocks that execute at different rates. There are three methods by which you can specify the rates (i.e., sample times):

In the case of block-based sample times, your S-function specifies all the sample rates of the block and processes inputs and outputs at the fastest rate specified if all the sample times are integer multiples of the fastest sample time. (If your sample times are not multiples of each other, Simulink behaves differently. See "Sample Time Colors" in chapter 9 of Using Simulink for more information.) When using port-based sample times, your S-function specifies the sample time for each input and output port. To compare block-based versus port-based sample times, consider two sample rates, 0.5 and 0.25 seconds respectively:

You should use port-based sample times if your application requires unequal sample rates for input and output execution or if you don't want the overhead associated with running input and output ports at the highest sample rate of your block.

In some applications, an S-Function block may need to operate internally at one or more sample rates while inputting or outputting signals at other rates. The hybrid block- and port-based method of specifying sample rates allows you to create such blocks.

In typical applications, you will specify only one block-based sample time. Advanced S-functions may require the specification of port-based or multiple block sample times.


 Custom Data Types Block-Based Sample Times