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.
2.10.1
Mandatory
Boolean
and the fixed-point type, ufix1
,
are both 1-bit
data types in MATLAB® and Simulink. These types are treated differently.
Use Boolean
for control logic signals such as
enable and local reset signals. If you want to calculate a
Boolean
signal with a fixed-point data type, use
a Data Type Conversion to
convert the signal to a fixdt (0,1,0)
type.
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
rule
setting, because of the
numerictype
property of fixdt
(0,1,0)
.
2.10.2
Recommended
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:
Specify a Simulink.NumericType
object, 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 fi
object, such as
fi(3.44,0,8,4)
.
Avoid using 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.
2.10.3
Mandatory
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
*
, /
,
-
, and +
with enumeration
values.
You cannot perform comparison operations such as
>
, <
,
>=
, <=
,
==
, and ~=
with
enumeration values. You can perform a <>
operation or a conditional branch such as if or switch.