Products & Services Solutions Academia Support User Community Company

Tutorial: Feedback Controller

Before You Begin

The tutorial that follows shows you how to use the Fixed-Point Tool to refine the scaling of fixed-point data types associated with a feedback controller model (see Introduction to the Tutorial). Although the tool enables multiple workflows for converting a digital controller described in ideal double-precision numbers to one realized in fixed-point numbers, this tutorial demonstrates the following approach:

  1. Initial Guess at Scaling. Run an initial "proof of concept" simulation using a reasonable guess at the fixed-point word size and scaling. This task illustrates how difficult it is to guess the best scaling.

  2. Data Type Override. Perform a global override of the fixed-point data types using double-precision numbers. The Simulink software logs the simulation results to the MATLAB workspace, and the Fixed-Point Tool displays them.

  3. Automatic Scaling. Perform the automatic scaling procedure, which uses the double-precision simulation results to propose fixed-point scaling for appropriately configured blocks. The Fixed-Point Tool allows you to accept and apply the scaling proposals selectively. Afterward, you determine the quality of the results by examining the input and output of the model's analog plant.

To begin, open both the fxpdemo_feedback model and the Fixed-Point Tool.

Initial Guess at Scaling

Initial guesses for the scaling of each block are already specified in each block mask in the model. This task illustrates the difficulty of guessing the best scaling.

  1. In the Fixed-Point Tool, click the Start button .

    The Simulink software simulates the fxpdemo_feedback model. Afterward, the Fixed-Point Tool displays in its Contents pane the simulation results for each block that logged fixed-point data. The tool stores the results as an active run, denoted by the Active label in the Run column. The Saturations column reveals that the Up Cast block saturated 23 times, which indicates a poor guess for its scaling.

      Tip   You can use the Show option in the main toolbar to view only blocks that have Overflows.

  2. In the Contents pane of the Fixed-Point Tool, select the Transfer Fcn block named Analog Plant and then click the Time Series Plot button .

    The Fixed-Point Tool plots the signal associated with the plant output.

The preceding plot of the plant output signal reflects the initial guess at scaling. The Bode plot design sought to produce a well-behaved linear response for the closed-loop system. Clearly, the response is nonlinear. Significant quantization effects cause the nonlinear features. An important part of fixed-point design is finding a scaling that reduces quantization effects to acceptable levels.

Data Type Override

Data type override mode enables you to perform a global override of the fixed-point data types and scaling using double-precision numbers, thereby avoiding quantization effects. The Fixed-Point Tool will use these simulation results when performing automatic scaling to propose higher fidelity fixed-point scaling.

  1. In the Dialog pane of the Fixed-Point Tool:

    • Click the Exchange Active and Reference results button. The tool swaps the results that it stores as an active run with those that it stores as a reference run. The existing results are now stored as a reference run, denoted by the Reference label in the Run column, and the active run is empty. This prevents the tool from overwriting the previous set of results.

    • Ensure that the Fixed-point instrumentation mode parameter for the fxpdemo_feedback system specifies Minimums, maximums and overflows. This option enables logging for all the model's blocks that can log such data.

    • Specify the Data type override parameter for the fxpdemo_feedback system as True doubles. This option overrides all local data type settings for the model's subsystems.

    The Fixed-Point Tool appears.

  2. In the Fixed-Point Tool, click the Start button .

    The Simulink software simulates the fxpdemo_feedback model in data type override mode and stores the results as an active run. Afterward, the Fixed-Point Tool displays in its Contents pane the active run results along with those of the reference run that you generated previously (see Initial Guess at Scaling). The SimDT (simulation data type) column for the active run shows that the model's blocks used a double data type during simulation.

  3. In the Contents pane of the Fixed-Point Tool, select the Transfer Fcn block named Analog Plant that corresponds with either the active or the reference run, and then click the Time Series Difference (A-R) Plot button .

    The Fixed-Point Tool plots both the active and reference versions of the signal associated with the plant output (upper axes), and plots the difference between the active and reference versions of that signal (lower axes). Compare the ideal (double data type) plant output signal with its fixed-point version.

      Tip   You can use the Zoom tool to zoom in on an area of interest. By default, synchronized zooming is enabled for the Time Series Difference (A-R) plot. Zooming on either plot zooms both plots. For more information, see Plot Interface in the fxptdlg Reference.

