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.
openExample('visionhdl/VisionHDLMATLABTutorialExample')
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.
Generate HDL Code
Click Workflow Advisor to open the advisor.
Set Fixed-point conversion to
Keep original types
.Click HDL Code Generation to view the HDL code generation options.
On the Target tab, set Language to
Verilog
orVHDL
.Also on the Target tab, select Generate HDL.
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.
Click Run to generate the HDL design with reports.
Under HDL Verification, open Verify with HDL Test Bench and select Generate HDL Test Bench.
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.