mdlref_conversion.mdl Open this Model

Converting Existing Models to Using Model Reference Demonstration

Introduction

This demonstration shows one way to automate the conversion of an existing model with buses to using model reference. (For a quick introduction to Model Reference, run the Basic Model Reference Demo and for a quick introduction to bus signals, run the Bus Signal Demo.)

Demo Requirements

During this demonstration, Simulink will generate code in a Simulink project directory created in the current working directory. If you do not want to (or if you cannot) generate files in this directory, you should change the working directory to a suitable directory.

If you plan to alter the demonstration models or functions:

  1. Preserve the demo in its original state by copying the following files in your MATLAB installation directory without changing their names to a different directory:

  2. Change your current working directory to the directory to which you copied the files.

  3. Continue with the demonstration.

Description of the Conversion Process

This demonstration function is: sl_convert_to_model_reference. It has two required inputs, the name of the model to convert and the directory in which to save the converted model.

This function looks for Atomic Subsystems in the model and creates stand alone models from them. These created models will have all of the same compiled properties (for example sample times, data types, dimensions) as the original subsystem. The Subsystem in the original model is then replaced with a Model Block. Additionally, any buses going into or out of the subsystem will have bus objects created for them and set on the bus creators and inport and outport blocks.

If you would like to use this demonstration function as a starting point for converting your own models, you will also probably be interested in the four helper functions: If you would like to use these functions as a starting point for your own conversion function, please use the above links to open them and save them in a new location with a new name. Please see the help in sl_convert_to_model_reference for a listing of some of the things that this function does and does not support.

If you haven't already opened it, open the demo model mdlref_conversion.

Description of the Original Model for the Demonstration

This model contains a Bus Creator block, COUNTERBUSCreator, that drives an atomic subsystem Bus Counter, modeling a simple counter. A bus signal called COUNTERBUS feeds the input signal and the saturation limits of the counter into the subsystem. The COUNTERBUS contains two more bus signals, the LIMITBUS and the SIGNALBUS. LIMITBUS contains the upper and lower limit values of the counter and SIGNALBUS contains the signal used in counting. The following shows the structure of COUNTERBUS:

Note that in the mdlref_conversion demonstration model the "Specify properties via bus object" checkbox is unchecked on all three of the Bus Creator Blocks above.

Note also that the Inport of the subsystem Bus Counter, does not specify any of its signal properties on the Signal specification tab of its parameter dialog, nor does the Outport.

Perform the Conversion

Now you can convert mdlref_conversion. To try this demonstration function on another model you will have to use sl_convert_to_model_reference at the command line.

Examine the Result

Two new models have been created:

The new model, mdlref_conversion_converted, contains a Model block, Bus Counter, that references Bus_Counter, a model that contains the contents of the original subsystem Bus Counter, in the original model mdlref_conversion.

Comparing the original model, mdlref_conversion with the newly created model, mdlref_conversion_converted, there are several differences worth noting:

  1. Bus objects have been specified on the bus creators ( COUNTERBUSCreator, SIGNALBUSCreator, and LIMITBUSCreator) in the new model mdlref_conversion_converted, but there were none in the original model's bus creators ( COUNTERBUSCreator, SIGNALBUSCreator, and LIMITBUSCreator).
  2. A bus object has been specified on the Signal Specification tab of the parameter dialog of the Inport block in the referenced model where none was needed in the Inport of the original subsystem
  3. A bus object has been specified on the Signal Specification tab of parameter dialog of the Outport block in the referenced model where none was needed for the Outport of the original subsystem
  4. Note: You can view these bus objects by selecting the MATLAB workspace in the Model Explorer. You can also view the bus structures in the Bus Types Editor.

  5. Sample time colors match in the referenced model and the original subsystem
  6. If you simulate the new model and simulate the original model and examine the new scope and original scope, you will see the same results.

Exit