If you neglect implementation details when you begin building a Simulink model you may face unexpected errors and warnings later in the project. Here are some good practices for preventing that scenario.
At the outset, most settings come from the defaults. All the solver settings are configured to accommodate the broadest possible range of models, and many sources are configured to use the base rate, or continuous update. Data types default to double to ensure the most flexibility in the environment and enable you to assemble a high-level proof of concept.
As the design matures, it's a good idea to lock down settings. By doing so you ensure that the final model meets requirements and that discrepancies between the design and implementation can be addressed early. You can lock down model behavior by doing the following:
Run Simulink Model Advisor checks and address issues that arise.
The Model Advisor catches many common modeling errors and gives most users a good starting point for refining their model.
Address all diagnostic warnings or errors.
Simulink diagnostics provide checks for problems that commonly occur when modeling with default settings (Figure 1). They are a first line of defense.
(Click to enlarge)
Figure 1. The Configuration Parameters, connectivity diagnostics panel.
Raise the diagnostic level.
Most diagnostics can range between warnings levels of None, Warning, and Error (Figure 2). When you have corrected any settings that are causing warnings, consider raising the diagnostic levels to Error. This will guarantee that your model informs you when a design change produces a suspect behavior.
(Click to enlarge)
Figure 2. Key diagnostics.
Set signal dimensions, data types, and sample times in key locations.
Root-level input ports and inputs to atomic subsystems should be fully specified unless the atomic subsystem is required to dynamically size or inherit its sample time and data types. When bus signals pass through boundaries between components, use bus objects to provide this level of type and size checking. You can use Signal Specification blocks, but a better option is to add Simulink. Signal data objects to the model workspace to control type and size information. Fully specify Mux and Demux port dimensions by using vectors of widths to set the number of ports. For example, for a Demux with a vector of 8 elements at its input and 3 outputs of width 2, 2, and 4, the number of outputs is [2 2 4].
Remove auto solver settings and uncheck "Automatically handle data transfers between tasks."
Use your knowledge of the model to set the appropriate step size for the solver. If you are working with a variable step solver, and using "auto" for the "Max step size" Simulink computes your maximum step size to be (Tstop – Tstart) / 50. Set the value explicitly to ensure that a change in simulation length doesn't unexpectedly change the simulation. Uncheck "Automatically handle data transfers between tasks" and manually insert rate transition where needed.
[This article first appeared in The MathWorks News and Notes and is presented here by permission of the author.]