Contents

Propose Word Lengths

How the Fixed-Point Tool Proposes Word Lengths

To use the Fixed-Point Tool to propose word lengths, you must specify the target hardware and the fraction length requirements for data types in the model. Select the fraction lengths based on the precision required for the system that you are modeling. If you do not specify fraction lengths, the Fixed-Point Tool sets the fraction length to zero. The Fixed-Point Tool uses these specified fraction lengths to recommend the minimum word length for fixed-point data types in the selected model or subsystem to avoid overflow for the collected range information.

The proposed word length is based on:

  • Design range information and range information that the Fixed-Point Tool or Fixed-Point Advisor collects. This collected range information can be either simulation or derived range data.

  • The signedness and fraction lengths of data types that you specify for blocks, signal objects.

  • The signedness and fraction lengths of the default data types that you specify in the Fixed-Point Tool or Fixed-Point Advisor.

  • The production hardware implementation settings specified in the Configuration Parameters dialog box.

How the Fixed-Point Tool Uses Range Information

The Fixed-Point Tool determines whether to use different types of range information based on its availability and on the Fixed-Point Tool Derived min/max and Simulation min/max settings.

Design range information always takes precedence over both simulation and derived range data. When there is no design range information, the Fixed-Point Tool uses the union of available simulation and derived range data. If you specify safety margins, the Fixed-Point Tool takes these margins into account.

For example, if a signal has a design range of [-10,10], the Fixed-Point Tool uses this range for the proposal and ignores all simulation and derived range information. If you specify a safety margin of 10% for design range, the Fixed-Point Tool uses a range of [-11,11] for the proposal.

If the signal has no specified design information, but does have a simulation range of [-8,8] and a derived range of [-2,2], the proposal uses the union of the ranges, [-8,8]. If you specify a safety margin of 50%, the proposal uses a range of [-12, 12].

How the Fixed-Point Tool Uses Target Hardware Information

The Fixed-Point Tool calculates the ideal word length and then checks this length against the production hardware implementation settings for the target hardware. The tool uses the following rules.

Target HardwareIdeal Word LengthProposed Word LengthRestrictions
FPGA/ASICIdeal word length=<128Ideal word lengthNone
Ideal word length>128128Maximum word length is 128
Embedded ProcessorIdeal word length=< character bit length for the embedded processor (char)charRounds up word length
char <Ideal word length=< short bit length for the embedded processor (short)shortRounds up word length
short<Ideal word length=< integer bit length for the embedded processor (int)intRounds up word length
int<Ideal word length=<long bit length for the embedded processor (long)longRounds up word length
Ideal word length>long bit length for the embedded processorlongMaximum word length is the target hardware long

Propose Word Lengths

  1. Specify the target hardware.

    1. In the model, select Simulation > Model Configuration Parameters.

    2. In the Configuration Parameters dialog box, select Hardware Implementation.

    3. On the Hardware Implementation pane, specify the Device vendor and Device type, and then click Apply.

  2. On the Fixed-Point Tool Automatic data typing for selected system pane, select Propose word lengths for specified fraction lengths. If you cannot see this option, click Configure to display more options.

  3. On the same pane:

    • For simulation min/max information only, clear Derived min/max.

    • For derived min/max information only, clear Simulation min/max.

  4. If you have safety margins to apply, set Safety margin for design and derived min/max (%) and Safety margin for design and derived min/max (%), as applicable.

  5. Click the Propose word lengths button, .

      Note:   When the Fixed-Point Tool proposes data types, it does not alter your model.

    If there are conflicts in your model, the Fixed-Point Tool opens the Result Details dialog box.

    If you do not see this warning, there are no conflicts in your model. Review the proposed word lengths,

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.

    1. In the model, select Simulation > Model Configuration Parameters.

    2. In the Configuration Parameters dialog box, select Hardware Implementation.

      On the Hardware Implementation pane, the Device vendor is Generic and the Device type is 16–bit embedded processor.

    3. Close the Configuration Parameters dialog box.

  3. From the model Analysis menu, select Fixed-Point Tool.

  4. On the Shortcuts to set up runs pane, click the Model-wide double override and full instrumentation button to set:

    • Data type override to Double

    • Data type override applies to to All numeric types

    • Fixed-point instrumentation mode to Minimums, maximums and overflows

    • The run name (in the Data collection pane Store results in run field) to DoubleOverride

    Using these settings, the Fixed-Point Tool performs a global override of the fixed-point data types with double-precision data types, avoiding quantization effects. During simulation, the tool logs minimum value, maximum value, and overflow data for all blocks in the current system or subsystem in the run DoubleOverride.

  5. Click the Fixed-Point Tool Simulate button to run the simulation.

    The Fixed-Point Tool simulates the model and displays the results on the Contents pane in the run named DoubleOverride.

  6. On the Automatic data typing for selected system pane:

    1. Click Configure to display more options.

    2. Select Propose word lengths for specified fraction lengths, then click Apply.

  7. Click the Propose word lengths button.

    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 Safety margin for design and derived min/max (%) parameter specifies a range that differs from that defined by the design range. In this example, no safety margins are set.

    • 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, no safety margins are set.

    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 not selected.

    • Output data type parameter specifies a generalized fixed-point number.

    • Data types are not inherited types.

    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.

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

    1. In the model, select Simulation > Model Configuration Parameters.

    2. In the Configuration Parameters dialog box, select Hardware Implementation.

    3. On the Hardware Implementation pane, set Device vendor to ASIC/FPGA. Simulink® automatically sets the Device type to ASIC/FPGA.

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

  9. On the Fixed-Point Tool Automatic data typing for selected system pane, click the Propose word lengths button.

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

Was this topic helpful?