Main Content

Fixed-Point Tool

This example uses the fxpdemo_feedback model to demonstrate how to use the Iterative Fixed-Point Conversion workflow in the Fixed-Point Tool. The iterative workflow in the tool automates common tasks of collecting min-max range data during simulations for use in automatically selecting fixed-point data types for blocks. You can configure any fixed-point capable block in Simulink® to accept the fixed-point data types proposed by the tool. You can manually specify data types for key blocks such as input ports and selectively disable automated scaling in a model on a block-by-block basis. This gives the Fixed-Point Tool more information to work with and results in automatically selected fixed-point scalings that are compatible with the key manually selected scalings.

Open the fxpdemo_feedback Model

The fxpdemo_feedback model contains a digital controller with initial guesses for fixed-point data types already specified in the Controller subsystem. In this example, you specify a known tolerance for the plant output, propose new fixed-point data types for the Controller subsystem, then apply the proposed data types to the model.

Open the Fixed-Point Tool

On the Simulink® Apps tab, under Code Generation, click the app icon.

Start the iterative Fixed-Point Conversion workflow. In the Fixed-Point Tool, click New > Iterative Fixed-Point Conversion.

Set Up the Model for Conversion to Fixed-Point

  1. Select the subsystem that you want to convert. Under System Under Design (SUD), select the Controller subsystem.

  2. Choose the range collection method to use. Under Range Collection Mode, select Simulation ranges.

  3. Specify Simulation Inputs. For this example, use the default model inputs for simulation.

  4. Specify signal tolerances for logged signals. Set the Absolute Tolerance of the Plant Output signal to 0.1.

Prepare for Conversion to Fixed-Point

To prepare the model for fixed-point conversion, click Prepare. The Fixed-Point Tool creates a backup version of the model and checks the model for compatibility with the conversion process. For more information about preparation checks, see Use the Fixed-Point Tool to Prepare a System for Conversion.

Collect Ranges

To collect ranges, click the Collect Ranges button arrow and select Double precision. Click Collect Ranges to start the range collection simulation.

When you select Double precision as the range collection mode, the tool simulates the fxpdemo_feedback model with data type override enabled. Data type override performs a global override of the fixed-point data types in the model, thereby avoiding quantization effects. This enables you to establish an ideal floating-point baseline for the behavior of your model.

The results of range collection are stored in BaselineRun. The Results spreadsheet displays a summary of the statistics collected during the range collection simulation, including the currently specified data types on the model (SpecifiedDT), simulation minimum, and simulation maximum values. The compiled data type (CompiledDT) column displays double for all objects in the Controller subsystem, indicating that data type override was applied during the range collection simulation.

You can click on any result to view additional details in the Results Details pane. The Visualization of Simulation Data pane displays a summary of histograms of the bits used by each object in your model. You can customize the information displayed in the Results spreadsheet, or use the Explore tab to sort and filter these results based on additional criteria. For more information, see Control Views in the Fixed-Point Tool.

Propose Fixed-Point Data Types

To configure the settings to use for data type proposals, expand the Settings button arrow. For this example, use the default settings.

To propose data types based on the ranges collected and the data type proposal settings specified, click Propose Data Types. The tool uses all available range data to calculate data type proposals which can include design minimum or maximum values, simulation minimum or maximum values, and derived minimum or maximum values. Data types are proposed for all objects in the system under design whose Lock output data type setting against changes by the fixed-point tools parameter is cleared.

The Results spreadsheet updates to show the proposed data types in the ProposedDT column. The Fixed-Point Tool allows you to selectively apply data type proposals to objects in your model. In the spreadsheet, use the Accept check boxes to specify the proposed data types that you want to apply to your model. By default, the app accepts all data type proposals which differ from the currently specified data types. For this example, use the default.

Apply Fixed-Point Data Types to the Model and Verify New Settings

To write the proposed data types to the model, click Apply Data Types. The tool updates the SpecifiedDT column to show that the data types have been applied to the model.

Simulate the model using the applied fixed-point data types. Expand the Simulate with Embedded Types button arrrow and select Specified data types. Then click Simulate with Embedded Types.

Next, simulate the model using the fixed-point data types currently specified on the model. Expand the Simulate with Embedded Types button arrow and select Specified data types, then click *Simulate with Embedded Types.

The Fixed-Point Tool simulates the model using the new fixed-point data types and logs minimum and maximum values and overflow data for all objects in the system under design. This information is stored in a new run named EmbeddedRun. The icon next to EmbeddedRun displays a pass status, indicating that all signals in the system under design meet the specified tolerances. The Visualization of Simulation Data pane updates to display the new EmbeddedRun data.

To compare the ideal results stored in BaselineRun with the newly applied fixed-point data types, select EmbeddedRun from the Run to compare in SDI drop down menu. Then click Compare Results to open the Simulation Data Inspector.

In the Simulation Data Inspector, select PlantOutput as the signal to compare.

The plot of the plant output signal for EmbeddedRun is within the specified tolerance band.

If the behavior of the converted system does not meet your requirements or if you wish to explore the effect of additional data type selections, you can propose new data types after applying new proposal settings. Continue iterating until you find settings for which the fixed-point behavior of the system is acceptable.

After the conversion process, if you want to restore your model to its state at the start of the conversion process, click Restore Original Model. Any changes made to your model after the preparation stage of conversion are removed.

See Also