You are on page 1of 10

ECE 893 Industrial Applications of Nonlinear Control Spring 2013

This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

1 Updated 01/13/2013

Setting up and using xPC Target

xPC Target is used as part of the real-time control system for the projects in ECE 893. In real-time control systems,
the act of reading sensors, generating feedback, and changing the corresponding control input is guaranteed within
a set response time.
MATLAB Simulink is used to create a model of the control system and modify various settings and parameters to
improve system performance. Simulink compiles your model and downloads it onto the xPC Target workstation. xPC
Target is a real-time software environment from MathWorks which runs on a separate workstation. xPC runs the
real-time model, which ships data back to the your laptop while reading inputs and issuing commands with the Q4
Data Acquisition boards.
xPC installation is a one-time process, after which you will have the freedom to work on simulation and control
design on your laptop while using the desktop to test hardware implementation.




1. Laptop Software Installation (once)

The following MATLAB/Visual C++ combination is approved for Windows only:
Windows XP, Vista, or Windows 7
o We HIGHLY recommend running windows on a PC laptop or using the Boot Camp partition on an
Apple laptop.
Having an approved config will make the install of the following software packages and the
setup of xPC Target communication go much smoother.

The ECE893 class requires xPC Target to be run using Matlab 2012a and Visual Studio C++ 2010 Pro. If your
computer doesnt have these software packages, install these before proceeding, use the instructions below:
MATLAB R2012a 32-bit ( I would recommend plugging into Clemson Ethernet )
o Log into Novell and on the Software drive, go to Matlab_Student, and copy the Win folder to
your desktop (~4.5 Gb, takes about 15 minutes) \\software.clemson.edu\Matlab_student\Win\
While youre copying files over, open up the Installation Instruction for Matlab
Student.pdf document that can be found in the Matlab_Student\Documentation folder
Target: Workstation PC Host: Laptop
ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

2 Updated 01/13/2013
Once the file is copied, open up the folder (\Win\bin\Win32) and double click
setup.exe
Follow the Installation Instructions pdf
o The installer will warn you about installing a 32 bit program on a 64 bit
machine, but just press ok
It is best not to change the Windows User Name that Matlab uses to activate
your acct, as long as its your name, it may come from your Matlab username.
There are some issues when trying to change it.
Microsoft Visual Studio 2010 Pro
o Note: The TAs have a few copies of this program on DVD if you want to borrow a copy
o As a Clemson student, you may download a free copy from Microsoft:
https://www.dreamspark.com
If you dont have a DreamSpark acct, you will have to create one and then verify it
through Clemson University
Once you have been verified, download Visual Studio C++ 2010 Pro
It will ask you to download a Download Manager and wait for it to download (should
take 15-20 mins)
Once the download is complete, clicking Launch is going to open up the iso
burner on your computer, requiring you to burn a DVD, from which you can
install the program
When running the installer, choose a custom install and uncheck the last 4
lines, those programs on not required for our compiler


2. Laptop Compiler Setup (once)

Start MATLAB.
To select the C++ compiler, in the MATLAB command window, type mex setup.
Allow MATLAB to find available compilers on your laptop. Select the installed Visual C++ compiler, for example:
Microsoft Visual C++ 2010
Then verify your choice
NOTE: In the MATLAB command window, type xpcexplr to open the xPC Target Explorer. In the left panel, under
Host PC Root > Compiler Configuration, make sure VisualC is selected as the compiler and the path (ex.
C:\Program Files\Microsoft Visual Studio 10.0) points to your preferred C++ compiler (selected during mex setup).




ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

3 Updated 01/13/2013
3. Creating Matlab R2012a xPC Boot Disc
Bring up xPC Explorer, under xPC Target Hierarchy you will see TargetPC1 (if no target is present go to
File>Add Target). Expand the + and under Configuration > Communication, to the right will a window
labeled Target PC1 Communication Component at the top. Set the drop-down menus to the following
options (all other options should be grayed out):
Host target communication TCP/IP
Target PC TCP/IP address 10.0.1.2
TCP/IP target driver Auto
TCP/IP target port 22222
TCP/IP target bus PCI
LAN subset mask address 255.255.255.0
TCP/IP gateway address 255.255.255.255

Once this is done, go to TargetPC1 > Configuration > CD Boot tab, select an appropriate location
(i.e.Desktop, it doesnt really matter) and click on the Create CD Boot Image button. At this point, Matlab
may ask you to insert a blank CD into your drive to burn the boot disk immediately. Label the disc Matlab
R2012a Boot Disc, xPC Target 5.2.
(If there is no pop up from Matlab to burn a boot disc, use your software of choice to burn the cdboot.iso
image (not just the file) to a blank CD-R)



