User`s guide

Quick Start Tutorials
3-51
Tutorial 6: Generating Code for a Referenced
Model
The Model block, introduced in Version 6 of Simulink, enables an existing
Simulink model to be used as a block in another model. When a model
contains one or more Model blocks, we call it a top model. Models represented
by model blocks are called referenced models in that context.
Model blocks are particularly useful for large-scale modeling applications.
They work by generating code and creating a binary file for each referenced
model, then executing the binary during simulation. Real-Time Workshop
generates code for referenced models in a slightly different way than for top
models and stand-alone models, and generates different code than Simulink
does when it simulates them. Follow this tutorial to learn how Simulink and
Real-Time Workshop handle model blocks.
In this exercise you create a subsystem in an existing model, convert it to a
model, call it from the top model via a Model block, and generate code for both
models. You accomplish much of this automatically with a demo function
called
sl_convert_to_model_reference. You also explore the generated code
and the project directory using the Model Explorer.
Part 1: Create and Configure A Subsystem Within the vdp Model
In the first part of this exercise, you define a subsystem for the vdp demo
model, set configuration parameters for the model and use the
sl_convert_to_model_reference function to convert it into two new models
— the top model (
vdptop) and a referenced model containing the subsystem
you created (
vdpsub):
1 In MATLAB, create a new working directory wherever you want to work
and
cd into it:
mkdir tutorial6
cd tutorial6
2 Open the vdp demo model:
vdp
3 Drag a box around the three blocks on the left to select them, as shown
below.