Hardware Modeling with MATLAB Code

MATLAB® design and test bench guidelines for HDL code generation

System Objects

hdl.RAM Single, simple dual, or dual-port RAM for memory read/write access
hdl.BlackBox Black box for including custom HDL code

Examples and How To

Model a Counter for HDL Code Generation

This design pattern shows a MATLAB example of a counter, which is suitable for HDL code generation.

Model a State Machine for HDL Code Generation

The following design pattern shows MATLAB examples of Mealy and Moore state machines which are suitable for HDL code generation.

Generate Hardware Instances For Local Functions

The following example shows how to use local functions in MATLAB, so that each execution of a local function corresponds to a separate hardware module in the generated HDL code.

Implement RAM Using MATLAB Code

You can write MATLAB code that maps to RAM during HDL code generation by using:

For-Loop Best Practices for HDL Code Generation

Some best practices for using loops in MATLAB code for HDL code generation are:

Model State with Persistent Variables and System Objects

This example shows how to use persistent variables and System objects to model state and delays in a MATLAB® design for HDL code generation.

Map Matrices to ROM

To map a matrix constant to ROM:If your MATLAB code meets these requirements, HDL Coder™ inserts a no-reset register at the output of the matrix in the generated code.

Bit Shifting and Bit Rotation

HDL Coder supports shift and rotate functions that mimic HDL-specific operators without saturation and rounding logic.

Bit Slicing and Bit Concatenation

This section describes how to use the functions bitsliceget and bitconcat to access and manipulate bit slices (fields) in a fixed-point or integer word.

Concepts

Guidelines for Efficient HDL Code

Best practices for writing MATLAB code for HDL code generation

MATLAB Design Requirements for HDL Code Generation

MATLAB design requirements and language support for HDL code generation

What Is a MATLAB Test Bench?

MATLAB test bench definition

MATLAB Test Bench Requirements and Best Practices

MATLAB test bench requirements and best practices for HDL code generation

Was this topic helpful?