Automatic Scaling

Using the automatic scaling procedure, you can easily maximize the precision of the output data type while spanning the full simulation range. For a complex model, the absence of such a procedure can make achieving this goal tedious and time consuming.

Perform automatic scaling for the Controller block. This block is a subsystem that represents software running on the target, and it requires optimization.

  1. In the Model Hierarchy pane of the Fixed-Point Tool, select the Controller subsystem. In the Dialog pane, ensure that Use simulation min/max if design min/max is not available is selected then specify the Percent safety margin for simulation min/max parameter as 20.

    Because no design min/max information is supplied, the simulation min/max data that was collected during the simulation run is used for autoscaling. The Percent safety margin for simulation min/max parameter value multiplies the "raw" simulation values by a factor of 1.2. Setting this parameter to a value greater than 1 decreases the likelihood that an overflow will occur when fixed-point data types are being used. For more information about how the Fixed-Point Tool calculates scaling proposals, see Proposing Scaling.

    Because of the nonlinear effects of quantization, a fixed-point simulation will produce results that are different from an idealized, doubles-based simulation. Signals in a fixed-point simulation can cover a larger or smaller range than in a doubles-based simulation. If the range increases enough, overflows or saturations could occur. A safety margin decreases the likelihood of this happening, but it might also decrease the precision of the simulation.

  2. In the Fixed-Point Tool, click the Propose fraction lengths button .

    The Fixed-Point Tool analyzes the scaling 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.

    The Fixed-Point Tool uses the minimum and maximum values stored in the active run to propose each block's scaling such that the precision is maximized while the full range of simulation values is spanned. The tool displays the proposed scaling in its Contents pane:

      Tip   You can use the Show option in the main toolbar to view the groups that must share data types. For more information, see fxptdlg in the Simulink Reference.

  3. Review the scaling that the Fixed-Point Tool proposes. You can choose to accept the scaling proposal for each block by selecting the corresponding Accept check box in the Contents pane. By default, the Fixed-Point Tool accepts all scaling proposals that differ from the current scaling. For this example, ensure that the Accept check box associated with the active run is selected for each of the Controller subsystem's blocks.

  4. In the Fixed-Point Tool, click the Apply accepted fraction lengths button .

    The Fixed-Point Tool applies to the Controller subsystem's blocks the scaling proposals that you accepted in the previous step.

  5. In the Model Hierarchy pane of the Fixed-Point Tool, select the fxpdemo_feedback system. In the Dialog pane:

    • Click the Exchange Active and Reference results button. The tool swaps the results that it stores as an active run with those that it stores as a reference run. The simulation results corresponding to True doubles override are now stored as a reference run. This prevents the tool from overwriting the results that we want to retain.

    • Specify the Data type override parameter as Use local settings. This option enables each of the model's subsystems to use its locally specified data type settings.

  6. In the Fixed-Point Tool, click the Start button .

    The Simulink software simulates the fxpdemo_feedback model using the new scaling that you applied in step 4. Afterward, the Fixed-Point Tool displays in its Contents pane information about blocks that logged fixed-point data. The SimDT (simulation data type) column for the active run shows that the Controller subsystem's blocks used fixed-point data types with the new scaling.

  7. In the Model Hierarchy pane of the Fixed-Point Tool, select the fxpdemo_feedback system. In the Contents pane, select the Transfer Fcn block named Analog Plant that corresponds with either the active or the reference run, and then click the Time Series Difference (A-R) Plot button .

    The Fixed-Point Tool plots the active and reference versions of the plant output signal, as well as their difference. Compare the ideal plant output signal (of data type double) in the reference run with its fixed-point version in the active run.

  8. Optionally, you can zoom in to view the steady-state region with greater detail. From the Tools menu of the figure window, select Zoom In and then drag the pointer to draw a box around the area you want to view more closely. For instance, the following figure shows a close-up view of a portion of the previous plot.

    Note that the plant output signal represented by the active run achieves a steady state, but a small limit cycle is present because of poor A/D design.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS