Generating HDL Code Using The GUI - Introduction To HDL Code..
Generating HDL Code Using The GUI - Introduction To HDL Code..
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
The following figure shows the top-level HDL Coder options pane as displayed in the Model Explorer.
1 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
If you are not familiar with Simulink configuration sets and how to view and edit them in the Configuration Parameters dialog box, see the following documentation: Setting Up Configuration Sets Configuration Parameters Dialog Box If you are not familiar with the Model Explorer, see Exploring, Searching, and Browsing Models. In the hands-on code generation exercises that follow, you will use the Configuration Parameters dialog box to view and set the coder options and controls. The exercises use the sfir_fixed demo model (see The sfir_fixed Demo Model) in basic code generation and verification steps. Back to Top
Creating a Folder
Start by setting up a working folder: 1. Start the MATLAB software. 2. Create a folder named sl_hdlcoder_work, for example: mkdir C:\work\sl_hdlcoder_work You will use sl_hdlcoder_work to store a local copy of the demo model and to store directories and code generated by the coder. The location of the folder does not matter, except that it should not be within the MATLAB folder tree. 3. Make the sl_hdlcoder_work folder your working folder, for example: cd C:\work\sl_hdlcoder_work
2 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
Next, make a copy of the sfir_fixed demo model: 1. To open the demo model, type the following command at the MATLAB prompt: demos The Help window opens. 2. In the Demos pane on the left, click the + for Simulink. Then click the + for Simulink HDL Coder. Then double-click the list entry for the Symmetric FIR Filter demo. The sfir_fixed model opens. 3. Select Save As from the File menu and save a local copy of sfir_fixed.mdl to your working folder. 4. Leave the sfir_fixed model open and proceed to the next section. Back to Top
2. Observe that the Select tree in the left pane of the dialog box includes an HDL Coder category, as shown. 3. Click the HDL Coder category in the Select tree. The HDL Coder pane is displayed, as shown in the following figure.
3 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
The HDL Coder pane contains top-level options and buttons that control the HDL code generation process. Several other categories of options are available under the HDL Coder entry in the Select tree. This exercise uses a small subset of these options, leaving the others at their default settings. Code Generation Options in the Simulink HDL Coder GUI summarizes all the options available in the HDL Coder category. Back to Top
4 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
To save the current HDL code generation options to a new control file: 1. 2. 3. 4. Open the Configuration Parameters dialog box and select the HDL Coder options pane. Under Code generation control file, click the Save button. A standard file dialog box opens. Navigate to your current working folder and save the file as sfir_fixed_control.m. Select Save from the File menu. When you save the model, the control file linkage information is written to the .mdl file, and the control file linkage persists in future sessions with your model.
This tutorial uses a control file only as a mechanism for saving HDL code generation settings. This simple application of a control file does not require knowledge of any internal details about the file. You can also use a control file to direct or customize many details of the code generation process. It is strongly recommended that you read Code Generation Control Files, after completing this tutorial. Back to Top
5 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
hdlsetup also configures the model start and stop times and fixed-step size as follows: Start Time: 0.0 s Stop Time: 10 s Fixed step size (fundamental periodic sample time): auto If Fixed step size is set to auto the step size is chosen automatically, based on the sample times specified in the model. In the demo model, only the Signal From Workspace block specifies an explicit sample time (1 s); all other blocks inherit this sample time. The model start and stop times determine the total simulation time. This in turn determines the size of data arrays that are generated to provide stimulus and output data for generated test benches. For the demo model, computation of 10 seconds of test data does not take a significant amount of time. Computation of sample values for more complex models can be time consuming. In such cases, you may want to decrease the total simulation time. The remaining parameters set by hdlsetup affect error severity levels, data logging, and model display options. If you want to view the complete set of model parameters affected by hdlsetup, open hdlsetup.m in the MATLAB Editor. The model parameter settings provided by hdlsetup are intended as useful defaults, but they may not be appropriate for all your applications. For example, hdlsetup sets a default Simulation stop time of 10 s. A total simulation time of 1000 s would be more realistic for a test of the sfir_fixed demo model. If you would like to change the simulation time, enter the desired value into the Simulation stop time field of the Simulink window. See the "Model Parameters" table in the "Model and Block Parameters" section of the Simulink documentation for a summary of user-settable model parameters. Back to Top
6 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
1. Click the Run Compatibility Checker button. 2. The HDL compatibility checker examines the system selected in the Generate HDL for menu for any compatibility problems. In this case, the selected subsystem is fully HDL-compatible, and the compatibility checker displays the following message: ### Starting HDL Check. ### HDL Check Complete with 0 errors, warnings and messages. 3. The compatibility checker also displays an HTML report in a Web browser, as shown in the following figure.
Back to Top
Before generating code, select Current Folder from the Desktop menu in the MATLAB window. This displays the Current Folder browser, which lets you access your working folder and the files that will be generated within it. To generate code: 1. Click the Generate button.
7 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
2. As code generation proceeds, the coder displays progress messages. The process should complete successfully with the message ### HDL Code Generation Complete. Observe that the names of generated files in the progress messages are hyperlinked. After code generation completes, you can click these hyperlinks to view the files in the MATLAB Editor. The coder compiles the model before generating code. Depending on model display options (such as port data types, etc.), the appearance of the model may change after code generation. A folder icon for the hdlsrc folder is now visible in the Current Folder browser. To view generated code and script files, double-click the hdlsrc folder icon. The files that were generated in the hdlsrc folder are symmetric_fir.vhd: VHDL code. This file contains an entity definition and RTL architecture implementing the symmetric_fir filter. symmetric_fir_compile.do: Mentor Graphics ModelSim compilation script (vcom command) to compile the generated VHDL code. symmetric_fir_synplify.tcl: Synplify synthesis script. symmetric_fir_map.txt: Mapping file. This report file maps generated entities (or modules) to the subsystems that generated them (see Code Tracing Using the Mapping File). To view the generated VHDL code in the MATLAB Editor, double-click the symmetric_fir.vhd file icon in the Current Folder browser. At this point it is suggested that you study the ENTITY and ARCHITECTURE definitions while referring to HDL Code Generation Defaults in the makehdl reference documentation. The reference documentation describes the default naming conventions and correspondences between the elements of a model (subsystems, ports, signals, etc.) and elements of generated HDL code. Before proceeding to the next section, close any files you have opened in the editor. Then, click the Go Up One Level button in the Current Folder browser, to set the current folder back to your sl_hdlcoder_work folder.
3. 4.
5.
6.
Back to Top
2. Select the HDL test bench option. 3. Click the Generate Test bench button. 4. As test bench generation proceeds, the coder displays progress messages. The process should complete successfully with the message
8 of 9
30/10/2010 18:13
Generating HDL Code Using the GUI :: Introduction to HDL Code Gene...
jar:file:///C:/Program%20Files/MATLAB/R2009b/help/toolbox/slhdlcod...
### HDL TestBench Generation Complete. 5. The files that were generated in the hdlsrc folder are symmetric_fir_tb.vhd: VHDL test bench code and generated test and output data. symmetric_fir_tb_compile.do: Mentor Graphics ModelSim compilation script (vcom commands). This script compiles and loads both the entity to be tested (symmetric_fir.vhd) and the test bench code (symmetric_fir_tb.vhd). symmetric_fir_tb_sim.do: Mentor Graphics ModelSim script to initialize the simulator, set up wave window signal displays, and run a simulation. Back to Top
Back to Top
Provide feedback about this page
9 of 9
30/10/2010 18:13