主要内容

Code Verification and Profiling Using PIL Testing

在循环(PIL)仿真中,控制算法在目标硬件中执行,但植物模型在主机机器上运行。工厂模型模拟控制器的输入和输出信号,并使用串行通信接口与控制器通信。此功能使您可以使用PIL模拟来确定目标硬件上的执行时间,然后您可以将其与模拟主机上模型的执行时间进行比较。

The execution time, or the performance metric of an algorithm that you obtain from PIL simulation, helps you detect algorithm overrun on the target hardware. The PIL profiling report shows the average and maximum execution times of an algorithm on the target hardware. This example explains PIL profiling on Texas Instruments™ LAUNCHXL-F28379D hardware board.

This example uses themcb_pmsm_foc_sim.slx在PIL模拟中显示代码验证的模型。此示例显示了模型中当前控制子系统的PIL分析。该子系统包括面向现场的控制(FOC),电流缩放(每个单位转换),速度测量和转子位置缩放(从编码器位置计数计算角度计算)算法。PIL分析报告显示了目标硬件中控制算法的平均执行时间和最大执行时间。

此示例包括以下任务:

  • 通过比较模拟中的算法和目标硬件操作模式,通过使用PIL测试来验证代码执行。

  • Perform PIL profiling by measuring the algorithm execution time in the target hardware and generate the PIL profiling report.

必需的MathWorks下载188bet金宝搏

  • 嵌入式编码器®

  • Texas Instrumen金宝appts C2000™处理器的嵌入式编码器支持包

Supported Hardware

  • launchxl-F28379D控制器硬件板

Prepare PIL Model

  1. Open themcb_pmsm_foc_sim.slxmodel.

    open_system('mcb_pmsm_foc_sim.slx');

    该模型模拟PMSM电机和焦点算法以进行闭环速度控制。

  2. On theHardwareSimulink工具条金宝app的选项卡,单击Hardware Settings.

  3. 在里面Configuration Parameters对话框,下硬件实现,设置Hardware board字段到TI Delfino F28379D LaunchPad.

使用PIL验证代码

  1. 在里面Configuration Parameters dialog box, select these configuration settings under硬件实现>Hardware board settings>Target hardware resources>pil:

    1. Communication Interface- 选择系列.

    2. SCI module- 选择科学.

    3. Serial port in MATLAB preferences— The model automatically detects the communication port to which you have connected the hardware. This parameter remains unchanged for the rest of the currently active MATLAB®会议。点击刷新button to detect the communication port again.

  2. Open theMCB_PIL_CONFIG_TI.M脚本文件以设置配置参数。

    edit('mcb_pil_config_ti.m');
  3. Update the model name and stop time in the script.

  4. Run the script to update the configuration parameters of the simulation model and the PIL preferences.

  5. 右键单击当前的控制子系统mcb_pmsm_foc_sim.slxexample model. Under theC/C++ Codemenu, selectDeploy this Subsystem to Hardware.

    该系统显示建造code for Subsystem对话框。将存储类设置为嵌入式对于所有参数。

  6. Click建造创建一个名称的模型无题that includes a PIL subsystem called Current Control.

  7. Rename the Current Control subsystem to Current Control (PIL).

  8. 复制当前控件(PIL)子系统并替换当前控制子系统mcb_pmsm_foc_sim.slxexample model.

    在里面pilmode, the system deploys the Current Control (PIL) subsystem to the target and executes the subsystem in the target hardware.

  9. To compare the algorithm execution on the host machine simulation and in the PIL simulation, connect the Current Control subsystem parallely to the Current Control (PIL) subsystem. In addition, enable signal logging in the subsystem outputs.

  10. 在Simuli金宝appnk工具条上,选择SIL/PILManagerapp from theAppstab.

  11. On theSIL/PILtoolstrip, selectSIL/PIL SIM.

  12. SelectSIL/PIL模式的模型块在里面System Under Testfield.

  13. ClickRun SIL/PILSIL/PIL构建当前控件(PIL)子系统并将其部署到目标的工具分。

    After the system deploys the subsystem, the Current Control (PIL) subsystem executes on the target hardware processor, while the plant model runs on the host machine.

分析PIL分析结果

When PIL simulation ends, the system generates a profiling report.

Note

PIL模拟比基于宿主机的仿真需要更多的时间。这是因为在目标硬件上运行的主机计算机和子系统之间的串行通信(与当前控件(PIL)子系统的输入和输出有关。

This profiling report, which is for the fixed-point datatype, shows the maximum and average execution times of the Current Control (PIL) subsystem running on the target hardware.

You can use the数据检查员button on the模拟tab to compare the signals logged during host-machine-based simulation and PIL simulation (executed on the target). This helps you verify the accuracy of host-machine-based simulation and PIL simulation.

This plot compares the speed feedback signals from the Current Control (PIL) and Current Control subsystems.

If the execution time exceeds 60% of the budgeted time, you can optimize the algorithm using one of these techniques:

  • Execute from RAM.

  • 将一些功能卸载到CLA或其他CPU。

  • Scale the algorithm to run at every alternate cycle.

  • Move less critical functionalities like speed calculation to a slower rate.

For more details on SIL/PIL code verification, see: