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.
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.
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.
Some blocks in the model already have specified fixed-point data types.
|Block||Data Type Specified on Block|
Use the iterative fixed-point conversion workflow in the Fixed-Point Tool to see how the target hardware affects word length proposals.
In the model, in the Apps gallery, select Fixed-Point Tool.
In the Fixed-Point Tool, click New, and select
Iterative Fixed-Point Conversion.
In the Fixed-Point Tool, under System Under Design (SUD),
ex_moving_average as the system to convert.
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.
In the toolstrip, click Prepare to prepare the system for conversion.
Click the Collect Ranges button 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.
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
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: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
To see how the target hardware affects the word length proposal, change the target hardware to FPGA/ASIC.
In the Configuration Parameters dialog box, on the Hardware
Implementation pane, set Device vendor to
Click Apply and close the Configuration Parameters dialog box.
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