Newsletters - MATLAB Digest
Developing a Multitarget Model
by MathWorks Novi Development Team
If you have questions or comments regarding this article, please contact Steve Toeppe
This article describes how to develop a dictionary-driven Simulink model that accommodates multiple target controllers. A multitarget model provides a great deal of flexibility for targeting multiple controllers by supplying a variety of data dictionaries within a single model, as shown in the figure below. Each dictionary provides different simulation characteristics and code generation implementations. With a double mouse click, you can select the desired dictionary. Then, although the model (the algorithm) remains the same, the annotations appear in the model from that dictionary. After generating code, compiling, and linking, you can execute the resulting downloadable files on the target controller that corresponds to the selected dictionary.
![]() |
| Figure 1: Generating code from a dictionary-driven model. Click on image to see enlarged view. |
Advantages of a Multitarget Model
Multitarget, model-based design prevents you from having to write, test and, rewrite code for each target controller. With dictionary-driven, model-based design, you can use one model to simulate different targets. Using a multitarget Simulink model, you can experiment by selecting a dictionary, changing data types, and performing scaling in that dictionary. You can then run a simulation to see the effects of data type and resolution tradeoffs in the simulation environment.
This example model does not address aspects of embedded controller development other than selecting data types and scaling.
Description of the Supplied Model and Dictionaries
The article describes a multitarget Simulink model that is a generic powertrain engine controller for embedded systems called multi_target.mdl. The Input Processing block (shown in Figure 2) processes inputs that originate in sensors. The middle block, Control algorithm, processes the control algorithm, changing the raw sensor inputs to engineering units. This block contains a basic two-gear transmission model and calculates basic spark angle correction and fuel flow rate. The right block, Output processing, processes the outputs that control actuators. Each block contains subsystems that further specify the detailed behavior of the model.
The table below describes the five data dictionaries supplied with this model. These dictionaries represent possible target controller applications.
| Dictionary | Description |
|---|---|
| 16-bit bin 8 dictionary | Low-cost microprocessor, such as Motorola HC12 Limited in memory and cost Runs best with 16-bit data |
| 8-bit bin 1 dictionary | Lowest-cost microprocessor, such as Motorola HC08 or HC05 Eight bits with one-bit resolution Low cost and limited CPU |
| 32-bit bin 10 dictionary | For microprocessors that provide fixed point with 10 bits of resolution Select when the target controller is high power but not premium (e.g., a controller that has fixed point, such as Motorola 68332 or Intel C196). |
| Constrained dictionary | This dictionary represents a mixture of word sizes and resolution. You might select this dictionary when:
|
| Float dictionary | For those microprocessors that provide high precision (single precision) for embedded controllers. Select this dictionary when you're working with high-power target controllers, such as Motorola 555 or 565 microprocessor. |
Before and After a Dictionary Selection
The two screen captures below illustrate how the model changes after double-clicking a dictionary button. The first shows the model immediately after it was opened. Notice that input and output lines are labeled (underneath the lines). However, annotations (also known as port data types on the Format menu in Simulink) are not indicated (above the lines). After double-clicking one of the dictionary buttons under the model, the annotations from that dictionary appear on the model. The second screen capture illustrates this after the Load 32-bit Bin 10 Dictionary button has been double-clicked.
![]() |
| Figure 2: Before dictionary selection. Click on image to see enlarged view. |
![]() |
| Figure 3: After dictionary selection. Click on image to see enlarged view. |
Changing Values in a Dictionary
You can change data type and scaling values in a non-float dictionary, and can change data type values in a float dictionary. See below for the process of changing a value for input port 1 (ECTSensor).
- Click the "1"on input port 1:

