When harnessing the model, the model is compiled to determine the fixed sample times. Note that there can be more than one, since there may be multiple rates in the model. Always initialize the tick rate to be the value that Matlab returns as the lowest fixed period. Matlab follows the following rules:
1.When the fundamental sample time is not set to auto, all discrete steps specified in the model (sample times in blocks, etc.), must be an integral multiple of the fundamental sample time. For example, if the fundamental sample time is set to 0.003, you can have blocks of 0.003, 0.006, 0.009, but NOT blocks of 0.003, 0.005, 0.009 since 0.005 is not divisible integrally by 0.003. In this case, the default tick period is 0.003. The user can change the tick period in the transform to 0.001 (which would unnecessarily tick the S‑Function at 2 times out of 3) or 0.006, 0.009, etc. (which, by ticking at a greater rate, would miss things).
When the fundamental sample time is set to auto the following occurs:
2.If the model does not define any periodic sample times (it only contains continuous states), Matlab chooses a step size that divides the total simulation into 50 equal steps (if the simulation is set to run Inf, this time is 0.2). However, by virtue of the fact that the S‑Function block is a discrete block, the tick period specified in the Transform is the fundamental sample time used by the model. The default is the 50 equal steps (or 0.2), however the user can change to whatever you want for the run.
3.If the model contains periodic sample times (via discrete blocks, for example), Matlab reports the least common denominator (LCD) of the specified sample times, and that is the value that is used. Note that in practice, the LCD value returned follows the same rules as if the fundamental sample time is set to that value as described above in case 1 (the user CAN change the value, but it is not recommended, since it either ticks the S‑Function needlessly or misses transitions).
Any change to any sample period requires a re-harness of the model. However, it should be noted that if the model contains only continuous states, the re-harness resets the tick period on the transform to be the default as described above in case 2.
Special note: The fixed sample time is available only if the Periodic sample time constraint is set to Unconstrained. Therefore, if the Periodic sample time constraint is set to "ensure sample time is independent," it is implied that the model will be used as a submodel and that the sample times are inherited from the parent context. It has a special meaning which basically sets the solver to discrete (no continuous states), and the fundamental sample time to "auto." It also means that MxVDev can not directly harness these models, since there is no way for the S‑Function to inherit the sample times of the model, as the sample time in the S‑Function block is set to be the tick rate of MxVDev. The main reason for this is that MxVDev is driving the simulation, not Matlab. Therefore, to test these types of submodel blocks, either test with the Periodic sample time of unconstrained (and the discrete solver and auto) or create a higher level model that contains the model with its inherited times and harness that model.