Writing S-Functions    

Sample Times

Simulink supports blocks that execute at different rates. An S-function block can specify its rates (i.e., sample times) as:

With block-based sample times, the S-function specifies a set of operating rates for the block as a whole during the initialization phase of the simulation.With port-based sample times, the S-function specifies a sample time for each input and output port individually during initialization. During the execution phase, with block-based sample times, the S-function processes all inputs and outputs each time a sample hit occurs for the block. By contrast, with port-based sample times, the block processes a particular port only when a sample hit occurs for that port.

For example, 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 might 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 specify only one block-based sample time. Advanced S-functions might require the specification of port-based or multiple block sample times.


  Custom Data Types Block-Based Sample Times