## 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 Case | Block Name | Block Path | Parameter Settings | Supported Trigonometric Functions | Features | Limitations |
---|---|---|---|---|---|---|

Precision | Trigonometric Function | Simulink/Math Operations/ Trigonometric Function | Set For more
information about | `sin` , `cos` ,
`cos+jsin` , `sincos` ,
`atan2` | This block uses the | 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. |

Speed | n-D Lookup Table | HDL Coder/Lookup tables/n-D lookup Table | Set | `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 size | Sine 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 size | NCO | DSP HDL Toolbox/Signal Operations/NCO | Set | `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 Name | Block Path | Parameter Settings | Number of Break Points | Number of Data Points | Maximum Frequency (in MHz) | Path Delay (in ns) | FPGA Resource Usage | |||
---|---|---|---|---|---|---|---|---|---|---|

LUTs | Registers | Block RAMs | DSPs | |||||||

Trigonometric Function block | Simulink/Math Operations/ Trigonometric Function | Set | N/A | N/A | 313 | 3.19 | 656 | 506 | 0 | N/A |

Set | N/A | N/A | 265 | 3.766 | 719 | 247 | 0 | N/A | ||

Set | N/A | N/A | 50 | 20.015 | 686 | 59 | 0 | N/A | ||

n-D Lookup Table block | HDL Coder/Lookup tables/n-D lookup Table | Set | 1024 | N/A | 619 | 1.1614 | 21 | 12 | 0.5 | N/A |

Set | 128 | N/A | 109 | 9.158 | 89 | 26 | 0 | 2 | ||

Sine HDL Optimized and Cosine HDL Optimized blocks | HDL Coder/Lookup tables/Sine HDL Optimized and Cosine HDL Optimized | Default block settings. | N/A | 1024 | 374 | 2.672 | 52 | 13 | 0.5 | N/A |

NCO block | DSPHDL Toolbox/Signal Operations/NCO | Default block settings. | N/A | N/A | 356 | 2.809 | 48 | 113 | 0.5 | N/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 Case | Block Name | Block Path | Supported Data Types | Parameter Settings | Supported Trigonometric Function |
---|---|---|---|---|---|

Precision | Trigonometric Function | Simulink/Math Operations/ Trigonometric Function | Single | Set 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 Table | HDL Coder/Lookup Tables/n-D Lookup Table | Single, Double, Half | Set For LatencyStrategy settings, see n-D Lookup Table. |
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 Name | Block Path | Parameter Settings | Number of Break Points | Max Frequency (in MHz) | Path Delay (in ns) | FPGA Resource Usage | |||
---|---|---|---|---|---|---|---|---|---|

LUTs | Registers | Block RAMs | DSPs | ||||||

Trigonometric Function | Simulink/Math Operations/ Trigonometric Function | Set | N/A | 254 | 3.942 | 3749 | 2543 | 0 | 7 |

Set | N/A | 23 | 43.6 | 3434 | 0 | 0 | 7 | ||

n-D Lookup Table | HDL Coder/Lookup Tables/n-D Lookup Table | Set | 64 | 108 | 9.177 | 6202 | 88 | 1 | 1 |

Set | 64 | 103 | 9.708 | 6456 | 4593 | 1 | 1 | ||

Set | 1024 | 82 | 12.108 | 33240 | 490 | 1 | 1 |