Using the xPC Target
The MATLAB toolbox xPC Target  provides a real-time rapid-prototyping tool on a Host-Target environment in conjunction with MATLAB and other
Output of the model in Figure 5.2 on an oscilloscope.
toolboxes to model and design real-time control systems and implement in a hardware-in-loop (HIL) simulation. The general arrangement is shown in Figure 5.4.
The Target is the system in which the embedded application runs. This usually contains a bootable image of the xPC Target kernel or must be booted with one before connectivity with the host is established. The host is a standard microcomputer, that is, a desktop, laptop or a workstation with an OS like windows or Linux on which MATLAB runs.
The xPC Target module on the host acts as an integrated development environment (IDE) to develop embedded applications that run on the target.
xPC Host-Target system.
The xPC Target module.
The embedded application can be developed using Simulink and other blocks that are listed in the xPC Target module, as shown in Figure 5.5.
A guide to hardware supported by the xPC Target utility can be found online . In general, the IDE supports Intel, AMD, and other x86 compatible platforms and includes drivers for a wide variety of PC-compatible peripherals. The compiler is usually a visual C++. The host computer is configured for developing and downloading target applications using the xpcexplr utility. The utility is selected by using the command xpcexplr at the MATLAB prompt, which opens the window shown in Figure 5.6.
The essential steps in configuring the host system for downloading an application are as follows:
1. Setting up the C compiler—The easiest way to do this is by clicking on the compiler configuration tab and then the tabs on the window shown in Figure 5.7.
If Visual C++ is already installed, the compiler path needs to be set for the xPC Target to be able to build executable applications.
2. Configuring Target and Target Interface—This tells the IDE about the target hardware and the communication interface. The targets can be added using the toolbar on the xpcexplr window. In case multiple targets are present, the default can be set by a right-click on the Target name. Targets can also be renamed in the same way. The targets are configured by selecting the appropriate properties, for
Configuring the host using xpcexplr.
Setting up the compiler path on xPC Host.
Configuring Target interface on xPC Host.
example, Communications, which is selected for TargetPCl (default nomenclature) as shown in Figure 5.8.
As shown in Figure 5.8, the xPC Host is set up to communicate with the TargetPC1 through a TCP/IP interface, with options for network interface and the properties relevant for TCP/IP as shown in the window. The specification for the network interface is required so that the appropriate driver is bundled with the application. The IDE selects the default target for downloading the application identified through the IP address.
Once the application is downloaded on a target, the target has to be selected by left-click and then connected to the host using the Target > Connect to Target option on the toolbar of the xPC Target Explorer window. The application is started by clicking on the play button.
Figure 5.9 shows xPC implementation of a Target Send-Receive, which sends a sine wave over a UDP/IP interface to the Target Reflector (Figure 5.10), and the sent and received sine waves captured on the Target Scope of the Send-Receive module is reproduced in Figure 5.11 using the xpctargetspy utility. A detailed description of the usage of the xPC blocks used in the models of Figures 5.9 and 5.10 as well as the xpctargetspy is available in a guidebook .
As seen in Figure 5.10, the Reflector sends back the transmitted sine wave to the Send-Receive module and there is a minimum time delay, which equals one sample time between the transmitted and the received signals seen by the Send-Receive module that causes a small phase lag in the received (or reflected) sine wave. The initial distortion in the reflected wave is due to the
xPC Target implementation of a real-time Send-Receive module.
substantial data loss caused by the traffic generated by the refresh option by the host computer, which is then disabled using the Disable Refresh option by clicking on the Tools tab on the xpcexplr pane, thus reducing the data loss in the reflected wave.
It is important to note that building xPC Targets requires proper choice of the Target Language Compiler and a fixed step size. While choice of compilers allows various level of optimizations, the simple choice is xpctarget.tlc, which is selectable using the configuration option from the simulation tab
xPC Target implementation of a real-time Reflector module.
(See color insert.) The transmitted and received sine waves on the Send-Receive module.
in the pane of the Simulink model. Using the build or the incremental build option in the configuration pane builds the Target and downloads it on the default target selected through xpcexplr.