Main Content

将引用模型转换为固定点

当设计系统包含引用模型时,定点工具根据通过仿真或派生范围分析收集的范围提出了引用模型中对象的数据类型。如果设计中的系统包含相同引用模型的几个实例,则定点工具将收集到的范围的结合用于数据类型建议。

这Fixed-Point tool logs simulation minimum and maximum values only for instances of the referenced model that are in normal mode. It does not log simulation minimum and maximum values for instances of the referenced model that are in non-Normal modes. If your model contains multiple instances of a referenced model and some are instances are in normal mode and some are not, the tool logs and displays data for those that are in normal mode.

打开ex_mdlref_controller模型。At the MATLAB®命令行,输入:

addpath(fullfile(Docroot,'toolbox',,,,'fixpoint',,,,'examples')); ex_mdlref_controller

In the应用模型画廊,选择定点工具

当模型包含引用模型时,定点工具模型层次结构pane displays a subnode for the instance of the referenced model and a node for the referenced model. For example, theex_mdlref_controller模型包含aModel块引用ex_controller模型。定点工具在模型层次结构中显示两个模型。

If a model contains multiple instances of a referenced model, the tool displays each instance of the referenced model in this model and a node for the referenced model. For example, in the same model, if you duplicate the referenced model such that theex_mdlref_controllermodel contains two instances of the referenced modelex_controller。这定点工具displays both models and both instances of the referenced model in the model hierarchy.

Viewing Simulation Ranges for Referenced Models

  1. In the Fixed-Point Tool, underNew, 选择the迭代的定点转换workflow.

  2. 在下面设计中的系统(SUD), 选择theex_controllermodel as the system you want to convert to fixed point.

  3. 在下面范围收集模式, 选择Simulation Rangesas the range collection method.

  4. In the toolstrip, click准备。定点工具检查系统正在设计的系统中是否与转换过程兼容,并报告模型中发现的任何问题。在此示例中,该工具报告了该模型已准备好进行转换。

  5. Expand theCollect Ranges按钮箭头并选择双重精度。点击Collect Ranges按钮开始模拟。固定点工具覆盖了模型中的数据类型,并收集模型中每个对象中每个对象的最小值和最大值。定点工具将此范围存储在标题的运行中基础

该工具为每个在日志和显示结果stance of the referenced model. For example, here are the results for the first instance of the referenced modelex_controller

Here are the results for the second instance ofex_controller

In the referenced model node, the tool displays the union of the results for each instance of the referenced model.

定点仪器和数据类型覆盖设置

当您模拟包含引用模型的模型时,顶级模型的数据类型覆盖和定点仪器设置将无法控制引用模型的设置。您必须为引用模型分别指定这些设置。例如,如果设置不一致,例如,如果将顶级模型数据类型覆盖设置设置为double,并且引用模型使用本地设置,并且引用模型使用固定点数据类型,则可能会发生数据类型传播问题。

You can define custom data type override settings usingset_param.For an example, see使用自定义数据类型覆盖设置进行范围收集

当您为引用模型的任何实例更改定点仪器和数据类型覆盖设置时,设置在模型的所有实例和引用模型本身上都会更改。

提出引用模型的数据类型

  1. In the兑换section of the toolstrip, clickSettings。指定模拟最小/最大(%)的安全保证金参数为20

  2. 点击提出数据类型

    由于没有提供最小值和最大信息,因此模拟过程中收集的最小和最大数据用于提出数据类型。这模拟最小/最大(%)的安全保证金参数值将“原始”仿真值乘以1.2倍。设置模拟最小/最大(%)的安全保证金parameter to a value greater than 1 decreases the likelihood that an overflow will occur when fixed-point data types are being used.

    由于量化的非线性效应,固定点仿真产生的结果与理想化的基于双打的模拟不同。与基于双打的模拟相比,定点模拟中的信号可以覆盖更大或更小的范围。如果范围增加足够,则可能发生溢出或饱和。安全边缘降低了这种情况的可能性,但也可能降低了模拟的精度。

    定点工具分析了所有定点块的缩放Lock output data type setting against changes by the fixed-point toolsparameter is not selected.

    固定点工具使用模拟过程中收集的最小值和最大值为每个块提出缩放,以使精度最大化,同时跨越了整个仿真值。该工具在电子表格中显示提出的缩放。

  3. Review the scaling that the Fixed-Point Tool proposes. You can choose to accept the scaling proposal for each block by selecting the correspondingAcceptcheck box. By default, the Fixed-Point Tool accepts all scaling proposals that differ from the current scaling. For this example, verify that theAcceptcheck box is selected for each of the Controller system’s blocks.

    To view more information about a proposal, select the result and view theResult Detailspane.

  4. 在定点工具中,单击应用数据类型button.

    这定点工具applies the scaling proposals that you accepted in the previous step.

  5. In the核实工具条的部分,单击Simulate with Embedded Typesbutton.

    金宝app®模拟ex_mdlref_controller使用您应用的新缩放模型。之后,定点工具显示有关记录定点数据的块的信息。

  6. 点击Compare Results。这Simulation Data Inspector plots the Analog Plant output for the floating-point and fixed-point runs and the difference between them.

Related Topics