How Hardware Implementation Settings Affect Data Type Proposals

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.

Propose Word Lengths Based on Simulation Data

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.

  1. Open the ex_moving_average model. At the MATLAB® command line, enter:

    addpath(fullfile(docroot,'toolbox','fixpoint','examples'))
    ex_moving_average

    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)

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

  3. In the model menu, select Analysis > Data Type Design > Fixed-Point Tool.

  4. In the Prepare System section of the toolstrip, under System under design, select ex_moving_average as the system to convert.

  5. In the Collect Ranges section of the toolstrip, select Simulation Ranges as the method of range collection. This button configures the model to collect ranges using idealized floating-point data types.

  6. Click the Collect Ranges button to start the simulation.

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

  7. In the Convert Data Types section of the toolstrip you can configure the data type proposal settings for the blocks. Click the Settings button arrow.

  8. In the Settings dialog, next to Propose, select Word Length.

  9. 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 the Simulation min/max option.

      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.

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

  11. 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 Examples

More About