Main Content

How Hardware Implementation Settings Affect Data Type Proposals

This example shows how to use the Fixed-Point Tool to propose word lengths for a model that implements a simple moving average algorithm. The model already uses fixed-point data types, but they are not optimal. Simulate the model and propose data types based on simulation data. To see how the target hardware affects the word length proposals, first set the target hardware to an embedded processor and propose word lengths. Then, set the target hardware to an FPGA and propose word lengths.

Open the Model and Specify Hardware Implementation Settings

In the Configuration Parameters dialog box, on the Hardware Implementation pane, you can specify the Device vendor and Device type of your target hardware. The Fixed-Point Tool uses this information when it proposes fixed-point data types for objects in your model. For example, if you specify the target hardware to be an embedded processor, the tool will propose standard word lengths appropriate for the target.

Open the ex_moving_average example.

open_system('ex_moving_average')

Verify that the target hardware is an embedded processor. In the Configuration Parameters dialog box, on the Hardware Implementation pane, set the Device vendor to Custom Processor. Close the Configuration Parameters dialog box.

Propose Word Lengths Based on Simulation Data

Some blocks in the model already have specified fixed-point data types.

BlockData Type Specified on Block
Dbl2Fixptfixdt(1,16,10)
Gain1fixdt(1,32,17)
Gain2fixdt(1,32,17)
Gain3fixdt(1,32,17)
Gain4fixdt(1,16,1)
Add1fixdt(1,32,17)
Add2fixdt(1,32,17)
Add3fixdt(1,32,17)

Use the iterative fixed-point conversion workflow in the Fixed-Point Tool to see how the target hardware affects word length proposals.

  1. In the model, in the Apps gallery, select Fixed-Point Tool.

  2. In the Fixed-Point Tool, click New, and select Iterative Fixed-Point Conversion.

  3. In the Fixed-Point Tool, under System Under Design (SUD), select ex_moving_average as the system to convert.

  4. Under Range Collection Mode, select Simulation ranges as the method of range collection. This configures the model to collect ranges using idealized floating-point data types.

  5. In the toolstrip, click Prepare to prepare the system for conversion.

  6. Expand the Collect Ranges button arrow and select Double precision. Click Collect Ranges to start the simulation.

    The Fixed-Point Tool stores the simulation data in a run titled BaselineRun. You can examine the range information of the blocks in the model in the spreadsheet.

  7. In the Convert section of the toolstrip you can configure the data type proposal settings for the blocks. Click the Settings button arrow. In the Settings dialog, next to Propose, select Word Length.

  8. Click Propose Data Types.

    The Fixed-Point Tool uses available range data to calculate data type proposals according to the following rules:

    • Design minimum and maximum values take precedence over the simulation range.

    • The tool observes the simulation range because you selected Simulation ranges as the range collection method.

      The Safety margin for simulation min/max (%) parameter specifies a range that differs from that defined by the simulation range. In this example, the default safety margin is used.

    The Fixed-Point Tool analyzes the data types of all fixed-point blocks whose Lock output data type setting against changes by the fixed-point tools parameter is cleared.

    For each object in the model, the Fixed-Point Tool proposes the minimum word length that avoids overflow for the collected range information. Because the target hardware is a 16-bit embedded processor, the Fixed-Point tool proposes word lengths based on the number of bits used by the processor for each data type. For more information, see How the Fixed-Point Tool Uses Target Hardware Information.

    The tool proposes smaller word lengths for Gain4 and Gain4:Gain. The tool calculated that their ideal word length is less than or equal to the character bit length for the embedded processor (8), so the tool rounds up the word length to 8.

  9. To see how the target hardware affects the word length proposal, change the target hardware to FPGA/ASIC.

    1. In the Configuration Parameters dialog box, on the Hardware Implementation pane, set Device vendor to ASIC/FPGA.

    2. Click Apply and close the Configuration Parameters dialog box.

  10. In the Fixed-Point Tool, click Propose data types again.

    Because the target hardware is an FPGA, there are no constraints on the word lengths that the Fixed-Point Tool proposes. The word length for Gain4:Gain is now 2.

Related Topics