| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink HDL Coder |
| Contents | Index |
| On this page… |
|---|
Use Compiled External M-Functions on the Embedded MATLAB Path Build the Embedded MATLAB Code First |
This section describes recommended practices when using the Embedded MATLAB Function block for HDL code generation.
By setting Embedded MATLAB Function block options as described in this section, you can significantly increase the efficiency of generated HDL code. See Setting Optimal Fixed-Point Options for the Embedded MATLAB Function Block for an example.
The coder supports HDL code generation from Embedded MATLAB Function blocks that include compiled external M-functions. This feature lets you write reusable M-code and call it from multiple Embedded MATLAB Function blocks.
Such functions must be defined in M-files that are on the Embedded MATLAB path, and must include the %#eml compilation directive. See Adding the Compilation Directive %#eml in the Embedded MATLAB documentation for information on how to create, compile, and invoke external M-functions.
Before generating HDL code for a subsystem containing an Embedded MATLAB Function block, it is strongly recommended that you build the Embedded MATLAB code to check for errors. To build the code, select Build from the Tools menu in the Embedded MATLAB Function block editor (or press CTRL+B).
The M-function hdlfimath.m is a utility that defines a FIMATH specification that is optimized for HDL code generation. It is strongly recommended that you replace the default FIMATH for fixed-point signals specification with a call to the hdlfimath function, as shown in the following figure.

The following listing shows the FIMATH setting defined by hdlfimath.
hdlfm = fimath(...
'RoundMode', 'floor',...
'OverflowMode', 'wrap',...
'ProductMode', 'FullPrecision', 'ProductWordLength', 32,...
'SumMode', 'FullPrecision', 'SumWordLength', 32,...
'CastBeforeSum', true);Note When the FIMATH OverflowMode property of the FIMATH specification is set to 'Saturate', HDL code generation is disallowed for the following cases:
|
Use the default (Fixed-point) setting for the Treat these inherited signal types as fi objects option , as shown in the following figure.

![]() | Distributed Pipeline Insertion | Language Support | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |