Code Verification and Validation with PIL
This example shows you how to use Texas Instruments™ C2000™ Processor for code verification and validation using PIL in C2000™ Microcontroller Blockset.
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
Note: If you have fixed point license, configure Configuration Parameters > Math and Data Types > Simulation behavior for denormal numbers to Flush to Zero (FTZ)
instead of Gradual Underflow
, which matches the actual hardware behavior.
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 control Card 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 C2000™ Microcontroller Blockset supports serial communication interface for PIL over Serial.
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. Configure the Serial to run PIL. For more information, refer Serial 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 the c2000_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.
Note: If you choose to select a different TI C2000 processors other than default configured model, ensure you set the Total number of instances allowed per top model to Multiple under Configuration parameters > Model Referencing > Options for referencing this model.
2. Choose a PIL communication interface by following the steps in Task 1 above.
3. Create a PIL block for the Controller subsystem as explained in Test Generated Code with SIL and PIL Simulations (Embedded Coder).
4. Place the PIL block created in the model as shown by the comments in the model.
5. Run the PIL simulation as explained in Test Generated Code with SIL and PIL Simulations (Embedded Coder).
6. 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 c2000_model_pil_block 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.
Note: If you choose to select a different TI C2000 processors other than the default configured model, ensure you set the Total number of instances allowed per top model to Multiple under Configuration parameters > Model Referencing > Options for referencing this model.
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 as explained in Test Generated Code with SIL and PIL Simulations (Embedded Coder).
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 c2000_top_model_pil model. This model is configured for the TI Piccolo F2806x target.
Note: If you choose to select a different TI C2000 processors other than default configured model, ensure you set the Total number of instances allowed per top model to Multiple under Configuration parameters > Model Referencing > Options for referencing this model.
2. Choose a PIL serial communication interface by following the steps in Task 1 above.
3. Run the top model PIL simulation as explained in Test Generated Code with SIL and PIL Simulations (Embedded Coder).
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.