Generate HDL Code from Simulink Model Using Configuration Parameters - MATLAB & Simulink (original) (raw)

Main Content

You can view and edit options and parameters that affect HDL code generation in the Configuration Parameters dialog box, or in the Model Explorer. This example illustrates how you can use the Configuration Parameters dialog box to generate HDL code for the Symmetric FIR filter model.

FIR Filter Model

Before you generate HDL code, the model must be compatible for HDL code generation. To check and update your model for HDL compatibility, see Check HDL Compatibility of Simulink Model Using HDL Code Advisor.

This example uses the Symmetric FIR filter model that is compatible for HDL code generation. To open this model at the command line, enter:

Fixed-point Symmetric FIR model

The model uses a division of labor that is suitable for HDL design.

The top-level model generates 16-bit fixed-point input signals for the symmetric_fir subsystem. The Signal From Workspace block generates a test input (stimulus) signal for the filter. The fourConstant blocks provide filter coefficients. TheScope blocks are used for simulation and are not used for HDL code generation.

To navigate to the symmetric_fir subsystem, enter:

open_system('sfir_fixed/symmetric_fir')

Symmetric FIR filter algorithm.

Create a Folder and Copy Relevant Files

In MATLAB®:

  1. Create a folder named sl_hdlcoder_work, for example:
    mkdir C:\work\sl_hdlcoder_work
    sl_hdlcoder_work stores a local copy of the example model and folders and generated HDL code. Use a folder location that is not within the MATLAB folder tree.
  2. Make the sl_hdlcoder_work folder your working folder, for example:
    cd C:\work\sl_hdlcoder_work
  3. Save a local copy of the sfir_fixed model to your current working folder. Leave the model open.

Open HDL Code Generation Pane of Configuration Parameters Dialog Box

To open the pane of the Configuration Parameters dialog box, in the Apps gallery, click HDL Coder. The HDL Code tab appears. In thePrepare section, clickSettings.

The pane consists of basic options that specify the DUT that you want to generate code for, target language, and folder settings. The Generate HDL for setting is synchronized with the menu in the HDL Code tab. You can also use the buttons in this pane to initiate code generation and perform compatibility checking. The pane consists of various subpanes that you can use to specify various settings related to clock and reset signals to reporting and optimization settings.

In the pane

Generate HDL Code

To generate code, click the Generate button. By default, HDL Coder™ generates VHDL code in the target hdlsrc folder.

To generate Verilog code for the model:

  1. In the HDL Code tab, clickSettings.
  2. In the HDL Code Generation pane, forLanguage, select Verilog. Leave other settings to the default. Click Apply and then click Generate.

HDL Coder compiles the model before generating code. Depending on model display options such as port data types, the model can change in appearance after code generation. As code generation proceeds, HDL Coder displays progress messages in the MATLAB command line with:

The process completes with the message:

HDL Code Generation Complete.

See Also

makehdl | makehdltb

Topics