Main Content

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

Guideline ID

2.10.1

Severity

Mandatory

Description

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).

Specify Data Type of Gain Blocks

Guideline ID

2.10.2

Severity

Recommended

Description

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.

Enumerated Data Type Restrictions

Guideline ID

2.10.3

Severity

Mandatory

Description

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 cannot perform arithmetic operations such as *, /, -, and + with enumeration values.

Choose Optimal Simulink Block to Compute Sine and Cosine Functions with Fixed-Point Data Types

Guideline ID

2.10.4

Severity

Recommended

Description

You can compute Sine and Cosine functions with fixed-point data types by using the Trigonometric Function block, n-D Lookup Table block, Sine HDL Optimized block, Cosine HDL Optimized block, and NCO (DSP HDL Toolbox) block. Each of these blocks adds different latencies and offer varying performance in speed and area. Choose the appropriate block based on your specific use case.

Follow these guidelines to determine the optimal block:

  • Use the Trigonometric Function block for better precision in fixed-point applications. It provides the highest accuracy because it allows increased iterations of the CORDIC approximation.

  • Use the n-D Lookup Table block for better speed. Because it has quick computation capabilities, it generates the outputs in one cycle. In comparison, the CORDIC approximation method of the Trigonometric Function block takes several cycles.

  • Use the Sine HDL Optimized and Cosine HDL Optimized blocks to minimize circuit area size. They consumes only 1/4 of the memory compared to the n-D Lookup Table block.

Additionally, consider these limitations:

  • When the required precision results in a lookup table (LUT) size that exceeds the available block RAM capacity, use the Trigonometric Function block with the Approximate method parameter set to CORDIC method.

  • For the fixed-point Trigonometric Function block, the operating speed depends on the latency settings.

Guidelines for Block RAM Allocation:

  • Allocate the n-D Lookup Table block, Sine HDL Optimized block, Cosine HDL Optimized block and NCO block to block RAM as required.

  • To allocate the n-D Lookup Table block to block RAM, set the MAPToRAM parameter in the HDL Block Properties window or insert a Delay block after the n-D Lookup Table block.

  • To allocate a Sine HDL Optimized block and Cosine HDL Optimized block to block RAM, do not place a Delay block immediately after it. This configuration prevents the assignment of table data to slice LUTs.

This table compares the Simulink blocks you can use to calculate sine and cosine functions with fixed-point data types:

Use CaseBlock NameBlock PathParameter SettingsSupported Trigonometric FunctionsFeaturesLimitations
PrecisionTrigonometric FunctionSimulink/Math Operations/ Trigonometric Function

Set Approximation method to CORDIC.

For more information about LatencyStrategy. See LatencyStrategy.

sin, cos, cos+jsin, sincos, atan2

This block uses the CORDIC approximate algorithm for calculations, which does not use memory but introduces delay due to pipelining. As the bit width increases, accuracy improves, and the circuit size remains smaller compared to other methods. For more information, see Trigonometric Function.

The number of iterations specified in the block parameters must be a natural number that is less than or equal to the word length of the fixed-point data.

Speedn-D Lookup TableHDL Coder/Lookup tables/n-D lookup Table

Set Interpolation method to Flat or Linear point-slope.

sin, cos, exp(j)

This block is inefficient in terms of circuit area size because it occupies memory for entire period.

See Extended Capabilities section of n-D Lookup Table.

Circuit area sizeSine HDL Optimized and Cosine HDL Optimized HDL Coder/Lookup tables/Sine HDL Optimized an Cosine HDL Optimized

Default block settings

sin, cos, exp(j), sincos

This block is efficient because it uses table data for 1/4 period or less.

To map to Block RAM, avoid placing a Delay block immediately after the Lookup Table block.

Speed and Circuit area sizeNCODSP HDL Toolbox/Signal Operations/NCO

Set Phase offset source to Input port and Phase increment to 0.

sin, cos, exp(j), sincos

This block is efficient because it uses table data of ¼ period or less.

This block is designed for signal generation and can be used to calculate sine and cosine functions by configuring the appropriate parameters. See NCO (DSP HDL Toolbox).

The table compares the results from the operation of sin function on a logic synthesis with the single fixed-point data type on a Xilinx® Kintex® 7, XC7K325T FFG900 device.