4. Workstation Setup

The following steps have already been completed on each workstation. Please do not alter the setup in any manner.
Installation of the Q4 Card.
Installation of xPC compatible Ethernet card.
Internal Network Interface Card (NIC) disabled (if another Ethernet card installed).
Boot sequence changed with CD ROM priority




ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

4 Updated 01/13/2013
5. Laptop Network Setup (each time, or once if you only use wireless to access the internet)

Using xPC requires changing IP addresses on your laptop LAN.
NOTE: Your laptop firewall may block an attempted change in the IP address. If the following network setup fails,
try the same steps again with the firewall turned off. Windows Firewall is turned ON by default, so your laptop
could have a firewall running even if you havent installed third party firewall software.
Connect the Ethernet cable to workstation and laptop ports. Do not use any Ethernet ports covered with tape, these
have intentionally been blocked.
Insert the boot disc created in section 3 and power-on the workstation. If the workstation does not find a boot
device, see Note below.
NOTE: The workstation must be booted using a copy of the xPC target disk. Once the system is booted, the disk
can be removed. Only use Matlab R2012a xPC Target 5.2 disks.
Configure Laptop LAN
Go to Control Panel > Network and Internet > Network and Sharing Center > Manage network
connections (for Vista) or Change adapter settings (Windows 7).
Select Local Area Connection > Properties.
Go to TCP/IP v4 Properties.
Select Use the following IP address and click Advanced without filling in the details.
Set IP address to 10.0.1.1 [Add if it doesnt exist]
Set the subnet to 255.255.255.0
Test the connection by pinging 10.0.1.2 using Windows Command Prompt. After a few bytes are successfully sent,
the ping operation automatically terminates. The ping command is typed as follows:
ping 10.0.1.2 <Enter>
If you see a message such as Request timed Out or Destination host unreachable, either the cable has not been
properly connected (look for illuminated Green LED lights, indicating a link) or the network setup has not been done
correctly.
NOTE: For laptops running virtual machines (Virtual Box for instance), create a 2
nd
lan connection in the Network
Connections of the virtual machine and set that to Bridge configuration, you will configure the IP settings as
directed above. For Parallels on Mac, leave the settings in Windows alone (Shared config) and instead change the
Ethernet connection as directed above (these have been most common solutions to communication problems with
virtual machines)

NOTE: To return to using the Ethernet port to connect to the internet, you will need to check the Obtain IP
address automatically option. You may leave the Ethernet port configured as above if you connect to the internet
using Wireless.
ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

5 Updated 01/13/2013
6. Laptop xPC Target Setup

In the MATLAB command window, type xpcexplr to open the xPC Target Explorer, if not already open.
To add the workstation as a target, go to File > Add Target (if not done in section 3).
Under TargetPC1 > Configuration > Communication, make the following changes (if not reflected from section 3,
when creating the boot disc):
Select TCP/IP as the communication protocol.
Set the Target TCP/IP address to 10.0.1.2
Set the LAN Subnet Mask to 255.255.255.0

Select Apply.
Go to Target > Connect to Target to connect. Successful connection is confirmed by checking TargetPC1. The
Connected status should be Yes.
NOTE: The next time you connect, only the previous step should be followed. Setup does not need to be repeated.


7. Testing Configuration with the Analog Loopback Simulation Setup

To confirm the success of this entire installation process, the analog loopback test is required.
This test involves sending out a signal from an Analog Output port on the Q4 and reading the same signal using an
Analog Input port. This ensures that the model built and downloaded to the target machine correctly as well as
showing the user some of the settings required to control how signals are sent out/read in by manipulating the
settings in the Quanser Simulink blocks.
A test model analogLoopback.mdl has been created and posted at the course website for your reference.
Download this model by right-clicking on the Simulink MDL for loopback link and save link as and save it into
its own folder (explained later). Navigate to that folder inside Matlab, making that your current folder.
Double clicking the analogLoopback.mdl file will open it up in Simulink. Going from left to right in the model
window, a sine wave block will output to the Q4 Analog Output. The signal will also be displayed on a Target Scope
which will appear on the monitor of the Target machine. The Q4 Analog Output block sends the Sine wave through
an analog output on the Q4 board. A Q4 Analog Input block will tell the Q4 which port to read the sine wave and a
Host Scope block allows the user to display that signal (brought up through xPC Target Explorer). A wire with RCA
audio plugs on both ends is externally connected to the Q4 Analog Output port and Analog Input port to loop the
signal between the different ports on the Q4.
ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

