Main Content

Generate HDL Code From MATLAB

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

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

Create an HDL Coder Project

Copy the relevant files to a temporary folder.

functionName = 'HDLTargetedDesign';
tbName = 'VisionHDLMATLABTutorialExample';
vhtExampleDir = fullfile(matlabroot,'examples','visionhdl');
workDir = [tempdir 'vht_matlabhdl_ex'];

[~, ~, ~] = rmdir(workDir, 's');

copyfile(fullfile(vhtExampleDir, [functionName,'.m*']), workDir)
copyfile(fullfile(vhtExampleDir, [tbName,'.m*']), workDir)

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 logical scalars. The pixel data type is uint8. The pixel input is a scalar.

Generate HDL Code

  1. Click Workflow Advisor to open the advisor.

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

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

  4. Also on the Target tab, select Generate HDL and Generate HDL test bench.

  5. 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.

  6. Click Run to generate the HDL design and the test bench with reports.

Examine the log window and click the links to view the generated code and the reports.

Related Topics