- The Block Parameters dialog box appears, as shown below.
Figure 4: Dialog box with data type and scaling fields.
Click on image to see enlarged view. - To change the data type value, on the MATLAB command line, issue the command ECTSensor.datatypei = x (where x is the desired value, such as sfix(16), ufix(32), float('single')).
- On the Simulink Edit menu, select Update diagram.
- To change the scaling value on the MATLAB command line, issue the command ECTSensor.scalingi = y (where y is the desired value, such as 2^-8, [ 2^-8 0.5], [2^-4, 0.25], [2^-4 0]). Note: This is only applicable to nonfloat dictionaries. For details, see an Overview of Blockset Features in the Fixed-Point Blockset documentation.
- On the Simulink Edit menu, select Update diagram.
Code Generation Report
Next, double-click the Build button. Real-Time Workshop Embedded Coder generates the code generation report, like that shown in the next figure. Under Generated Source Files, all of the generated .c and .h filenames appear. Click a filename and it opens in the right pane for inspection.
![]() |
| Figure 5: Code generation report. Click on image to see enlarged view. |
Correlation Among Dictionary, Model, and Generated Code
An input or output on the model identifies a data object that has certain properties, including the data type and scaling (resolution). It becomes an identifier in the generated code. As such, there will be a defining declaration for this variable in a generated file. Also, the variable will be used in the file that contains the code body.
It will prove helpful to track these interrelationships among data dictionary annotations, the model, and the generated code. A good understanding of these relationships helps you manage the code generation process and yield the best code from the clearest annotations and models. We will compare the effects of two dictionary selections on a particular signal: the ECTSensor signal at input port. Figures 6 and 7 show the effects of the two dictionaries. Figure 6 shows the effects after selecting the 16-bit bin8 dictionary. Compare these with the effects of selecting the float dictionary, shown in Figure 7.
Figures 6 & 7 display the effects, after the user performs the following:
- Download the model from MATLAB Central.
- Open the model. On the model, the ECTSensor signal line does not have an annotation.
- Load a dictionary. Signal ECTSensor takes on the respective annotation that designates the data type and scaling of ECTSensor. Typing a command on the MATLAB command line also displays this information for the ECTSensor data object. Double-clicking the input port on the model displays the Block Parameters dialog box. The Output data type field on this dialog shows a reference to the data type ECTSensor.datatypei. The Output scaling field on this dialog shows a reference to the scaling ECTSensor.scalingi.
- Issue the command ECTSensor.datatypei on the MATLAB command line. The data type for this signal shows in the command window.
- Issue the command ECTSensor.scalingi on the MATLAB command line. (This is only applicable for nonfloat dictionaries.) The scaling for this signal shows in the command window. Note: there is no user-specified scaling for float. For details see Selecting the Output Scaling in the Fixed-Point Block Set documentation.
- Double-click the Build button. After a moment, the code generation report appears. Open the InputProcessing.c file and look for an occurrence of the variable ECTSensor as a parameter in a function call. Notice that the data type specified in that function call is the same data type as was indicated on the model and on the MATLAB command window.
- Click the ECTSensor parameter name to open the file where the defining declaration of this variable is found. Notice that its data type is the same as was indicated on the model, the MATLAB command window, and in the function call.
![]() |
| Figure 6: Fragments of model and code for 16-bit bin 8 dictionary. Click on image to see enlarged view. |
![]() |
| Figure 7: Fragments of model and code for float dictionary. Click on image to see enlarged view. |
Minimum System Requirements
The multitarget model described in this article requires that you install the following MathWorks Release 13 products:
- MATLAB
- Simulink
- Real-Time Workshop
- Real-Time Workshop Embedded Coder
- Fixed-Point Blockset
- Stateflow
- Stateflow Coder
Installing and Using the Multitarget Model
- Unzip the folder that contains the multi_target files and place them in the desired folder. The files can be obtained from the MATLAB Central.
- Add the desired folder (of the previous step) to the MATLAB path.
- Start MATLAB.
- Click the Current Directory tab and, using the Current Directory browse button, navigate to (open) the folder where you placed the multi_target files in step 1. The files appear under All Files.
- Double-click multi_target.mdl. The model appears without annotations.
- Double-click the desired dictionary button. The model now appears populated with annotations from this dictionary.
- If desired, change one or more values in the dictionary, as explained previously.
- Generate code by double-clicking the Build button. After a moment, the code generation report appears. All of the generated files are listed under Generated Source Files, as shown previously in Figure 5.
- Click the desired filename to open it for inspection.
- Repeat steps 5 through 8 as desired.
Related Documents
See the following MathWorks documentation for information related to this article.
- Stateflow User's Guide
- Fixed-Point Block Set User's Guide
- Using MATLAB
- Using Simulink (for how a model's data type and scaling are designated on a signal line)
- Real-Time Workshop User's Guide
- Real-Time Workshop Embedded Coder User's Guide





