Verify Numerical Accuracy Using PIL

Using PIL

In a processor-in-the-loop (PIL) simulation, the generated code runs on the Texas Instruments™ Hercules RM57Lx LaunchPad containing an ARM® Cortex®-R processor. The results of the PIL simulation are transferred to Simulink® to verify the numerical equivalence of the simulation and the code generation results. The PIL verification process is a crucial part of the design cycle to check that the behavior of the generated code matches the design.

Perform PIL Verification Using PIL Block

This example shows how to create a PIL block from a Subsystem block that contains the model that you want to verify. It then shows how to verify numerical equivalence by comparing the signals of the two blocks.

With this approach:

  • You can verify code generated for subsystems.

  • You must provide a test harness model to supply test vector or stimulus inputs.

  • You must swap your original subsystem with a generated PIL block. Do not save your model in this state, or you will lose your original subsystem.

For more information, see .

Tip

For an interactive example of this process, see Task 1 - Verify generated code using PIL block in Code Verification and Validation with PIL and External Mode. To see the corresponding model, enter arm_cortex_r_model_pil_block in the MATLAB® Command Window.

Create a Subsystem and a PIL block from the model that you want to test:

  1. Create a model, called the test harness model, and configure it for the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad), as described in Build and Run Executable on the Texas Instruments Hercules RM57Lx LaunchPad.

  2. Set Configuration Parameters > All Parameters > Create block to PIL. Then, click OK.

  3. Add a Subsystem block to the test harness model.

  4. Right-click the Subsystem block and select Block Parameters (Subsystem).

  5. In the Subsystem dialog box, select Treat as atomic unit.

  6. Place or create the model that you want to test within the Subsystem block.

  7. Right-click the Subsystem block and select C/C++ Code > Build This Subsystem.

  8. In the Build code for Subsystem dialog box, click Build.

    This action creates an untitled* model that contains a PIL block named after the subsystem.

  9. Copy the PIL block from untitled* to the test harness model.

  10. Close untitled* without saving it.

Create a test harness around the Subsystem and PIL blocks, similar to this sample test harness.

To create a test harness, you can:

  • Use parallel inputs for the Subsystem and PIL blocks.

  • Use a Sum block to compare the outputs for differences.

  • Connect the output of the Sum block to a Scope block to display the numerical differences.

  • Use a Manual Switch block to toggle between the outputs of the two blocks

Run the PIL simulation:

  1. Confirm that Simulation mode is set to Normal.

  2. Click Build Model to simulate the test harness model in Simulink.

    This action simulates the test harness model in Simulink software. It runs the PIL block on the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad). The simulation lasts for the duration specified by the Simulation stop time.

  3. During the simulation, you can:

    • Use the Manual Switch to toggle between the two outputs.

    • Observe the scope for numerical differences.

Perform PIL Verification Using Model Block PIL

This example shows how to run two model blocks, one in normal simulation, and the other in PIL simulation, to verify that their outputs are numerically equivalent.

With this approach:

  • You can verify code generated for referenced models.

  • You must provide a test harness model to supply test vector or stimulus inputs.

  • You can easily switch a model block between the normal and PIL simulation modes.

For more information, see .

Note

For an interactive example of this process, see Task 2 - Verify generated code using PIL Simulation for Model Blocks in Code Verification and Validation with PIL and External Mode. To see the corresponding model, enter arm_cortex_r_model_pil_block in the MATLAB Command Window.

  1. Create the model that you want to verify, called the referenced model.

  2. Create a model to run the PIL simulation, called the test model.

  3. Configure both the referenced model and the test model for the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad), as described in Build and Run Executable on the Texas Instruments Hercules RM57Lx LaunchPad.

    You must maintain the same model configuration parameter values for both the referenced model and the test model. You can share a configuration between the two models, as described in Share a Configuration for Multiple Models (Simulink).

  4. Add a Model block to the test model that points to your referenced model, as described in Reference Existing Models (Simulink).

  5. Copy and paste the Model block so that the test model contains two identical Model blocks.

  6. Create parallel inputs and outputs for the Model blocks.

    To see an example model of this type, enter arm_cortex_r_model_pil_block in a MATLAB Command Window.

  7. Right-click one of the Model blocks, and select Block Parameters (ModelReference).

  8. In the Function Block Parameters dialog box, set Simulation mode to Processor-in-the-Loop and set Code Interface to Model reference. Click OK.

  9. Leave the Simulation mode of the test model and the other Model block set to Normal.

  10. Click Run to simulate the test model and one Model block in Simulink.

    The Simulink software runs the Model block that you configured to use PIL on the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad). The simulation lasts for the duration specified by the Simulation stop time.

Perform PIL Verification Using PIL Simulation for Top Models

This example shows you how to record PIL simulation data from your model, and then review it using the Simulation Data Inspector.

With this approach:

  • You can verify code generated for a top model.

  • You must configure the model to load test vectors or stimulus inputs from the MATLAB workspace.

  • You can switch the entire model between normal and PIL simulation mode.

For more information, see .

Note

For an interactive example of this process, see Task 2 - Verify generated code using PIL Simulation for Model Blocks in Code Verification and Validation with PIL and External Mode (Embedded Coder Support Package for ARM Cortex-A Processors). To see the corresponding model, enter arm_cortex_r_top_model_pil in the MATLAB Command Window.

  1. Create the model that you want to verify, called the test model, and configure it for the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad), as described in Build and Run Executable on the Texas Instruments Hercules RM57Lx LaunchPad.

    To see an example model of this type, enter arm_cortex_r_top_model_pil in a MATLAB Command Window.

  2. Set Simulation mode to Processor-in-the-Loop (PIL).

  3. Click the Simulation Data Inspector button arrow, and enable Send Logged Workspace Data to Data Inspector.

  4. Click Run to test the model in PIL mode on the ARM Cortex-R (Texas Instruments Hercules RM57Lx LaunchPad). The simulation lasts for the duration specified by the Simulation stop time.

  5. When the PIL simulation stops, click the Simulation Data Inspector button to open the Simulation Data Inspector and review the PIL data.

Related Topics