Preparation for Fixed-Point Conversion

Introduction

Using the Fixed-Point Advisor, you can prepare a model for conversion from a floating-point model or subsystem to an equivalent fixed-point representation. After preparing the model for conversion, use the Fixed-Point Tool to obtain initial fixed-point data types and then refine these data types.

Best Practices

Use a Known Working Model

Before using the Fixed-Point Advisor, verify that update diagram succeeds for your model. To update diagram, press Ctrl+D. If update diagram fails, before you start converting your model, fix the failure in your model.

Back Up Your Model

Back up your Simulink® model first.

This practice provides you with a back up in case of error and a baseline for testing and validation.

Convert Small Models

The Fixed-Point Advisor is intended to assist in converting small models. Using larger models can result in long processing times.

Convert Subsystems

Convert subsystems within your model, rather than the entire model. This practice saves time and unnecessary conversions.

Specify Short Simulation Run Times

Specifying small simulation run times reduces task processing times. You can change the simulation run time in the Configuration Parameters dialog box. For more information, see Start time and Stop time in the Simulink Reference.

Make Small Changes to Your Model

Make small changes to your model so that you can identify where errors are accidentally introduced.

Isolate the System Under Conversion

If you encounter data type propagation issues with a particular subsystem, isolate this subsystem by placing Data Type Conversion blocks on the inputs and outputs of the system. The Data Type Conversion block converts an input signal of any Simulink software data type to the data type and scaling you specify for its Output data type parameter. This practice enables you to continue converting the rest of your model.

The ultimate goal is to replace all blocks that do not support fixed-point data types. You must eventually replace blocks that you isolate with Data Type Conversion blocks with blocks that do support fixed-point data types.

Use Lock Output Data Type Setting

You can prevent the Fixed-Point Advisor from replacing the current data type. Use the Lock output data type setting against changes by the fixed-point tools parameter available on many blocks. The default setting allows replacement. Use this setting when:

  • You already know the fixed-point data types that you want to use for a particular block.

    For example, the block is modeling a real-world component. Set up the block to allow for known hardware limitations, such as restricting outputs to integer values.

    Specify the output data type of the block explicitly and select Lock output data type setting against changes by the fixed-point tools.

  • You are debugging a model and know that a particular block accepts only certain data types.

    Specify the output data type of upstream blocks explicitly and select Lock output data type setting against changes by the fixed-point tools.

Save Simulink Signal Objects

The Fixed-Point Advisor proposes data types for Simulink signal objects in your model. However, it does not automatically save Simulink signal objects. To preserve changes, before closing the model, save the Simulink signal objects in your workspace and model before closing the model.

Save Restore Point

Before making changes to your model that might cause subsequent update diagram failure, consider saving a restore point. For example, before applying proposed data types in task 3.1. For more information, see Save a Restore Point.

Run the Fixed-Point Advisor

  1. Open a model.

  2. Start the Fixed-Point Advisor by:

    • Typing fpcadvisor('model_name/subsystem_name') at the MATLAB® command line

    • Selecting a subsystem and, from the menu, selecting Analysis > Fixed-Point Tool to open the Fixed-Point Tool. On the Fixed-Point Tool Fixed-point preparation for selected system pane, click Fixed-Point Advisor.

    • Right-clicking a subsystem block and, from the subsystem context menu, selecting Fixed-Point Tool to open the Fixed-Point Tool. On the Fixed-Point Tool Fixed-point preparation for selected system pane, click Fixed-Point Advisor.

  3. In the Fixed-Point Advisor window, on the left pane, select the Fixed-Point Advisor folder.

  4. Run the advisor by:

    • Selecting Run All from the Run menu.

    • Right-clicking the Fixed-Point Advisor folder and selecting Run All from the folder context menu.

    The Fixed-Point Advisor runs the tasks in order until a task fails. A waitbar is displayed while each task runs.

  5. Review the results. If a task fails because input parameters are not specified, select an Input Parameter. Then continue running to failure by right-clicking the task and selecting Continue from the context menu. If the task fails for a different reason, fix the task as described in Fix a Task Failure.

    If your model contains referenced models, the Fixed-Point Advisor provides results for each referenced model instance.

Fix a Task Failure

Tasks fail when there is a step for you to take to convert your model from floating-point to fixed-point. The Fixed-Point Advisor provides guidance on how to fix the issues.

You can fix a failure using three different methods:

    Note:   A warning result is meant for your information. You can choose to fix the reported issue or move on to the next task.

Manually Fixing Failures

All checks have an Analysis Result box that describes the recommended actions to manually fix failures.

To manually fix warnings or failures within a task:

  1. Optionally, save a restore point so you can undo the changes that you make. For more information, see Save a Restore Point.

  2. In the Analysis Result box, review the recommended actions. Use the information to make changes to your model.

  3. To verify that the task now passes, in the Analysis box, click Run This Task.

Automatically Fixing Failures

You can automatically fix failures using the Action box. The Action box applies all of the recommended actions listed in the Analysis Result box.

    Caution   Prior to automatically fixing failures, review the Analysis Result box to ensure that you want to apply all of the recommended actions.

Automatically fix all failures within a task using the following steps:

  1. Optionally, save a restore point so you can undo the changes that you make. For more information, see Save a Restore Point.

  2. In the Action box, click Modify All.

    The Action Result box displays a table of changes.

  3. To verify that the task now passes, in the Analysis box, click Run This Task.

Batch Fixing Failures

If a task fails and you want to explore the results and make batch changes, use the following steps.

  1. Optionally, save a restore point so you can undo the changes that you make. For more information, see Save a Restore Point.

  2. In the Analysis box, click Explore Result.

  3. Use the Model Advisor Result Explorer to modify block parameters.

  4. When you finish making changes, in the Fixed-Point Advisor window, click Run This Task to see if the changes you made result in the task passing. Continue fixing failures and rerunning the task until the task passes.

Restore Points

The Fixed-Point Advisor provides a model and data restore point capability for reverting changes that you made in response to advice from the Fixed-Point Advisor. A restore point is a snapshot in time of the model, base workspace, and Fixed-Point Advisor.

    Caution   A restore point saves only the current working model, base workspace variables, and Fixed-Point Advisor tree. It does not save other items, such as libraries and referenced submodels.

To learn how to save a restore point, see Save a Restore Point.

To learn how to load a restore point, see Load a Restore Point.

Save a Restore Point

When to Save a Restore Point

Consider saving a restore point:

  • Before applying changes to your model that might cause update diagram failure. For example, before applying proposed data types in task 3.1.

  • Before attempting to fix failures.

How to Save a Restore Point

You can save a restore point and give it a name and optional description, or allow the Fixed Point Advisor to automatically name the restore point for you.

To save a restore point with a name and optional description:

  1. From the main menu, select File > Save Restore Point As.

  2. In the Save Model and Data Restore Point dialog box, in the Name field, enter a name for the restore point.

  3. In the Description field, you can optionally add a description to help you identify the restore point.

  4. Click Save.

    The Fixed Point Advisor saves a restore point of the current model, base workspace, and Fixed Point Advisor status.

    Note:   To quickly save a restore point, go to File > Save Restore Point. The Fixed Advisor saves a restore point with the name autosaven. n is the sequential number of the restore point. If you use this method, you cannot change the name of, or add a description to, the restore point.

Load a Restore Point

When to Load a Restore Point

Load a restore point when:

  • A task fails and you cannot continue the conversion. In this case, load a restore point saved earlier in the run to avoid rerunning all the previous tasks.

  • You want to revert changes you made in response to advice from the Fixed-Point Advisor.

How to Load a Restore Point

To load a restore point:

  1. Go to File > Load Restore Point.

  2. In the Load Model and Data Restore Point dialog box, select the restore point that you want.

  3. Click Load.

    The Model Advisor issues a warning that the restoration will overwrite the current model and workspace.

  4. Click Load to load the restore point that you selected.

    The Fixed Point Advisor reverts the model, base workspace, and Fixed Point Advisor status.

Was this topic helpful?