MATLAB Examples

Code Verification and Validation with PIL

This example shows you how to use Embedded Coder Support Package for Texas Instruments C2000 processor for code verification and validation using PIL.

Contents

Introduction

In this example you will learn how to configure a Simulink model to run Processor-In-the-Loop (PIL) simulation. In a PIL simulation, the generated code runs on the Texas Instruments C2000 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 development cycle to ensure that the behavior of the deployment code matches the design.

This example introduces how to configure a Simulink model for code generation and verification using :

  • PIL Block
  • Model Block PIL
  • Top-Model PIL

Required Hardware

To run this example you will need the following hardware: Texas Instruments C2000 processor based board with serial over USB capabilities

The Texas Instruments controlCard provides serial over USB capabilities. This allows serial communication from the target to your host computer. We will use this serial connection in this example to exchange data from Simulink to the target.

Some boards do not provide a FTDI chip and use the FTDI on the docking station and use the USB serial cable to establish a serial connection between the host computer and the target hardware. You can also use the COM1 port of your computer to establish an RS-232 serial connection with the board. See Set Up Serial Communication with Target Hardware for details on establishing a serial connection between the target and the host computer.

Task 1 - Choose a Serial Communication Interface for PIL Simulation

The Embedded Coder Support Package for Texas Instruments C2000 supports serial communication interface for PIL over SCI-A.

After establishing a serial connection, find the COM port associated with the target hardware.

For more information on how to configure the Virtual COM port refer to this page. Note the COM port number of the USB Serial Port showing in your Windows Device Manager under Ports "(COM & LPT)"

1. Connect the target hardware to your host machine

2. Enable the settings for running PIL on Serial

  • Set the COM Port as obtained above and replace the 'COM1' in the following command with the correct Serial port corresponding to your controlCARD:

setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','COMPort','COM1');

  • Set the baud rate for PIL communication by entering the baud rate as

setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','BaudRate',115200);

  • Enable PIL over serial by the following command:

setpref('MathWorks_Embedded_IDE_Link_PIL_Preferences','enableserial',true);

Task 2 - Verify the generated code for a subsystem using a PIL block

This example shows how to use a PIL block for subsystem code verification. With this approach:

  • You can verify the code generated for a subsystem
  • You must swap your original subsystem with a generated PIL block; make sure to avoid saving your model in this state as you would lose your original subsystem

1. Open the PIL Block model. This model is configured for the TI Piccolo F2806x target. You can configure the model to run on other TI C2000 processors or TI C2000 Concerto C28x core by changing the target hardware in the Configuration Parameters > Hardware Implementation pane. The objective here is to create a PIL block out of the Controller subsystem that you will run on the Texas Instruments C2000 processor.

2. Choose a PIL communication interface by following the steps in Task 1 above.

3. Create a PIL block for the Controller subsystem by following Task Example 1 of the Verify Generated Code Using Software-in-the-Loop (SIL) and Processor-in-the-Loop (PIL) Simulation.

4. Run the PIL simulation by following Example 1 of the Verify Generated Code Using Software-in-the-Loop (SIL) and Processor-in-the-Loop (PIL) Simulation.

5. You can switch between the original and PIL block subsystems by double clicking on the Manual Switch block. Double click on the Numerical Difference block to see the difference between the simulated Controller subsystem and the PIL block running on the target processor.

Task 3 - Verify referenced model code using PIL

This example shows how to verify the generated code for a referenced model by running a PIL simulation. With this approach:

  • You can verify code generated for referenced models
  • You can easily switch a Model block between normal and PIL simulation mode

1. Open the Model Block PIL model. This model is configured for TI Piccolo F2806x target. To configure the model to run on other TI C2000 processors you can change the target hardware in the Configuration Parameters > Hardware Implementation pane. The model contains two Model blocks that both point at the same referenced model. You will configure one of the Model blocks to run in PIL simulation mode and the other in normal mode.

2. Choose a PIL serial communication interface by following the steps in Task 1 above.

3. Configure and run CounterA Model block in PIL simulation mode by following Example 2 of the Verify Generated Code Using Software-in-the-Loop (SIL) and Processor-in-the-Loop (PIL) Simulation.

4. When the model starts running, Scope1 displays the PIL simulation output running on the TI Piccolo F2806x processor while Scope2 shows the normal mode simulation output.

Task 4 - Verify top model code using PIL

This example shows how to verify the generated code for a model by running a PIL simulation. With this approach:

  • You can verify code generated for a top model
  • You can easily switch the entire model between normal and PIL simulation mode

1. Open the Top Model PIL model. This model is configured for the TI Piccolo F2806x target.

2. Choose a PIL serial communication interface by following the steps in Task 1 above.

3. Run the top model PIL simulation by following Example 3 of the Verify Generated Code Using Software-in-the-Loop (SIL) and Processor-in-the-Loop (PIL) Simulation.

4. When the PIL simulation is completed, a logsOut variable is created in the base workspace. The logsOut data contains PIL simulation results. You can access the logged data for signals count_a and count_b using the following commands:

  • count_a = get(logsOut,'count_a');
  • count_a.Values.Data
  • count_b = get(logsOut,'count_b');
  • count_b.Values.Data

Summary

This example introduced code verification workflows using PIL