6 Updated 01/13/2013
All blocks from this model are from the Simulink library. It is available at both the MATLAB command prompt (type:
Simulink) and in the Simulink model window. The library can be accessed using its icon in the
analogLoopback.mdl window.
Take a couple minutes to open up the Simulink Library and look over the various blocks (found Libraries>xPC Target,
see following figure) related to functions on the Q4 board that can be inserted into the model from the xPC folder.
For example, the Analog Input block found in the analogLoopback.mdl is located at xPC Target > A/D > Quanser >
Q4 A/D.


NOTE: Scopes to be used in simulations need to be added from xPC target, through Library > xPC Target > Misc >
Scope (xPC). A Host Scope displays data on the laptop screen, while a Target Scope is used for displaying on the
workstation screen. Scope type can be selected by double-clicking the Scope block in your model.



ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

7 Updated 01/13/2013

Laptop Simulation Configuration

To familiarize you with some of the simulation settings, go to the analogLoopback.mdl and at the top, select
Simulation > External to set the timing source of the simulation. This step is necessary to get real-time
performance.
Go to Simulation > Configuration Parameters for the next few settings.
Set the stop time of your model to infinity (does not stop by itself, requires user input to stop). This is done
by clicking Solver then setting Simulation time > Stop time to inf.
Set Solver options to Fixed Step. Do this by clicking Solver then selecting Fixed Step in Solver options >
Type. Set step size to 0.001.
Click on Code Generation then Target selection > System target file, select xpctarget.tlc. Ensure the
description of target file is xPC Target.
NOTE: To avoid simulation setup for each new simulation, use the analog loopback as a template for new
simulations. If that is done, each new simulation will only need modifications in the type of blocks inserted in the
model. Configuration parameters as set in this section remain unchanged.

Get to know the Quanser Q4

The Quanser Q4 data acquisition card allows the user to read and generate signals with a computer through the use
of a PCI card and breakout board. There are Analog In, Analog Out, Digital Out, and Encoder ports. The user guide is
located here: http://www.clemson.edu/ces/crb/ece495/References/manuals/quanser_q4_manual.pdf.
Q4 Channels labeled on the terminal board start with 0 as the first index. However, xPC starts indices from 1
(Matlab does not start array indices with 0). Take note of this to avoid confusion when checking the channel vectors
in the blocks in your model and comparing with hardware setup.
NOTE: Channel vector [1] corresponds to Channel 0 on the board, [2] to Channel 1 and so on.
ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

8 Updated 01/13/2013

ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

9 Updated 01/13/2013
Running the Simulation

This section is a guide to building the analogLoopback.mdl and uploading it onto the xPC Target machine.
Check your config first:
If the target has to be booted, make sure the correct xPC target disk is inserted.
Ensure that a crossover Ethernet cable is connected to the target and host.
Ensure the network settings on your laptop are set up correctly.
To start the simulation from Simulink, open your model file and you can open xPC Target Explorer using Tools >
Code Generation > xPC Target Explorer (or type xpcexplr from MATLAB command line).
To start it from xPC Target Explorer, go to Target > Connect to Target.
Make sure your current folder for Matlab has the analogLoopback.mdl in it, go to the Simulink model window with
the model that you wish to build and build/upload the simulation using Tools > Code Generation > Build Model in the
simulation window. Build steps are displayed in the MATLAB command window. If you receive an error in compiling,
most likely the Compiler path is incorrect (go to section 2 for instructions on how to set the correct path for the C++
compiler)
The simulation can be started through xPC Target Explorer, go to the top row of buttons and press the Play button.
If the scope in your model is a Target Scope (the scope set up in the analogLoopback.mdl) then the plot will appear
on the screen.
Some model settings, such as constant values, amplitudes and gains, can be changed from the xPC Target
Explorer. In addition to that, the settings for the scope may need to be changed to see a greater range of the
displayed signal (do this by double clicking on Target Scope to adjust its settings). Note: the Host scope has less
customization options than the Target Scope.
ECE 893 Industrial Applications of Nonlinear Control Spring 2013
This is a modified copy of the document created by Matthew Pepper and Ninad Piradhan for ECE 495.

10 Updated 01/13/2013


The xPC Explorer interface is shown above. Some notes on using the Explorer:
Set the scope Display Mode to Rolling to see a continuous display of the signal.
Set the scope Y axis limits so that the signal fits into the plot.
Experiment with the number of samples and Decimation to see how display properties change.
Remember to Update Parameter or Apply changes when a change is made.
Try using a Host Scope instead of a Target Scope.


NOTE: The simulation needs to be built each time you Stop the model and make changes to it. Unless the model is
built after modifications, those modifications are not applied to it during runtime. However, changes made inside
the xPC Explorer do not require a rebuild.