MATLAB Examples

Code Verification and Validation with PIL and External Mode

This example shows you how to use Embedded Coder™ Support Package for ARM Cortex-A® Processors for code verification and validation using PIL and External Mode.

Contents

Introduction

In this example you will learn how to configure a Simulink model to run Processor-In-the-Loop (PIL) and External Mode simulations. In a PIL simulation, the generated code runs on a Zynq hardware. 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 ensure that the behavior of the deployment code matches the design.

Simulink's External mode feature enables you to accelerate the process of parameter tuning by letting you change certain parameter values while the model is running on target hardware, without stopping the model. When you change parameter values from within Simulink, the modified parameter values are communicated to the target hardware immediately. The effects of the parameters tuning activity may be monitored by viewing algorithm signals on scopes or displays in Simulink.

This example introduces the Simulink code generation and verification workflow by showing you how to:

  • Configure a Simulink model to run PIL simulations on the Zynq hardware
  • Configure a Simulink model to run External Mode simulation Zynq hardware

Prerequisites

Required Software

This example requires one of the following Xilinx Software:

  • Xilinx ISE® Design: Suite Embedded Edition (version 14.4 or later)
  • Xilinx Software Development Kit (version 2013.4 or later)

Required Hardware

This example requires one of the following boards:

  • Xilinx Zynq ZC702 Evaluation Kit
  • Xilinx Zynq ZC706 Evaluation Kit
  • ZedBoard

Task 1 - Verify generated code using PIL block

This example shows how the automatically generated PIL block can be used for verification. 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 an automatically generated PIL block; you should be careful 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 Xilinx Zynq ZC702 evaluation kit. But you can choose any of the supported Zynq hardware. The objective here is to create a PIL block out of the Controller subsystem running on the Zynq hardware.

2. Enable PIL feature by following the steps below:

3. Create a PIL block for the Controller subsystem by following the steps below:

4. Run PIL simulation:

5. Once you start simulating the model, the PIL executable starts running on the Zynq hardware. You can switch between the original and PIL block subsystems by double clicking on the Manual Switch block. Double click on the Numerical Differences block to see the difference between the simulated Controller subsystem and the PIL block running on the Zynq hardware.

Task 2 - Verify generated code using PIL Simulation for Model Blocks

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

  • You can verify code generated for referenced models
  • You must provide a test harness model to provide test vector or stimulus inputs
  • You can easily switch a Model block between normal and PIL simulation mode

1. Open Model Block PIL model. This model is configured for Xilinx Zynq ZC702 evaluation kit. The model contains two Model blocks; both point to 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. Configure and run CounterA Model block in PIL simulation mode by following the steps below:

3. When model starts running, Scope1 displays the PIL simulation output running on the Zynq hardware while Scope2 shows the normal mode simulation output.

Task 3 - Verify generated code using PIL simulation for top models

This example shows how you can verify the automatically generated code for a top model by running a PIL simulation. 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 easily switch the entire model between normal and PIL simulation mode

1. Open the Top Model PIL model. This model is configured for Xilinx Zynq ZC702 evaluation kit target. You will run the model PIL simulation mode.

2. Run the entire model in PIL simulation mode by following the steps below:

3. 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

Task 4 - External Mode

In this task, you will run a Simulink model in External simulation mode. When you are prototyping and developing an algorithm, it is useful to monitor and tune the algorithm while it runs on hardware. The External mode feature in Simulink enables this capability.

1. Open the External Mode model. This model is configured for Xilinx Zynq ZC702 evaluation kit. You will run the model in External simulation mode.

2. Configure the model for External mode simulation:

In this step, the simulation stop time is set to 'inf' to run the simulation until you explicitly pause or stop the model.

3. Start the External mode simulation:

Wait for the model to finish getting built and downloaded onto the target. Once this is done, the External mode simulation will begin. Double click the Manual Switch block while simulation is running to change the input source. Double click on the Gain block to change the signal gain. Finally, double click on the Scope block to view the External mode simulation results. Note that the entire model is running on the Zynq hardware.

3. Stop External mode simulation:

Please note: At any point during the course of the External mode simulation, you can open the External Mode Control Panel, using the following instructions:

Summary

This example introduced the workflow for code verification using target connectivity features PIL and External Mode.