You should consider using MATLAB Copilot to translate your MATLAB to follow Synthesis friendly rules.
Here is some guidance to get you started.
How to Use MATLAB Copilot for HDL Conversion and Compatibility
To successfully convert MATLAB code to VHDL and ensure compatibility with HDL Coder, follow these steps:
1. Prepare Your MATLAB Code for HDL Coder
HDL Coder supports only a subset of MATLAB language features. To make your code compatible:
- Avoid unsupported constructs such as: Dynamic array resizing, Cell arrays and structures, Variable-size signals
- Ensure loops have bounded iteration counts (no while loops with unknown limits).
- Avoid functions that are not synthesizable (e.g., plotting, file I/O).
- Use fixed-point data types where possible for hardware efficiency or use Automated Float to Fixed Workflow.
2. Use MATLAB Copilot to Refactor Code
- Open MATLAB Copilot and provide your existing MATLAB code.
- Ask Copilot to:
- Analyze compatibility with HDL Coder.
- Suggest refactoring steps to replace unsupported features.
- Convert algorithmic parts into HDL-compatible constructs (e.g., replace dynamic arrays with preallocated arrays).
------------------------------------------------------------------
Example prompt for Copilot:
Make this MATLAB function compatible with HDL Coder by removing unsupported features and using fixed-point arithmetic. Break the design into synthesizable dut.m and a testbench.m calling the dut function. Use HDL Coder supported subset of MATLAB in the dut.m file.
------------------------------------------------------------------
Once your MATLAB Code is ready follow these steps to generate VHDL.
- Open HDL Workflow Advisor in MATLAB.
- Select Convert MATLAB Function to HDL.
- Configure:
- Target Language: VHDL
- Synthesis Tool: Choose your FPGA vendor tool (e.g., Xilinx Vivado, Intel Quartus)
- Run the workflow to generate VHDL code.
- Use HDL Coder reports to check for: Resource utilization, Timing estimates
- Apply optimizations like pipelining and resource sharing for better performance.
------------------------------------------------------------------
HDL Code Generation from MATLAB
Generate HDL Code from MATLAB® algorithms
Implement your MATLAB algorithm in hardware by generating HDL code and deploying that code on an Application-Specific Integrated Circuit (ASIC) or Field Programmable Gate Array (FPGA). Write the MATLAB algorithm with syntax and functions that are compatible with HDL code generation. If the algorithm uses floating-point data, HDL Coder™ helps you to convert it to a fixed-point algorithm. After you generate HDL code and verify that it matches your original algorithm, deploy the HDL code on your target hardware.