Block NameBlock PathParameter SettingsNumber of Break PointsNumber of Data PointsMaximum Frequency (in MHz)Path Delay (in ns)FPGA Resource Usage
LUTsRegistersBlock RAMsDSPs
Trigonometric Function blockSimulink/Math Operations/ Trigonometric Function

Set Approximation method to CORDIC, LatencyStrategy to Custom, CustomLatency to 13.

N/AN/A3133.196565060N/A

Set Approximation method to CORDIC, LatencyStrategy to Custom, CustomLatency to 6.

N/AN/A2653.7667192470N/A

Set Approximation method to CORDIC, LatencyStrategy to Custom, CustomLatency to 0.

N/AN/A5020.015686590N/A
n-D Lookup Table blockHDL Coder/Lookup tables/n-D lookup Table

Set Interpolation method to Flat.

1024N/A6191.161421120.5N/A

Set Interpolation method to Linear point-slope.

128N/A1099.158892602
Sine HDL Optimized and Cosine HDL Optimized blocksHDL Coder/Lookup tables/Sine HDL Optimized and Cosine HDL Optimized

Default block settings.

N/A10243742.67252130.5N/A
NCO blockDSPHDL Toolbox/Signal Operations/NCO

Default block settings.

N/AN/A3562.809481130.5N/A

Choose Optimal Simulink Block to Compute Sine and Cosine Functions with Floating-Point Data Types

Guideline ID

2.10.5

Severity

Recommended

Description

You can compute Sine and Cosine functions with floating point data types by using the Trigonometric Function block or the n-D Lookup Table block. Each of these blocks adds different latencies and offer varying performance in speed and area. Choose the appropriate block based on your specific use case.

Follow these guidelines to determine the optimal block:

  • Use Trigonometric Function block for superior accuracy, speed, and a smaller circuit area size than the n-D Lookup Table block.

  • Use the n-D Lookup Table block in block RAM. The Trigonometric Function block is not suitable for RAM storage.

Additionally, consider these limitations:

  • The LatencyStrategy: ZERO, MIN, MAX alter the clock frequency.

  • The Trigonometric Function block supports a wide dynamic range with its floating-point logic circuit calculations, but, this may lead to an increase in circuit area size due to its complexity.

Guidelines for Block RAM Allocation

To allocate the n-D Lookup Table block to block RAM, set the MAPToRAM parameter in the HDL Block Properties window or insert a Delay block after the n-D Lookup Table block.

This table compares the Simulink blocks you can use to calculate sine and cosine functions with floating-point data types:

Use CaseBlock NameBlock PathSupported Data TypesParameter SettingsSupported Trigonometric Function
PrecisionTrigonometric FunctionSimulink/Math Operations/ Trigonometric FunctionSingle

Set Approximation method to None.

For LatencyStrategy settings, see Latency Values of Floating-Point Operators.

sin, cos, cos+jsin, sincos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh.
Speed (Implement to Block RAM)n-D Lookup TableHDL Coder/Lookup Tables/n-D Lookup TableSingle, Double, Half

Set Interpolation method to Linear point-slope or Flat .

For LatencyStrategy settings, see n-D Lookup Table.

sin, cos, cos+jsin, sincos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh.

The available functions depend on the table data settings.

This table compares the results from the sin function operation on a logic synthesis with the single floating-point on a Xilinx Kintex 7 XC7K325T FFG900 device.

Block NameBlock PathParameter SettingsNumber of Break PointsMax Frequency (in MHz)Path Delay (in ns)FPGA Resource Usage
LUTs RegistersBlock RAMs DSPs
Trigonometric Function Simulink/Math Operations/ Trigonometric Function

Set Approximation method to None, LatencyStrategy to MAX.

N/A2543.9423749254307

Set Approximation method to None, LatencyStrategy to ZERO.

N/A2343.63434007
n-D Lookup TableHDL Coder/Lookup Tables/n-D Lookup Table

Set Interpolation method to Linear point-slope and LatencyStrategy to ZERO. Numeric error 1e-3 order.

641089.17762028811

Set Interpolation method to Linear point-slope and LatencyStrategy to MAX. Numeric error 1e-3 order.

641039.7086456459311

Set Interpolation method to Flat and LatencyStrategy to MAX. Numeric error 1e-7 order.

10248212.1083324049011

See Also

Functions

Related Topics