Simulink Data Type Considerations
You can follow these guidelines to learn the recommended data type settings that you want to use in your Simulink® model for HDL code generation. Each guideline has a severity level that indicates the level of compliance requirements. To learn more, see HDL Modeling Guidelines Severity Levels.
Use Boolean for Logical Data and Ufix1 for Numerical Data
Boolean and the fixed-point type,
1-bit data types in MATLAB® and Simulink. These types are treated differently.
Booleanfor control logic signals such as enable and local reset signals. If you want to calculate a
Booleansignal with a fixed-point data type, use a Data Type Conversion to convert the signal to a
To perform numeric calculations, use
fixdt (0,1,0). Sometimes, the output bit width can become larger than the bitwidth. To perform such operations, use the
Inherit: Inherit via internal rulesetting, because of the
Specify Data Type of Gain Blocks
Gain blocks have a Gain parameter and an Output data type setting. It is recommended that you use fixed-point data types for these settings. In the Block Parameters dialog box of the Gain block:
Simulink.NumericTypeobject, such as
fixdt (1, 16, 8).
Make sure that the Gain parameter of the block does not use a round parameter value. To avoid rounding of the gain value, you can specify a
fiobject, such as
Inherit:Inherit via internal rule. This setting can result in an erroneous data type being assigned to the block, thereby resulting in an HDL code generation error.
Enumerated Data Type Restrictions
Certain optimizations such as pipelining and resource sharing do not work seamlessly in the presence of enumerated data types. It is recommended that you use enumerated types on an as needed basis. HDL code generation has certain restrictions when modeling with enumerated types.
You cannot use an enumerated data type for the input or output port of the top-level DUT.
You must use monotonically increasing enumeration values. For example, see this code:
classdef BasicColors < Simulink.IntEnumType enumeration Red(0) Yellow(1) Blue(2) end methods (Static) function retVal = getDefaultValue() retVal = BasicColors.Blue; end end end
You cannot perform arithmetic operations such as
+with enumeration values.
You cannot perform comparison operations such as
~=with enumeration values. You can perform a
<>operation or a conditional branch such as if or switch.