Main Content

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.

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.

这个示例介绍了如何配置一个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. SeeSet Up Serial Communication with Target Hardwarefor 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 Serial.

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

更多的备用ion on how to configure the Virtual COM port refer tothis 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.Configure the Serial to run PIL. For more information, referSerial Configuration for External Mode and PIL

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 PIL block in the model as indicated by the comments in the model; make sure to avoid saving your model in this state as you would lose your original subsystem

1.Open thePIL Blockmodel. This model is configured for theTI Piccolo F2806xtarget. 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 theControllersubsystem 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 theControllersubsystem as explained inTest Generated Code with SIL and PIL Simulations.

4.Place the PIL block created in the model as shown by the comments in the model.

5.Run the PIL simulation as explained inTest Generated Code with SIL and PIL Simulations.

6.You can switch between the original and PIL block subsystems by double clicking on theManual Switchblock. Double click on theNumerical Differenceblock to see the difference between the simulatedControllersubsystem 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 theModel Block PILmodel. This model is configured forTI Piccolo F2806xtarget. 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 runCounterAModel block in PIL simulation as explained inTest Generated Code with SIL and PIL Simulations.

4.When the model starts running,Scope1displays the PIL simulation output running on the TI Piccolo F2806x processor whileScope2shows 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 theTop Model PILmodel. This model is configured for theTI Piccolo F2806xtarget.

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

3.Run the top model PIL simulation as explained inTest Generated Code with SIL and PIL Simulations.

4.When the PIL simulation is completed, alogsOutvariable is created in the base workspace. ThelogsOutdata contains PIL simulation results. You can access the logged data for signalscount_aandcount_busing 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