Main Content

Generate HDL Code from MATLAB

This page shows you how to generate HDL code from the design in the Design Hardware-Targeted Image Filters in MATLAB example.

To generate HDL code, you must have an HDL Coder™ license.

Create an HDL Coder Project

Start from a working folder that contains a function and a test bench MATLAB script file. You can use this openExample command to get a working folder with the files from the Design Hardware-Targeted Image Filters in MATLAB example.


Open the HDL Coder app and create a new project.

coder -hdlcoder -new vht_matlabhdl_ex

In the HDL Code Generation pane, add the function file HDLTargetedDesign.m and the test bench file VisionHDLMATLABTutorialExample.m to the project.

Click next to the signal names under MATLAB Function to define the data types for the input and output signals of the function. The control signals are a struct of five logical scalars, enter their names as shown in the figure. The pixel data type is uint8. The pixel input is a scalar.

HDL Code Generation pane with input data types defined for the HDL-targeted function.

Generate HDL Code

  1. Click Workflow Advisor to open the advisor.

  2. Set Fixed-point conversion to Keep original types.

  3. Click HDL Code Generation to view the HDL code generation options.

  4. On the Target tab, set Language to Verilog or VHDL.

  5. Also on the Target tab, select Generate HDL.

  6. On the Coding Style tab, select Include MATLAB source code as comments and Generate report to generate a code generation report with comments and traceability links.

  7. Click Run to generate the HDL design with reports.

  8. Under HDL Verification, open Verify with HDL Test Bench and select Generate HDL Test Bench.

  9. Click Run to generate the HDL test bench.

Examine the log window and click the links to view the generated code and the reports. You can run the generated test bench in your HDL simulator, or integrate the generated HDL code into a larger design you already have.

Related Topics