XPC Target Getting Started Guide PDF
XPC Target Getting Started Guide PDF
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
www.mathworks.com/contact_TS.html Technical Support
508-647-7000 (Phone)
508-647-7001 (Fax)
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
November 2000 First printing New for Version 1 (Release 12)
June 2001 Online only Revised for Version 1.2 (Release 12.1)
September 2001 Online only Revised for Version 1.3 (Release 12.1+)
July 2002 Second printing Revised for Version 2 (Release 13)
September 2003 Online only Revised for Version 2.0.1 (Release 13SP1)
June 2004 Third printing Revised for Version 2.5 (Release 14)
August 2004 Online only Revised for Version 2.6 (Release 14+)
October 2004 Fourth printing Revised for Version 2.6.1 (Release 14SP1)
November 2004 Online only Revised for Version 2.7 (Release 14SP1+)
March 2005 Online only Revised for Version 2.7.2 (Release 14SP2)
September 2005 Online only Revised for Version 2.8 (Release 14SP3)
March 2006 Online only Revised for Version 2.9 (Release 2006a)
May 2006 Fifth printing Revised for Version 3.0 (Release 2006a+)
September 2006 Online only Revised for Version 3.1 (Release 2006b)
March 2007 Online only Revised for Version 3.2 (Release 2007a)
September 2007 Online only Revised for Version 3.3 (Release 2007b)
March 2008 Online only Revised for Version 3.4 (Release 2008a)
October 2008 Sixth printing Revised for Version 4.0 (Release 2008b)
March 2009 Online only Revised for Version 4.1 (Release 2009a)
September 2009 Online only Revised for Version 4.2 (Release 2009b)
March 2010 Online only Revised for Version 4.3 (Release 2010a)
September 2010 Seventh printing Revised for Version 4.4 (Release 2010b)
Contents
Introduction
1
Product Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
v
Web Browser Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Custom GUI with xPC Target API for Microsoft .NET
Framework . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-33
Custom GUI with xPC Target API . . . . . . . . . . . . . . . . . . . . 1-34
Custom GUI with xPC Target COM API . . . . . . . . . . . . . . . 1-34
vi Contents
Network Communication Overview . . . . . . . . . . . . . . . . . . 2-25
Hardware for Network Communication . . . . . . . . . . . . . . . 2-25
Ethernet Card Provided with the xPC Target Product . . . . 2-26
Ethernet Card for a PCI Bus . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Ethernet Card for an ISA Bus . . . . . . . . . . . . . . . . . . . . . . . 2-28
Environment Properties for Network Communication . . . . 2-30
Basic Tutorial
3
Simulink Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Creating a Simple Simulink Model . . . . . . . . . . . . . . . . . . . 3-2
Entering Parameters for the Scope Block . . . . . . . . . . . . . . 3-6
Adding a Simulink Outport Block . . . . . . . . . . . . . . . . . . . . 3-10
Entering Parameters for the Outport Blocks . . . . . . . . . . . 3-13
Adding an xPC Target Scope Block . . . . . . . . . . . . . . . . . . . 3-17
Entering Parameters for an xPC Target Scope Block . . . . . 3-21
vii
Simulating the Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Simulating the Model with Simulink . . . . . . . . . . . . . . . . . . 3-37
Simulating the Model from MATLAB . . . . . . . . . . . . . . . . . 3-39
Glossary
Index
viii Contents
1
Introduction
Product Overview
The xPC Target™ product is a solution for rapid control prototyping,
hardware-in-the-loop (HIL), testing, and deploying real-time systems using
standard PC hardware. It is an environment that uses a target PC, separate
from a host PC, for running real-time applications. The xPC Target software
environment includes many features to help you prototype, test, and deploy
real-time systems.
1-2
Product Overview
For additional information on using the xPC Target product, see the following
MathWorks Web site resources:
1-3
1 Introduction
Expected Background
Users who read this book should be familiar with
When using the Real-Time Workshop and xPC Target products, you do not
need to program in C or other programming languages to create, test, and
deploy real-time systems.
If you are an experienced user — After you are familiar with using the xPC
Target software, read or browse the following chapters in the xPC Target
User’s Guide: “Software Environment and Demos” and “Targets and Scopes in
the MATLAB Interface” for more detailed information about the commands
in the xPC Target software.
1-4
xPC Target™ Features
Real-Time Kernel
The xPC Target software does not require Microsoft DOS, Microsoft
Windows®, Linux®, or any another operating system on the target PC. Instead,
you boot the target PC with boot media that includes the xPC Target kernel.
However, the xPC Target Embedded Option product requires DOS and a
DOS license at boot time. For more information, see “Embedded Option” in
the xPC Target User’s Guide.
1-5
1 Introduction
Target PC BIOS
At the beginning of the target PC boot process, the BIOS is loaded. Among
other tasks, the BIOS searches for a bootable image (executable). This
bootable image includes 16-bit and 32-bit tasks. The 16-bit task runs first
because the CPU is in real mode by default. It prepares the descriptor tables
and switches the CPU to protected mode. Next, the 32-bit task runs. It
prepares the target PC environment for running the kernel and finally starts
the real-time kernel.
You might need to enter the BIOS to customize settings for optimal real-time
behavior of the system. For example, you can suppress checking for a
keyboard or switch off any power save features. Enabled power features and
legacy USB support can generate system management interrupts (SMIs).
These features and support can also degrade real-time performance.
After loading the kernel, the target PC does not make calls to the BIOS or DOS
functions. The resources on the CPU motherboard (for example, interrupt
controller, UART, and counters) are addressed entirely through I/O addresses.
Real-Time Kernel
After the kernel starts running, it displays a welcome message with
information confirming the host-target connection. The kernel activates
the application loader and waits to download a target application from the
host PC. Upon download, the loader receives the code, copies the different
code sections to their designated addresses, and sets the target application
ready to start. You can now use xPC Target functions and other utilities to
communicate with the target application.
It is important to note that after the CPU switches to protected mode (32-bit),
none of the xPC Target components switches the CPU back to real mode
(16-bit).
1-6
xPC Target™ Features
The generated real-time application and the real-time kernel are compiled
with a flat memory model. This provides full 32-bit power without
time-consuming 16-bit segment switching and Microsoft DOS extenders.
1-7
1 Introduction
Real-Time Application
The Real-Time Workshop, Real-Time Workshop Embedded Coder, Stateflow
Coder, and xPC Target products, and a C compiler, create a real-time
application (target application) from a Simulink and Stateflow model. Target
applications created with the Real-Time Workshop and xPC Target software
run in real time on a standard PC using an xPC Target real-time kernel.
The target application runs in real time on the target PC and has the
following characteristics:
Signal Acquisition
The xPC Target real-time kernel stores signal data from the target application
in RAM on the target PC. Alternatively, you can have the xPC Target
real-time kernel store signal data in a file on the target PC. In either case,
you can use this signal data to analyze and visualize signals. The xPC Target
product supports the following types of signal acquisition:
1-8
xPC Target™ Features
• Signal logging — This is the process of acquiring signal data while a target
application is running, and then visualizing the collected data after the
target application stops running. The data is collected in the real-time task
and acquired samples are associated with a time stamp. After the run
finishes or you manually stop the run, the host PC makes a request to
upload data from the target PC. You can then visualize signals by plotting
data on the host PC, or you can save data to a disk.
• Signal tracing — This is the process of acquiring and visualizing signal
data while a target application is running. The data is collected in the
real-time task and acquired samples are associated with a time stamp. It
allows you to acquire signal data and visualize it on the target PC or to
upload the signal data and visualize it on the host PC while the target
application is running. The flexibility of this acquisition type is very similar
to the behavior of a digital oscilloscope.
For information on acquiring signal data with the xPC Target software, see
“User Interaction” on page 1-27 in the xPC Target™ Getting Started Guide on
page 1 and “Signal Monitoring with the MATLAB Interface”, “Signal Logging”
and “Signal Tracing” in the xPC Target User’s Guide documentation.
Parameter Tuning
Most Simulink blocks have parameters (such as the amplitude and frequency
of a sine wave) that you can change before or while your target application is
running:
Note Opening a dialog box for a source block causes Simulink to pause.
While Simulink is paused, you can edit the parameter values. You must
close the dialog box to have the changes take effect and allow Simulink
to continue.
• Scripts and batch procedures — The xPC Target software also includes
commands to change parameters during a run or between runs. By writing
a script that incrementally changes a parameter and monitors a signal
1-9
1 Introduction
output and running it on the host PC, you can optimize the value of that
parameter.
1-10
xPC Target™ Features
Fixed-Point Support
The xPC Target software supports Simulink fixed-point data. This enables
you to
For more information on using fixed-point data, see the “Simulink Fixed
Point”.
To use these features, create a file that uses the MATLAB Compiler
command-line interface for the xPC Target software (for example, then use
the MATLAB Compiler).
1-11
1 Introduction
Note Your model accesses this library if you build your model with a
Microsoft Visual C/C++ compiler. If you build your model with the Open
Watcom compiler, the xPC Target software does not use the BLAS library.
1-12
Hardware Environment
Hardware Environment
In this section...
“Introduction” on page 1-13
“Host PC” on page 1-13
“Target PC” on page 1-14
“Host-Target Connection” on page 1-15
“I/O Driver Support” on page 1-17
Introduction
The hardware environment consists of a host computer, target computer, I/O
boards in the target computer, and a serial or network connection between
the host and target computers. Knowing the different types of computers and
I/O supported by the xPC Target software will help you to set up a real-time
testing environment that meets your needs.
For a complete, fully assembled, real-time testing solution, see xPC Target
Turnkey. xPC Target Turnkey combines the xPC Target software with a
variety of high-performance real-time target computers.
Host PC
You can use any PC that runs a Windows operating system supported by
MathWorks as the host PC. It must also contain an available serial port or
Ethernet adapter. In addition, to provide a means to boot the target PC, the
host PC must have at least:
• A CD or DVD drive
• The ability to belong to a dedicated network
• A 3.5–inch floppy disk drive
For more details on the requirements of the host PC, see “Host PC
Requirements” on page 2-8.
1-13
1 Introduction
Target PC
The xPC Target software supports concurrent access to up to 64 target PCs
with one host. A target PC can be almost any PC compatible system with a
32-bit Intel® or AMD® processor (386 compatible or higher). It must also
contain a free serial port or an Ethernet adapter. In addition, the target PC
must contain a 3.5–inch floppy disk drive, CD or DVD drive, or have the
ability to belong to a dedicated network. Using the xPC Target Embedded
Option software, you can transfer files from the 3.5-inch disk or CD to a hard
disk or flash memory. Do not use a laptop PC as a target PC.
You do not need any special target hardware. However, the target PC must
be a fully PC-compatible system and contain a serial port or an Ethernet
controller compatible with the xPC Target software.
For more details on the requirements of the target PC, see “Target PC
Requirements” on page 2-10.
1-14
Hardware Environment
Host-Target Connection
The xPC Target product supports two connection types and communication
protocols between the host PC and the target PC: serial and network.
Serial — The host and target computers are connected directly with a serial
cable using their RS-232 ports. This cable is wired as a null modem link that
can be up to 5 meters long and with a transfer rate between 1200 and 115200
baud. A null modem cable is provided with the xPC Target software.
Serial Serial
port port
For detailed information on setting up the hardware and software for serial
communication, see “Serial Communication” on page 2-37.
1-15
1 Introduction
When using a network connection, the target PC can use the Ethernet adapter
card provided with the xPC Target product or one of the supported cards.
The data transfer rate can be 10 megabits/second, 100 megabits/second, or
1 gigabit/second. For a list of supported cards, see “Hardware for Network
Communication” on page 2-25.
Host PC Target PC
network network
card card
TCP/IP
network connection
For detailed information on setting up the hardware and software for network
communication, see “Network Communication” on page 2-25.
This manual does not include information for installing network cards or
the TCP/IP protocol on your host computer. For correct installation and
setup of your network cards and the TCP/IP protocol, contact your system
administrator.
1-16
Hardware Environment
Note You are responsible for taking necessary precautions and implementing
safeguards when interfacing hardware with the xPC Target product. You
are also solely responsible for the content of your models that controls such
hardware.
I/O board library — The I/O board library contains Simulink blocks for the
xPC Target product. You drag and drop blocks from the I/O library and
connect I/O drivers to your model the same way you would connect any
standard Simulink block.
I/O support — The I/O device library supports approximately 300 standard
boards. I/O boards plug into the target PC expansion bus, PC/104 stack, or
industrial PC chassis. There is also support for modules that plug into IP or
PMC carrier boards. The xPC Target block library supports the following
I/O functions:
• Analog input (A/D) and analog output (D/A) — Connect sensors and
actuators to your target application.
• Digital input and output — Connect to switches, on/off devices, and
communicate information in parallel.
• RS-232/422/485 support — Use the COM1 or COM2 ports for serial
communication with external devices. You can also access multiple RS-232,
RS-422, and RS-485 serial ports using Quatech® and Commtech devices.
See “Serial Communications Support” in the xPC Target I/O Reference.
• CAN support — You can use CAN-AC2, CAN-AC2-PCI, and CAN-AC2-104
boards from Softing® GmbH AG with xPC Target CAN blocks to interface
with a CAN field bus network. This interface provides communication
through a CAN network between target applications and remote sensors
and actuators.
1-17
1 Introduction
The xPC Target CAN blocks are compatible with CAN specifications 2.0A
and 2.0B and use dynamic object mode. See “CAN I/O Support” and “CAN
I/O Support for FIFO” in the xPC Target I/O Reference.
• GPIB support — Special RS-232 drivers support communication with a
GPIB control module from National Instruments® to external devices with
a GPIB connector. See “GPIB I/O Support” in the xPC Target I/O Reference.
• UDP support — Communicate with another system using the standard
UDP/IP network protocol. See “UDP I/O Support” in the xPC Target I/O
Reference.
• Counter-Timers — Use the counter-timer blocks for measuring pulse and
frequency with modulation applications.
• Watchdog — Monitor an interrupt or memory location, and reset the
computer if an application does not respond. See “Access” and “Versalogic”
in the xPC Target I/O Reference.
• Incremental encoder — Change motion into numerical information for
determining position, direction of rotation, and velocity.
• Shared memory — Use shared memory blocks with multiprocessing
applications.
• LVDT — Use the North Atlantic Industries, Inc. 73LD3, 76CL1, 76LD1,
and 76CL1 boards with xPC Target LVDT blocks to work with LVDT
applications.
• ARINC-429 — Use the Condor Engineering CEI-X20 boards with xPC
Target ARINC-429 blocks to interface with the ARINC 429 data bus.
• MIL-STD-1553 — Use the Condor Engineering PCI-1553 and QPCI-1553
series boards with xPC Target MIL-STD-1553 blocks to interface with the
MIL-STD-1553 data bus.
• Audio — Use the audio blocks to work with audio applications. See General
Standards PMC66-16AO16 and General Standards PMC-24DSI12 in the
xPC Target I/O Reference.
• Thermocouple — Use the Measurement Computing™ PCI-DAS-TC
board with xPC Target thermocouple blocks to work with thermocouple
applications.
1-18
Hardware Environment
For information on using specific I/O driver blocks and advanced I/O support,
see the xPC Target I/O Reference.
1-19
1 Introduction
Software Environment
In this section...
“Introduction” on page 1-20
“Host-Target Communication” on page 1-20
“Rapid Prototyping Process” on page 1-21
“Hardware-in-the-Loop Process” on page 1-24
“The xPC Target Embedded Option Product” on page 1-24
Introduction
The software environment is a place to design, build, and test a target
application in nonreal time and real time. It also includes communication
between the host and target computers.
Host-Target Communication
Whether using a serial connection (RS-232) or a network connection
(TCP/IP), information is exchanged between the host PC and target PC. This
information includes
1-20
Software Environment
• xPC Target
• Simulink
• Real-Time Workshop
• A C compiler
And connect the host PC to the target PC via a single TCP/IP or RS-232
connection. You then:
1-21
1 Introduction
Note Opening a dialog box for a source block causes Simulink to pause. While
Simulink is paused, you can edit the parameter values. You must close the
dialog box to have the changes take effect and allow Simulink to continue.
5 Execute the target application in real time — The target PC is booted using
an xPC Target boot image that loads the xPC Target real-time kernel. After
booting the target PC, you can build and download a real-time application.
1-22
Software Environment
You can create xPC Target scopes and acquire data from the target
application by
• xPC Target — Use the xPC Target Remote Control Tool and Scope
Manager windows to create scopes, and use the Simulink viewer to add
signals.
• MATLAB — Enter commands in the MATLAB Command Window.
• Simulink — Add xPC Target Scope blocks to your Simulink model.
Note xPC Target software does not support normal Simulink Scope
blocks in external mode. Instead, use xPC Target Scope blocks.
• xPC Target GUI — Use the xPC Target Remote Control Tool and
Simulink viewer to change parameters.
• MATLAB interface — Enter commands in the MATLAB window.
1-23
1 Introduction
Hardware-in-the-Loop Process
Hardware-in-the-loop (HIL) simulation lets you test the implementation of
your embedded system, such as a control system, in real time using test
benches and simulations from your design phase. HIL simulation is especially
valuable when:
Using your system-level model, which consists of the embedded control system
and the plant model, you can reuse your plant model, which executes in the
Simulink environment, and use the Real-Time Workshop software to run
these models on real-time testing equipment. By automatically generating
code from your models with the Real-Time Workshop software, you focus
on testing, not programming.
1-24
Software Environment
When you have completed developing and testing, you can use the target
application as a real-time system that runs on a dedicated target PC without
needing to connect to the host computer.
The xPC Target Embedded Option product has one mode of operation,
StandAlone. In this case, the target PC boots into the Microsoft DOS
environment, starts the DOS program xpcboot.com from autoexec.bat, and
then starts the kernel from xpcboot.com:
When using Boot Floppy or CD Boot, you do not need DOS environment to
load and run the xPC Target kernel. DOSLoader mode, like StandAlone mode,
boots the target PC into DOS, starts the DOS program xpcboot.com from
autoexec.bat, and then starts the kernel from xpcboot.com.
Note The xPC Target Embedded Option software is a separate product that
requires an additional license from MathWorks. With this additional license
you can deploy an unlimited number of real-time applications for stand-alone
operation.
For more information on the xPC Target Embedded Option product, see
“Embedded Option” in the xPC Target User’s Guide.
StandAlone Mode
StandAlone mode combines the target application with the kernel and boots
them together on the target PC from a hard disk drive or flash memory. The
host PC does not have to be connected to the target PC.
1 Select StandAlone mode from the Configuration node in the xPC Target
Hierarchy pane of the xPC Target Explorer tool.
3 Copy DOS system files, utilities, kernel/application files, and helper files to
the target PC hard drive or flash memory.
1-25
1 Introduction
When you boot the target PC, the target PC loads DOS environment, which
then calls the xPC Target autoexec.bat file to start the xPC Target kernel
(*.rtb) and associated target application. If you set up the boot device to
run the xPC Target autoexec.bat file upon startup, the target application
starts executing as soon as possible. The xPC Target application executes
entirely in protected mode using the 32-bit flat memory model.
For more information on the xPC Target Embedded Option product, see
“Embedded Option” in the xPC Target User’s Guide.
1-26
User Interaction
User Interaction
In this section...
“Introduction” on page 1-27
“xPC Target Explorer” on page 1-28
“MATLAB Command-Line Interface” on page 1-29
“Simulink External Mode Interface” on page 1-31
“Simulink with xPC Target Scope Blocks” on page 1-32
“Target PC Command-Line Interface” on page 1-32
“Web Browser Interface” on page 1-33
“Custom GUI with xPC Target API for Microsoft .NET Framework” on
page 1-33
“Custom GUI with xPC Target API” on page 1-34
“Custom GUI with xPC Target COM API” on page 1-34
Introduction
The xPC Target environment has a modifiable interface to the target PC.
You can use this interface from MATLAB or Simulink, and you can use
other development environments to create stand-alone client applications
independent of MATLAB. Because of this open environment, there are several
ways to interact with your target application from the host and target PCs.
Note Some blocks (see “Blocks Whose Outputs Depend on Inherited Sample
Time” in the Simulink User’s Guide) cannot properly handle sample time
changes at run-time. For models that contain these blocks, change the sample
time in the model first, then build that model. Although the xPC Target
product allows you to change sample times at run-time, changing them at
run-time for these blocks might cause incorrect results.
The following table compares the interfaces supported by the xPC Target
product.
1-27
1 Introduction
The xPC Target Explorer is an all-in-one user interface that includes the
following functionality.
1-28
User Interaction
For more information, see “Signals and Parameters” in the xPC Target User’s
Guide.
The xPC Target software has more than 90 MATLAB functions for controlling
the target application from the host computer. These functions define, at the
most basic level, what you can do with the xPC Target environment.
The GUIs provided with the xPC Target product are for completing the
most common tasks. They use the xPC Target functions but do not extend
their functionality. The command-line interface provides an interactive
environment that you can extend.
1-29
1 Introduction
1-30
User Interaction
Note Opening a dialog box for a source block causes Simulink to pause. While
Simulink is paused, you can edit the parameter values. You must close the
dialog box to have the changes take effect and allow Simulink to continue.
For more information, see “Parameter Tuning with Simulink External Mode”
in the xPC Target User’s Guide.
1-31
1 Introduction
Signal acquisition — Add scopes to the target PC by adding xPC Target Scope
blocks to your Simulink model. In the Block Parameters dialog box, select
the scope mode and set the trigger.
For information on acquiring signal data with the xPC Target product, see
“Adding an xPC Target Scope Block” on page 3-17, “Entering Parameters for
an xPC Target Scope Block” on page 3-21, “Entering Parameters for an xPC
Target Scope of Type File” on page 3-31, and “Signal Tracing with xPC Target
Scope Blocks” in the xPC Target User’s Guide.
• Control — Start and stop the target application, and change the stop time
and sample time.
For more information, see “Using the Target PC Command-Line Interface”
in the xPC Target User’s Guide.
• Signal acquisition — Acquiring signal data is limited to viewing signal
traces and signal monitoring on the target PC screen.
• Parameter tuning — You can change only scalar parameters in your model.
1-32
User Interaction
• Control — Start and stop the target application, and change the stop time
and sample time.
For more information, see “xPC Target Web Browser Interface” in the xPC
Target User’s Guide.
• Signal acquisition — Signal tracing is limited to viewing a snapshot of a
screen captured from the target PC screen. Add scopes of type target, add
or remove signals, and set triggering modes. You can also monitor signal
values.
For more information, see “Signal Logging with a Web Browser” in the xPC
Target User’s Guide.
• Parameter tuning — Change parameters in an HTML form, and then
submit that form to make the changes in your target application.
For more information, see “Parameter Tuning with a Web Browser” in
the xPC Target User’s Guide.
For more information, see “xPC Target API for Microsoft .NET Framework”.
1-33
1 Introduction
Use the GUI application to control the application, tune parameters, and
acquire signal data from a target application. The custom GUI runs on the
host PC and communicates with the target application on the target PC using
RS-232 or TCP/IP communication. A GUI application can be a console or
Windows application using ActiveX® components.
4 If you tag parameters and signals, build the model-specific COM library.
1-34
2
Installation and
Configuration
The software environment for xPC Target uses two separate computers.
Because of this complexity, installation and configuration are more involved.
This chapter includes the following sections:
Required Products
In this section...
“MATLAB” on page 2-2
“Simulink” on page 2-3
“Real-Time Workshop” on page 2-4
“C Compiler” on page 2-4
“xPC Target Embedded Option Product” on page 2-6
MATLAB
MATLAB provides a command-line interface for the xPC Target product.
With the xPC Target software, you have full control of the target computer
and target application using xPC Target functions and the command-line
interface or MATLAB scripts. You use the xPC Target functions for
2-2
Required Products
Simulink
Simulink provides an environment where you model your dynamic physical
system and controller as a block diagram. You create the block diagram by
using a mouse to connect blocks and a keyboard to edit block parameters.
You can use the xPC Target product with most Simulink blocks, including
discrete-time and continuous-time systems. When you use a continuous-time
system and generate code with Real-Time Workshop, you must use a
fixed-step integration algorithm.
xPC Target I/O driver blocks — You can replace the model of your physical
system with I/O driver blocks connected to the actual physical system, or you
can replace the model of your controller with the actual controller. The xPC
Target I/O library supports more than 400 driver blocks. As additional drivers
become available, you can download updates from the MathWorks Web site at
http://www.mathworks.com/support/product/XP/productnews/
productnews.html
2-3
2 Installation and Configuration
Real-Time Workshop
Real-Time Workshop provides the utilities to convert your Simulink models
into C code and then, with a third-party C/C++ compiler, compile the code
into a real-time executable.
Note xPC Target Version 4.4 requires Real-Time Workshop Version 7.6.
C Compiler
The C compiler creates executable code from the C code generated from
Real-Time Workshop and the C code S-functions you create. The xPC Target
product uses this executable code to create an executable image (target
application) that runs with the xPC Target kernel on the target computer.
Note To configure your C compiler for the xPC Target software, use the xPC
Target Explorer interface (see “Configuring the xPC Target Host PC for Your
C Compiler” on page 2-19). Be aware that the mex -setup command does not
set the C compiler for the xPC Target product.
2-4
Required Products
2-5
2 Installation and Configuration
The xPC Target Embedded Option product is a separate entity that requires
an additional license from MathWorks. Information about the xPC Target
Embedded Option product is included with the xPC Target documentation.
Note xPC Target Version 4.4 works with xPC Target Embedded Option
Version 4.4.
2-6
Related Products
Related Products
MathWorks provides several products that are relevant to the kinds of tasks
you can perform with the xPC Target software.
2-7
2 Installation and Configuration
System Requirements
In this section...
“Introduction” on page 2-8
“Host PC Requirements” on page 2-8
“Target PC Requirements” on page 2-10
Introduction
The hardware and software requirements are different for the host and target
computers.
Note that the BIOS settings of a target PC can affect how it works with
the xPC Target software. If you experience problems using the xPC Target
product with the target or host PC, you should check the system BIOS
settings on the target PC. These settings are beyond the control of the xPC
Target software. Refer to “Target PC BIOS” in the xPC Target User’s Guide
for guidelines on BIOS settings.
Host PC Requirements
The host PC is usually your desktop computer where you install the MATLAB,
Simulink, Stateflow, Stateflow Coder, Real-Time Workshop, xPC Target,
and xPC Target Embedded Option products. A notebook computer is also
a viable host PC.
Software Description
32-bit operating system Windows operating system version supported by
MathWorks
MATLAB Product MATLAB Version 7.11
2-8
System Requirements
Software Description
Simulink Product Simulink Version 7.6
Real-Time Workshop Real-Time Workshop Version 7.6
Product
C language compilers http://www.mathworks.com/support/-
compilers/current_release/
xPC Target Product xPC Target Version 4.4
Hardware Description
Communication Select one of the following methods to
communicate with the target PC:
2-9
2 Installation and Configuration
Target PC Requirements
The target PC must be a 32- or 64-bit PC-compatible system. For example,
you can use a second desktop computer or an industrial system like a PC/104
or CompactPCI as the target computer.
Software Description
Operating system None. The xPC Target kernel has no effect on any
operating system installed on the target PC.
BIOS PC compatible
2-10
System Requirements
Hardware Description
Chip set PC compatible with UART, programmable
interrupt controller, keyboard controller, and
counter
Communication Select one of the following methods to
communicate with the host PC:
2-11
2 Installation and Configuration
Hardware Description
Monitor MathWorks recommends using a monitor, but
it is not necessary. You can get all the target
information using xPC Target functions on the
host PC.
Peripheral One 3.5-inch floppy disk or CD/DVD drive. A
hard disk drive is not required unless you want to
access the target PC file system (for file scopes).
Notes:
Random Access Memory (RAM) — The xPC Target product works with
PC-compatible computers that use inexpensive dynamic RAM, unlike many
non-PC-compatible target computers that use expensive static RAM. You
can acquire several megabytes of data during a run depending on how much
memory you install in the target PC.
2-12
System Requirements
• ISA
• PCI
• PMC
• PC/104 and PC/104+
• PCIe
• CompactPCI
I/O boards — You can install inexpensive I/O boards in the PCI or ISA
slots of the target PC. These boards provide a direct interface to the
sensors, actuators, or other devices for real-time control or signal processing
applications.
The xPC Target software supports the I/O functionality listed in “I/O Driver
Support” on page 1-17.
2-13
2 Installation and Configuration
• USB support —- Disable all USB support, including general USB and
USB keyboard support. Failure to do this will cause occasional long task
execution times (TET).
• PCI boards — Do not detect PCI boards with class code 0xff in the target
PC BIOS. Set this option to Off to enable the BIOS to detect and configure
all boards.
• Hyper-threading — If your target PC supports hyper-threading capabilities,
do not enable these capabilities. Enabling hyper-threading can degrade
the performance of the target PC.
In addition, check the boot up order for the target PC BIOS. You can boot up
the target PC using the following methods:
• If the target PC has a multicore processor, you can configure the xPC
Target software to take advantage of the individual cores. See “Configuring
Environment Parameters for Target PCs” in the xPC Target User’s Guide.
To take advantage of a multicore processor, be sure to disable
hyper-threading in the target PC BIOS.
• If the target PC has only a single core processor, you cannot use the
multicore capabilities of the xPC Target software.
2-14
Installation on the Host PC
Overview
You install the xPC Target software entirely on the host PC. Installing
software on the target PC is not necessary. The xPC Target software is
distributed on a DVD or as a file you download from the Web.
Note Before you start, ensure that the xPC Target and xPC Target Embedded
Option products are not already installed on your host PC. Uninstall both
before proceeding if necessary.
After you install the product, you will need to set up the xPC Target
environment for either serial or network communication. See “Serial
Communication” on page 2-37 or “Network Communication” on page 2-25.
2-15
2 Installation and Configuration
License Requirements
Before you install the xPC Target or the xPC Target Embedded Option
products, you must have a valid File Installation Key and License File.
The File Installation Key identifies the products you purchased from
MathWorks and are permitted to install and use. The License File activates
the installation.
If you have not received either of these, go to the License Center at the
MathWorks Web site.
The xPC Target family of software includes options that you can purchase and
add later to the xPC Target environment.
xPC Target Embedded Option product — With the xPC Target Embedded
Option product, you can boot the target PC from a device other than a floppy
disk or CD/DVD and deploy stand-alone target applications separate from
the host PC.
The xPC Target software uses the directories and files located in
matlabroot\toolbox\rtw\targets\xpc\
• target — Files and functions related to the xPC Target kernel and build
process, including drivers to support I/O blocks
• xpc — Host PC functions related to all of the xPC Target software, methods
for target objects, and methods for scope objects
• xpcdemos — Simulink models and MATLAB code demos
2-16
Installation on the Host PC
If your MATLAB working folder is below or inside the MATLAB root, files
created by Simulink and Real-Time Workshop are mixed with the MATLAB
directories. This mixing of files could cause file management problems.
1 Right-click the MATLAB desktop icon or, from the program menu,
right-click the MATLAB shortcut.
2 Click Properties. In the Start in text box, enter the folder path you
want MATLAB to use initially. Make sure you choose a folder outside the
MATLAB root folder.
3 Click OK, and then start MATLAB. To check your working folder, in the
MATLAB Command Window, type
pwd
pwd or cd
To permanently set your working folder, see “From the Desktop Icon” on
page 2-17.
2-17
2 Installation and Configuration
xpc_register_ocx
This function registers the Active X controllers that xPC Target Explorer
requires.
3 Close MATLAB.
4 Restart MATLAB.
2-18
Installation on the Host PC
Note Do not use the mex -setup command to set the C compiler for the
xPC Target software.
xpcexplr
2-19
2 Installation and Configuration
multitarget environment, this visual aid helps you easily identify the
default target PC.
3 At the Select C Compiler drop-down list, select the compiler you have
installed on the host PC. The examples in this chapter use VisualC.
4 Enter the path (or browse) to the compiler for Compiler Path. For
example,
Note xPC Target Explorer dialogs highlight a field and enable the Revert
and Apply buttons when you make changes. To apply changes, click Apply.
A prompt is displayed if you leave a dialog without first saving changes. If
you want the original entry to be displayed, click the Revert button and
do not click the Apply button. If you click Apply, you cannot retrieve the
original entries.
2-20
xPC Target™ Explorer
The xPC Target Explorer GUI runs on your xPC Target system host machine.
You can interact with xPC Target Explorer through menus or a toolbar. You
can also right-click objects and select actions from the context menu for those
objects. The tutorials in the xPC Target documentation describe procedures
using mouse operations.
2-21
2 Installation and Configuration
xpcexplr
You can also start xPC Target Explorer from the Simulink model window
(Tools > Real-Time Workshop > xPC Target Explorer).
You can dock or undock the xPC Target Explorer window using the arrow
in the upper-right corner. Note the contents of the left pane of the xPC
Target Explorer. This is the xPC Target Hierarchy pane. If you resize or
move the window, the xPC Target software remembers the new size and
location in subsequent restarts of xPC Target Explorer.
2-22
xPC Target™ Explorer
This pane contains all the objects in your xPC Target hierarchy. As you
add objects to your system, xPC Target Explorer adds corresponding nodes
to the xPC Target Hierarchy pane. The foremost node is the Host PC
Root node. It represents the host PC. The right pane displays information
that reflects an item selected in the left pane.
Note that, by default, xPC Target Explorer starts with two target PC
objects. The first target PC object is highlighted as the default.
Note Do not use Simulink external mode while xPC Target Explorer is
running. Use only one interface or the other.
• When you first start xPC Target Explorer, it has a default node, TargetPC1.
You configure this node for a target PC, then connect the node to the target
PC. If you later build a target application from a Simulink model, the xPC
Target software builds and downloads that application for the default
target PC. You can add other target PC nodes and designate one of them
as the default target PC instead of the first one. To set a target PC node
as the default, right-click that node and select Set As Default from the
context-sensitive menu. The default target PC node is always boldfaced. In
a multitarget environment, this visual aid helps you easily see the target
PC you are working with.
If you delete a default target PC node, the target PC node preceding it
becomes the default target PC node. The last target PC node is always the
default target PC node and cannot be deleted.
• If you want to use the xPC Target command-line interface to work with the
target PC, you must indicate which target PC the command is interacting
with. If you do not identify a particular target PC, the xPC Target software
expects xPC Target Explorer to contain this information.
• The xPC Target product provides a default target PC to help you work
with the MATLAB command-line interface, maintain compatibility with
previous releases, and work with Simulink external mode, as follows:
2-23
2 Installation and Configuration
2-24
Network Communication
Network Communication
In this section...
“Network Communication Overview ” on page 2-25
“Hardware for Network Communication” on page 2-25
“Ethernet Card Provided with the xPC Target Product” on page 2-26
“Ethernet Card for a PCI Bus” on page 2-27
“Ethernet Card for an ISA Bus” on page 2-28
“Environment Properties for Network Communication” on page 2-30
• Network (Ethernet) adapter card — When using the product with TCP/IP,
you must have a network (Ethernet) adapter card correctly installed on
both the host PC and the target PC. Be sure to:
- Connect the host and target computers with an unshielded twisted pair
(UTP) cable to your (LAN).
- Assign a static IP address to the target PC network adapter card.
For the most current network communications requirements, see
http://www.mathworks.com/products/xpctarget/-
xPC_Target_Supported_Ethernet_Chipsets.pdf
You can also see “Ethernet Card Provided with the xPC Target Product”
on page 2-26 for information on the Ethernet card that ships with your
product.
2-25
2 Installation and Configuration
The host PC network adapter card can have a Dynamic Host Configuration
Protocol (DHCP) address. The host PC can be any computer on the
network. When using the product with TCP/IP, you must configure the
DHCP server to reserve all static IP addresses to prevent these addresses
from being assigned to other systems.
You can also directly connect your computers. Use a crossover UTP cable
with RJ45 connectors to connect them. Both computers must have static
IP addresses. If the host PC has a second network adapter card, that card
can have a DHCP address.
• I/O boards — If you use I/O boards on your target PC, you need to install
the boards correctly.
xpcexplr
2 In the xPC Target Explorer xPC Target Hierarchy pane, select the
Communication node of the target PC for which you want to check the boot
disk. For example, select the Communication node for TargetPC1.
2-26
Network Communication
If you cannot use the Ethernet card provided with the xPC Target product,
you can select your own Ethernet card, see
http://www.mathworks.com/products/xpctarget/-
xPC_Target_Supported_Ethernet_Chipsets.pdf
The following are cases where you might not be able to use the Ethernet card
provided with the xPC Target product:
To install the PCI bus Ethernet card supplied with the xPC Target software,
use the following procedure:
3 Plug the Ethernet card from MathWorks into a free PCI bus slot.
2-27
2 Installation and Configuration
Your next task is to set up the xPC Target environment for network
communication. See “Environment Properties for Network Communication”
on page 2-30.
If you are using an ISA bus, you need to reserve, from the BIOS, an interrupt
for this board.
MathWorks does not provide an ISA bus board. For a list of known compatible
network adapter chip families, see
http://www.mathworks.com/products/xpctarget/-
xPC_Target_Supported_Ethernet_Chipsets.pdf
2-28
Network Communication
2 On your ISA bus card, assign an IRQ and I/O-port base address by moving
the jumpers or switches on the card. Write down these settings, because
you need to enter them in the xPC Target Explorer.
You should set the IRQ line to 11 and the I/O-port base address to around
0x300. If one of these hardware settings would lead to a conflict in your
target PC, select another IRQ or I/O-port base address.
Note If your ISA bus card does not contain jumpers to set the IRQ line and
the base address, use the utility on the installation disk supplied with your
card to manually assign the IRQ line and base address. Do not configure
the card as a PnP-ISA device.
4 Connect the target PC network card to your local area network (LAN) using
a coaxial cable or an unshielded twisted-pair cable.
If you use an Ethernet card for an ISA bus within a target PC that has a
PCI bus, you must reserve the chosen IRQ line number for the Ethernet
card in the PCI BIOS. Refer to your BIOS setup documentation to set up
the PCI BIOS.
Your next task is to set up the xPC Target environment for network
communication. See “Environment Properties for Network Communication”
on page 2-30.
2-29
2 Installation and Configuration
After you have installed the xPC Target software, you can specify the
environment properties for the host and target computers. Note that you
must specify these properties before you can build and download a target
application.
xpcexplr
4 As necessary, repeat and for each additional target PC you want to add
to your system.
2-30
Network Communication
6 Select Communication.
The pane changes to one that contains only those parameters pertinent
to network communication.
8 You must enter the network properties with the correct values according
to your LAN environment. Ask your system administrator for values for
these settings.
2-31
2 Installation and Configuration
Note The TCP/IP address is for your host PC, not your target PC. You
still need to get the target PC TCP/IP address for your target PC from
your system administrator.
The default gateway address is blank in this dialog box. However, in the
xPC Target Explorer, you must enter 255.255.255.255 for the gateway
value in the TCP/IP gateway address property.
2-32
Network Communication
2-33
2 Installation and Configuration
to your target PC. If you connect your computers with a crossover cable,
leave this property as 255.255.255.255.
If you communicate with the target PC from within your LAN, you might
not need to define a gateway and change this setting.
If you communicate from a host PC located in a LAN different from your
target PC, you need to define a gateway and enter its IP address. This is
especially true if you want to work over the Internet. Ask your system
administrator for the IP address of the appropriate gateway.
10 Enter the following properties specific to the Ethernet card on your target
PC:
2-34
Network Communication
11 If the target PC has multiple Ethernet cards, type the following command
to specify which card to use:
setxpcenv(`EthernetIndex', '#')
# indicates a single digit to specify the index number for the Ethernet card.
This command ensures that upon booting the target, the kernel selects
the appropriate Ethernet card instead of selecting the default card with
index number 0 as the target PC card.
12 Repeat step 5 to 10 for any target PC for which you have a network
connection between the host PC and target PC.
The xPC Target software updates the environment with new properties as
you enter them.
2-35
2 Installation and Configuration
Your next task is to create a target boot disk. See “Booting Target PCs from
Boot Floppy Disk” on page 2-52.
2-36
Serial Communication
Serial Communication
In this section...
“Serial Communication Overview” on page 2-37
“Hardware for Serial Communication” on page 2-37
“Environment Properties for Serial Communication” on page 2-38
• Null modem cable — Connect the host and target computers with the null
modem cable supplied by MathWorks with the xPC Target software. You
can use either the COM1 or COM2 port.
• I/O boards — If you use I/O boards on the target PC, you need to install
the boards correctly. See the manufacturer’s literature for installation
instructions.
2-37
2 Installation and Configuration
1 5
6 9
2 4
7 8
3 3
8 7
4 2
9 6
5 1
After you have installed the xPC Target product, you can specify the
environment properties for the host and target computers. Note that you
must specify these properties before you can build and download a target
application.
2-38
Serial Communication
• If you have a serial connection between your host PC and target PC, and
you use a baud rate that is less than the maximum possible baud rate,
you might experience communication failures. If you do experience these
failures, use a baud rate greater than 19200.
• If you have an RS-232 connection, you might not want to use host scopes
and a scope viewer on the host PC (Host Scope Viewer) to acquire and
display large blocks of data. The slowness of the RS-232 connection causes
large delays in performance for large blocks of data.
xpcexplr
The xPC Target Explorer window opens. Note that xPC Target Explorer
automatically provides a default target PC node, TargetPC1.
4 As necessary, repeat step 2 and step 3 for each additional target PC you
want to add to your system.
2-39
2 Installation and Configuration
Configuration, File System, and PCI Devices nodes appear. You work
with the Configuration node to configure the target PC node for a target
PC. The File System node contains the contents of a target PC file system.
PCI Devices lists all PCI devices detected on the target PC. In this
procedure, you work with the Configuration node.
6 Select Communication.
2-40
Serial Communication
Note When you first select a subnode under a target PC node, the target
PC node becomes boldfaced. In a multitarget environment, this visual aid
helps you easily see the target PC you are working with.
The pane changes to one that contains only those parameters pertinent to
serial communication.
8 From the Host port list, select either COM1 or COM2 for the connection on
the host PC. The xPC Target software determines the COM port you use on
the target PC automatically.
9 From the Baud rate list, select the baud rate for the serial connection
between the host PC and this target PC. The default is 115200. Note that
for optimal performance, you should select the highest possible serial
connection baud rate for the xPC Target software.
10 Repeat step 5 to step 9 for any target PC for which you have a serial
connection between the host PC and target PC.
2-41
2 Installation and Configuration
The following figure illustrates the xPC Target Explorer settings for the
serial connection of one target PC.
You do not have to exit and restart MATLAB after making changes to the
xPC Target environment, even if you change the communication between the
host and target from RS-232 to TCP/IP. However, you do have to recreate the
target boot disk and rebuild the target application from the Simulink model.
2-42
Serial Communication
Your next task is to create a target boot disk. See “Booting Target PCs from
Boot Floppy Disk” on page 2-52.
2-43
2 Installation and Configuration
Introduction
You can boot your target PC with the xPC Target kernel using one of the
following ways from the xPC Target Explorer:
Target boot disks and boot images include the xPC Target kernel specific
for either serial or network communication. If you installed the xPC Target
Embedded Option, and you select stand-alone mode, the target boot files
include the target application (see “Embedded Option” in the xPC Target
User’s Guide). If you want to boot from a device other than a CD, DVD,
3.5-inch disk, or dedicated network boot image, see “Booting from a DOS
Device” in the xPC Target User’s Guide.
Note Before you create a target boot disk, ensure that you have write
permission for your current working folder. You cannot create a boot disk
otherwise.
2-44
xPC Target™ Boot Options
• Confirm that the boot tab on the Configuration pane is set to your desired
boot mode:
- CD Boot
- Boot Floppy
- Network Boot
For information on other boot modes, see the following topics in the xPC
Target User’s Guide:
- “Booting from a DOS Device”, for DOSLoader mode
- “Embedded Option”, for StandAlone mode
• Check the C compiler specification (see “Configuring the xPC Target Host
PC for Your C Compiler” on page 2-19).
• If you are using TCP/IP communication, check that your network
connections are correct. Also check the xPC Target Explorer settings (see
“Network Communication” on page 2-25). Your xPC Target system shipped
with a supported Ethernet card.
• If you are using serial communication, check that your physical connections
are correct. Also check the xPC Target Explorer settings (see “Serial
Communication” on page 2-37).
• Check your target PC BIOS settings (see “The xPC Target Software and
the Target PC BIOS” on page 2-13 in this chapter and “BIOS Settings”).
2-45
2 Installation and Configuration
You use the target boot CD or DVD to load and run the xPC Target kernel.
After you make changes to the xPC Target environment properties, you must
create a target boot CD or DVD. This topic assumes you are using default
environment parameter settings for the boot CD or DVD creation. If this is
not the case, see “Configuring Environment Parameters for Target PCs” in
the xPC Target User’s Guide for further details.
2-46
xPC Target™ Boot Options
2 If the xPC Target Explorer is not open, open it now. At the MATLAB
Command Window, type
xpcexplr
3 In the xPC Target Explorer xPC Target Hierarchy pane, select a target
PC Configuration node. For example, select the Configuration node
for TargetPC1.
5 In the location parameter, enter a path in which you want xPC Target
Explorer to write the xPC Target CD/DVD boot ISO image. For example,
enter C:\Work\matlab.
2-47
2 Installation and Configuration
2-48
xPC Target™ Boot Options
Select the appropriate drive, insert the CD or DVD, then click Burn
Disk.
• If you do not have Microsoft Windows Vista or Microsoft Windows XP
Service Pack 2 or 3 with Image Mastering API v2.0 (IMAPIv2.0), use
your third-party CD creation software to write the cdboot.iso image to
the empty CD/DVD.
9 Insert the bootable CD/DVD into your target PC CD/DVD drive and reboot
that PC.
Your next task is to install the software on the target PC and test your
installation. See “Testing and Troubleshooting the Installation” on page 2-62.
2-49
2 Installation and Configuration
getxpcenv
3 Ensure that the following xPC Target properties are set as follows:
• TargetBoot — CDBoot
• CDBootImageLocation — Your host PC CD/DVD disk drive location
4 If these properties are not set with the correct values, use the setxpcenv
function to set them. For example:
setxpcenv('TargetBoot','CDBoot')
setxpcenv(CDBootImageLocation,'c:\work\xpc\cdimage')
updatexpcenv
xpcbootdisk
The xPC Target software displays the following message and creates the
CD/DVD boot ISO image.
2-50
xPC Target™ Boot Options
Select the appropriate drive, insert the CD or DVD, then press the
Enter key.
• If you do not have Microsoft Windows Vista or Microsoft Windows XP
Service Pack 2 or 3 with Image Mastering API v2.0 (IMAPIv2.0), use
your third-party software to write the cdboot.iso image to the empty
CD/DVD.
8 Insert the bootable CD/DVD into your target PC CD/DVD drive and reboot
that PC.
Your next task is to install the software on the target PC and test your
installation. See “Testing and Troubleshooting the Installation” on page 2-62.
2-51
2 Installation and Configuration
1 If the xPC Target Explorer is not open, open it now. At the MATLAB
Command Window, type
xpcexplr
2 In the xPC Target Explorer xPC Target Hierarchy pane, select a target
PC Configuration node. For example, select the Configuration node
for TargetPC2.
2-52
xPC Target™ Boot Options
4 As necessary, change the drive letter of the 3.5-inch drive to a valid floppy
drive. It is a: by default.
7 Insert a formatted 3.5-inch floppy disk into the host PC disk drive, and
then click OK.
All data on the disk is erased as the xPC Target software writes the xPC
Target kernel and other required files to the 3.5-inch disk.
The xPC Target software displays the following dialog box while creating
the boot disk. The process takes about 1 to 2 minutes.
2-53
2 Installation and Configuration
9 Insert the boot disk into your target PC disk drive and reboot that PC.
Your next task is to install the software on the target PC and test your
installation. See “Testing and Troubleshooting the Installation” on page 2-62.
To create a target boot disk for the current xPC Target environment, use the
following procedure:
getxpcenv
2 Ensure that the following xPC Target properties are set as follows:
• TargetBoot — BootFloppy
• BootFloppyLocation — Your host PC 3.5-inch disk drive location
3 If these properties are not set with the correct values, use the setxpcenv
function to set them. For example:
setxpcenv('TargetBoot','BootFloppy')
setxpcenv('BootFloppyLocation','a:')
updatexpcenv
2-54
xPC Target™ Boot Options
xpcbootdisk
5 Insert a formatted floppy disk into the host PC disk drive, and then press
any key.
The write procedure starts and, while creating the boot disk, the MATLAB
Command Window displays the following status information.
Your next task is to install the software on the target PC and test your
installation. See “Testing and Troubleshooting the Installation” on page 2-62.
2-55
2 Installation and Configuration
1 Identify the target PC that you want to boot over the dedicated network.
• Install the Ethernet card supplied with the xPC Target product.
• Use your own Ethernet card. If you choose this, ensure that:
– The xPC Target product supports your Ethernet card (see “Hardware
for Network Communication” on page 2-25).
– Your Ethernet card must have a boot ROM that is compatible with
the Preboot eXecution Environment (PXE) specification.
3 Connect the host PC and the target PCs within the dedicated network. For
example, connect one end of a crossover cable to the dedicated network card
of the host PC and connect the other end of this cable to the dedicated
network card of the target PC.
5 Enter BIOS and set up the target PC for a LAN or network boot. If there
is a boot order, consider setting the boot order so that the removable/boot
floppy disk is the first option and the LAN is the second. Doing so ensures
that if there is no xPC Target boot disk in the target PC, you can still boot
the target PC from a kernel on the network.
2-56
xPC Target™ Boot Options
1 Ensure that the host PC has a network card available for the dedicated
network. As necessary, insert a second network card and configure that
card for the dedicated network. This step includes assigning the host PC
a unique IP address (for example, 10.10.10.10) in the same subnet as the
target PC.
2 If the xPC Target Explorer is not open, open it now. At the MATLAB
Command Window, type
xpcexplr
2-57
2 Installation and Configuration
b In the six fields, enter the physical target PC MAC address (in
hexadecimal).
2-58
xPC Target™ Boot Options
The software creates and starts a network boot server process on the host
PC. You will boot the target PC using this process.
The host PC network boot server displays a pop-up from the system tray
indicating that the boot server is being downloaded to the target PC.
2-59
2 Installation and Configuration
2 Select the target PC name with which you want to associate the physical
target PC.
The target PC receives the xPC Target kernel and boots with this kernel.
2-60
xPC Target™ Boot Options
If you click the Cancel button instead of selecting a target PC name, the
next time you try to boot the target PC across the network, the kernel will
ignore the target PC boot request for 90 seconds.
• If the target PC name has a MAC address, and there is a physical target
PC whose MAC address matches the target PC name MAC address, the
software matches the two and the xPC Target Network Boot dialog
does not display.
• If the connection between the target PC and host PC is an RS-232 one, you
cannot boot the target PC across the network.
• If the StandAlone mode is enabled, you cannot boot the target PC across
the network.
2-61
2 Installation and Configuration
1 Insert your target boot disk into a target PC disk drive or CD drive. This
target boot disk contains the software to run a target PC.
2 To reboot the target PC, press the reset button on the PC.
After loading the BIOS, the software boots the kernel and displays the
following on the target PC monitor.
2-62
Testing and Troubleshooting the Installation
If you have a keyboard attached to the target PC, you can activate that
keyboard by typing C, and press the Page Up and Page Down keys to
page up and down the target PC monitor.
Note During the build process, Real-Time Workshop does not allow files
to be saved within the MATLAB tree root. If you select a current folder
within the MATLAB tree, the xPC Target test procedure fails when trying
to build a target application.
xpctest
MATLAB runs the test script for the default target PC and displays
messages indicating the success or failure of a test. If you use RS-232
communication, the first test is skipped.
If all of the tests succeed, you are ready to build and download a target
application to the target PC. See Chapter 3, “Basic Tutorial”.
2-63
2 Installation and Configuration
Note This topic describes tests 1 to 4. For further details on these tests, or
for a description of tests 5 to 8, see “Troubleshooting xpctest Results” in the
“Frequently Asked Questions” chapter of the xPC Target User’s Guide.
1 Open a DOS shell and type the IP address of the target computer:
ping xxx.xxx.xxx.xxx
Ping command fails — If the DOS shell displays the following message,
the ping command failed, and the problem might be with your network
cables.
To solve this problem, check your network cables. You might have a faulty
network cable, or if you are using a coaxial cable, the terminators might
be missing.
2-64
Testing and Troubleshooting the Installation
Ping command fails, but cables are okay — If the cables are okay, the
problem might be that you entered an incorrect property in xPC Target
Explorer.
xpcexplr
For the problem target PC, check that Target PC IP address, LAN
subnet mask address, and TCP/IP gateway address have the correct
values. Change the TCP/IP options as necessary, then create a new boot
floppy disk. On the target PC, reboot with the new boot floppy disk.
• Check that TCP/IP target bus type is set to PCI instead of ISA.
• Check that TCP/IP target bus type is set to ISA instead of PCI.
• Check that TCP/IP target ISA memory port is set to the correct I/O
port base address and check that the address does not lead to a conflict
with another hardware resource.
• Check that TCP/IP target ISA IRQ number is set to the correct IRQ
line and check that the line number does not lead to a conflict with
another hardware resource.
• If the target PC motherboard contains a PCI chip set, check whether
the IRQ line used by the ISA bus Ethernet card is reserved within the
BIOS setup.
Ping succeeds, but test 1 with the command xpctest fails — The
problem might be that you have incorrect IP and gateway addresses
entered in xPC Target Explorer.
xpcexplr
2-65
2 Installation and Configuration
For the problem target PCs, enter the correct addresses. Recreate the
target boot disk.
See also “xpctest: Test 1 Fails” in “Frequently Asked Questions” in the xPC
Target User’s Guide. If you still cannot solve your problem, see “If You Need
More Help” on page 2-68.
tg=xpctarget.xpc('argument-list')
xPC Object
Connected = Yes
Application = loader
Target object does not connect — If you do not get the preceding
messages, the problem might be that you have a bad target boot disk.
To solve this problem, create another target boot disk with a new floppy
disk. See “Booting Target PCs from Boot Floppy Disk” on page 2-52.
See also “xpctest: Test 2 Fails” in “Frequently Asked Questions” in the xPC
Target User’s Guide. If you still cannot solve your problem, see “If You Need
More Help” on page 2-68.
2-66
Testing and Troubleshooting the Installation
xpctest('-noreboot')
This command reruns the test without using the reboot command and
displays the message
2 Observe the messages in the MATLAB Command Window during the build
process.
Reboot fails, but build okay when reboot skipped — If the command
xpctest skips the reboot command but successfully builds and loads the
target application, the problem could be that some target hardware does
not support the xPC Target reboot command. In this case, you cannot use
this command to reboot your target computer. You need to reboot using a
hardware reset button.
See also “xpctest: Test 3 Fails” in “Frequently Asked Questions” in the xPC
Target User’s Guide. If you still cannot solve your problem, see “If You Need
More Help” on page 2-68.
2-67
2 Installation and Configuration
See also “xpctest: Test 4 Fails” in “Frequently Asked Questions” in the xPC
Target User’s Guide. If you still cannot solve your problem, see “If You Need
More Help” on page 2-68.
Note MathWorks Technical Support might ask you to use the getxpcinfo
function to retrieve diagnostic information for your xPC Target configuration.
This function writes the diagnostic information to the xpcinfo.txt file in
the current folder. This file might contain information sensitive to your
organization. Review the contents of this file before sending to MathWorks.
2-68
Exporting and Importing xPC Target™ Explorer Environments
1 If the xPC Target Explorer is not open, open it now. At the MATLAB
Command Window, type
xpcexplr
2-69
2 Installation and Configuration
2-70
Exporting and Importing xPC Target™ Explorer Environments
You can save the target PC environment structure to a MAT-file. This enables
you to reimport the configuration defined in the structure into a future xPC
Target Explorer session.
load targetpc1.mat
2-71
2 Installation and Configuration
2-72
3
Basic Tutorial
This chapter explains the basic functions of the xPC Target product by using
a simple Simulink model. Because this model does not have I/O blocks, you
can try these procedures whether or not you have I/O hardware on your target
PC. This chapter includes the following sections:
Simulink Model
In this section...
“Creating a Simple Simulink Model” on page 3-2
“Entering Parameters for the Scope Block” on page 3-6
“Adding a Simulink Outport Block” on page 3-10
“Entering Parameters for the Outport Blocks” on page 3-13
“Adding an xPC Target Scope Block” on page 3-17
“Entering Parameters for an xPC Target Scope Block” on page 3-21
The model includes a transfer function and a signal generator block. If you
want to visualize signals while simulating your model, you need to add a
standard Simulink Scope block.
simulink
2 From the File menu, point to New, and then click Model.
3-2
Simulink® Model
4 Click and drag the Transfer Fcn block to the Simulink model window.
5 In the Simulink Library Browser window, click and drag the following
blocks to your model.
3-3
3 Basic Tutorial
Note If you provide a name for a signal in the Signal name property of the
Signal Properties dialog box, that name appears in the target PC GUI scope
graph after you build and download the model to the target PC. By default,
if you do not enter a name for the signal in this dialog box, the scope graph
displays the signal identifier rather than a name.
6 Double-click the Signal Generator block. The Block Parameters dialog box
opens. From the Wave form list, select square.
20
3-4
Simulink® Model
Your Block Parameters dialog box will look similar to the following figure.
9 Connect the Signal Generator block to the Transfer Fcn block, and connect
the input and output signals to the scope block using the Mux block.
3-5
3 Basic Tutorial
10 From the File menu, click Save As and enter a filename. For example,
enter my_xpc_osc and then click OK.
You can use either a Simulink Scope block or an xPC Target Scope block to
visualize signals from an xPC Target application running in real time. The
topics for this example describe how to use the xPC Target Scope block. See
“Adding an xPC Target Scope Block” on page 3-17. See “Signal Tracing with
Simulink External Mode” for a description of how to use a Simulink Scope
block to visualize target application signals.
For information on creating a Simulink model and adding signal and scope
blocks, see the online Simulink documentation.
After you add a Scope block to your Simulink model, you can enter the scope
parameters for signal tracing:
3-6
Simulink® Model
3 Click the General tab. In the Number of axes box, enter the number of
graphs you want in one Scope window. For example, enter 1 for a single
graph. Do not select the floating scope check box.
In the Time range box, enter the upper value for the time range. For
example, enter 1 second. From the Tick labels list, choose all.
From the Sampling list, choose Sample time and enter 0 in the text
box. Entering 0 indicates that Simulink evaluates this block as a
continuous-time block. If you have discrete blocks in your model, enter the
Fixed step size you entered in the Configuration Parameters dialog box.
3-7
3 Basic Tutorial
Your Scope parameters dialog box will look similar to the figure shown
below.
• Click Apply to apply the changes to your model and leave the dialog
box open.
• Click OK to apply the changes to your model and close the Scope
parameters dialog box.
3-8
Simulink® Model
5 In the Scope window, point to the y-axis shown in the figure below, and
right-click.
7 The Scope properties: axis 1 dialog box opens. In the Y-min and Y-max
text boxes, enter the range for the y-axis in the Scope window. For example,
enter -2 and 2 as shown in the figure below.
3-9
3 Basic Tutorial
• Click Apply to apply the changes to your model and leave the dialog
box open.
• Click OK to apply the changes to your model and close the Axes
Parameters dialog box.
my_xpc_osc
2 In the Simulink window, from the View menu, click Library Browser.
3-10
Simulink® Model
3-11
3 Basic Tutorial
4 Click and drag the Out1 block to your model and connect it to the output of
the Mux block.
3-12
Simulink® Model
5 From the File menu, click Save As and enter a filename. For example,
enter my_xpc_osc1 and then click OK.
Your next task is to enter parameters for the Outport block. See “Entering
Parameters for the Outport Blocks” on page 3-13.
After you add an Outport block to your Simulink model, you can enter
parameters. This procedure uses the model my_xpc_osc1.mdl with an
Outport block as an example. To add an Outport block, see “Adding a
Simulink Outport Block” on page 3-10.
my_xpc_osc1
3-13
3 Basic Tutorial
Simulink displays the Solver pane. The Simulation section of this pane
defines the initial stop and sample time for your target application.
4 In the Solver options section, enter 0 seconds in the Start time box.
In the Stop time box, enter an initial stop time. For example, enter 20
seconds. To change this time after creating your target application, change
the target object property tg.Stoptime to the new time using the MATLAB
command-line interface. To specify an infinite stop time, enter inf.
5 From the Type list, select Fixed-step. Real-Time Workshop does not
support variable-step solvers.
6 From the Solver list, select a solver. For example, select the
general-purpose solver ode4 (Runge-Kutta).
7 In the Fixed step size box, enter the sample time for the target
application. For example, enter 0.00025 second (250 microseconds). You
can change this value after creating the target application.
3-14
Simulink® Model
If you find that 0.000250 second results in overloading the CPU on the
target PC, try a larger Fixed step size such as 0.002 seconds.
If your model contains discrete states, which would lead to a hybrid model
with both continuous and discrete states, the sample times of the discrete
states can only be multiples of the Fixed step size. If your model does
not contain any continuous states, enter 'auto', and the sample time is
taken from the model.
The Solver pane should look similar to the figure shown below.
The Data Import/Export pane opens. This pane defines the model signals
logged during a simulation of your model or while running your target
application.
3-15
3 Basic Tutorial
9 In the Save to workspace section of this pane, select the Time, States,
and Output check boxes.
Note When your target application is running in real time, data is not
saved to the variables tout and yout. Instead, data is saved to the target
object properties TimeLog, StateLog, and OutLog. However, you must still
select the Time, States, and Output check boxes for data to be logged to
the target object properties.
The Data Import/Export pane should look similar to the figure shown.
Normally you select all the Save to workspace check boxes. However, you
might want to consider clearing some or all of them in the following cases:
• Many states — If your model contains many states (for example, more
than 20 states), the storage of the state vector requires a lot of target
memory. If you clear the States check box, logging of states is turned off
and more memory is available for the target application. An alternative
to logging all the state signals is to select individual states of interest by
adding Outport blocks to your model.
3-16
Simulink® Model
• Small sample time — If you choose a very short sample time, this setting
might overload the CPU. If you clear the Save to workspace check boxes,
logging is turned off and more computing time is available for calculating
the model.
1 Click OK.
2 From the File menu, click Save. The model is saved as my_xpc_osc1.mdl.
Your next task is to add an xPC Target Scope block to your Simulink model.
See “Adding an xPC Target Scope Block” on page 3-17.
Adding xPC Target Scope blocks to your Simulink model can save you time.
When you build the model, the resulting target application contains the xPC
Target Scope blocks you added to the model. After you download the target
application, the xPC Target Scope block automatically displays on the target
PC monitor. If you do not add xPC Target Scope blocks to your model and you
want to monitor signals on the target application without rebuilding it, you
need to add xPC Target scopes and define and select signals for the scopes
(see “Signals and Parameters” in the xPC Target User’s Guide). The signal
information is saved with your model.
After you create a Simulink model, you can add an xPC Target Scope block.
The following procedure uses the Simulink model my_xpc_osc1.mdl as an
example to show how to connect an xPC Target Scope block to your model.
3-17
3 Basic Tutorial
my_xpc_osc1
2 In the Simulink window, from the View menu, click Library Browser.
3-18
Simulink® Model
3-19
3 Basic Tutorial
4 Click Misc.
Simulink adds a new Scope block to your model with a scope identifier of 1.
3-20
Simulink® Model
6 Connect the xPC Target Scope block to the Simulink Scope block.
7 From the File menu, click Save As. Enter a filename. For example, enter
my_xpc_osc2 and then click OK.
Your next task is to define the xPC Target Scope block parameters. See
“Entering Parameters for an xPC Target Scope Block” on page 3-21.
After you add an xPC Target Scope block to your Simulink model, you can
enter parameters for this block. To add an xPC Target Scope block, see
3-21
3 Basic Tutorial
“Adding an xPC Target Scope Block” on page 3-17. To enter the parameters
for an xPC Target Scope block to write signal data to a file on the target PC,
see “Entering Parameters for an xPC Target Scope of Type File” on page 3-31.
There are three types of scopes, target, host, and file. The xPC Target
Scope block dialog changes depending on which scope type you are configuring.
The following sections describe the procedure depending on the scope type:
• “Entering Parameters for an xPC Target Scope of Type Target” on page 3-22
• “Entering Parameters for an xPC Target Scope of Type Host” on page 3-27
• “Entering Parameters for an xPC Target Scope of Type File” on page 3-31
my_xpc_osc2
3-22
Simulink® Model
3-23
3 Basic Tutorial
This number identifies the xPC Target Scope block and the scope screen on
the host or target computers.
4 From the Scope type list, select Target if it is not already selected.
5 Select the Start scope when application starts check box to start a
scope when the target application is downloaded and started. The scope
window opens automatically.
If you have a scope type of Target and a scope mode of Numerical, the
scope block dialog adds a Numerical format box to the dialog. You can
define the display format for the data. See step 7 for a description of how to
complete the Numerical format box. If you choose not to complete the
Numerical format box, the xPC Target software displays the signal using
the default format of %15.6f, which is a floating-point format, with no label.
where
• LabelN is the label for the signal. You can use a different label for each
signal or the same label for each signal. This argument is optional.
• width is the minimum number of characters to offset from the left of the
screen or label. This argument is optional.
• precision is the maximum number of decimal places for the signal
value. This argument is optional.
• type is the data type for the signal format. You can use one or more of
the following types:
3-24
Simulink® Model
Type Description
%e or %E Exponential format using e or E
%f Floating point
%g Signed value printed in f or e format depending on
which is smaller
%G Signed value printed in f or E format depending on
which is smaller
• LabelX is a second label for the signal. You can use a different label for
each signal or the same label for each signal. This argument is optional.
For example,
For a whole integer signal value, enter 0 for the precision value. For
example,
For a line with multiple entries, delimit each entry with a command and
enclose the entire string in single quotation marks. For example,
3-25
3 Basic Tutorial
8 Select the Grid check box to display grid lines on the scope. Note that this
parameter is only applicable for scopes of type Target and scope modes of
type Graphical redraw, Graphical sliding, or Graphical rolling.
9 In the Y-Axis limits box, enter a row vector with two elements where the
first element is the lower limit of the y-axis and the second element is the
upper limit. If you enter 0 for both elements, then scaling is set to auto.
Note that this parameter is only applicable for scopes of type Target and
scope modes of type Graphical redraw, Graphical sliding, or Graphical
rolling.
If you select a Trigger mode other than FreeRun, this parameter can
specify the number of samples to be acquired before the next trigger event.
If you select a Scope mode of Numerical, the block updates the output
every Number of samples.
If you select Signal Triggering, then, in the Trigger signal box, enter
the index of a signal. In the Trigger level box, enter a value for the signal
to cross before triggering. From the Trigger slope list, select either,
rising, or falling. You do not need to specify scope triggering.
3-26
Simulink® Model
If you select Scope Triggering, then in the Trigger scope number box,
enter the scope number of a Scope block. If you use this trigger mode, you
must also add a second Scope block to your Simulink model. You do not
need to specify signal triggering.
If you select Scope Triggering and want the scope to trigger on a specific
sample of the other scope, enter a value in the Sample to trigger on
box. The default value is 0 and indicates that the triggering scope and the
triggered (current) scope start simultaneously. For more information on
this field, see “Triggering One Scope with Another Scope to Acquire Data”
in the xPC Target User’s Guide.
14 Click OK.
15 From the File menu, click Save As. The model is saved as
my_xpc_osc2.mdl.
Your next task is to simulate the model. See “Simulating the Model” on page
3-37.
Note As soon as the target application is built and downloaded, the xPC
Target kernel creates a scope. If you want to change xPC Target Scope
parameters after building the target application or while it is running, you
need to assign the scope to a MATLAB variable. To assign the scope object,
use the target object method getscope. If you use the target object method
getscope to remove a scope created during the build and download process,
and then you restart the target application, the xPC Target kernel recreates
the scope.
my_xpc_osc2
3-27
3 Basic Tutorial
This number identifies the xPC Target Scope block and the scope screen on
the host or target computers.
3-28
Simulink® Model
5 Select the Start scope when application starts check box to start a
scope when the target application is downloaded and started. With a scope
of type target, the scope window opens automatically. With a scope of type
host, you can open a host scope viewer window from xPC Target Explorer.
3-29
3 Basic Tutorial
If you select Signal Triggering, then in the Trigger signal box, enter
the index of a signal. In the Trigger level box, enter a value for the signal
to cross before triggering. From the Trigger slope list, select either,
rising, or falling. You do not need to specify scope triggering.
If you select Scope Triggering, then in the Trigger scope number box,
enter the scope number of a Scope block. If you use this trigger mode, you
must also add a second Scope block to your Simulink model. You do not
need to specify signal triggering.
If you select Scope Triggering and want the scope to trigger on a specific
sample of the other scope, enter a value in the Sample to trigger on
box. The default value is 0 and indicates that the triggering scope and the
triggered (current) scope start simultaneously. For more information on
this field, see “Triggering One Scope with Another Scope to Acquire Data”
in the xPC Target User’s Guide.
10 Click OK.
11 From the File menu, click Save As. The model is saved as
my_xpc_osc2.mdl.
Your next task is to simulate the model. See “Simulating the Model” on page
3-37.
3-30
Simulink® Model
Note As soon as the target application is built and downloaded, the xPC
Target kernel creates a scope. If you want to change xPC Target Scope
parameters after building the target application or while it is running, you
need to assign the scope to a MATLAB variable. To assign the scope object,
use the target object method getscope. If you use the target object method
remscope to remove a scope created during the build and download process,
and then you restart the target application, the xPC Target kernel recreates
the scope.
After you add an xPC Target Scope block to your Simulink model, you can
configure this block to save a file on the target PC.
Note The signal data file can quickly increase in size. You should examine
the file size between runs to gauge the growth rate for the file. If the signal
data file grows beyond the available space on the disk, the signal data might
be corrupted.
Saving signal data to files is most useful when you are using target PCs as
stand-alone xPC Target systems. To access the contents of the signal data file
that a xPC Target scope of type file creates, use the xPC Target file system
object (xpctarget.fs) from a host PC MATLAB window. To view or examine
the signal data, you can use the readxpcfile utility in conjunction with the
plot function. For further details on the xpctarget.fs file system object
and the readxpcfile utility, see “Working with Target PC Files and File
Systems” in the xPC Target User’s Guide. Saving signal data to files lets you
recover signal data from a previous run in the event of system failure (such as
a system crash).
To add an xPC Target Scope block, see “Adding an xPC Target Scope Block”
on page 3-17.
3-31
3 Basic Tutorial
my_xpc_osc2
3 In the Scope number box, a unique number to identify the scope that
is displayed. This number is incremented each time you add a new xPC
Target scope. Normally, you do not want to edit this value.
This number identifies the xPC Target Scope block and the scope screen on
the host or target computer.
3-32
Simulink® Model
5 Select the Start scope when application starts check box to start a
scope when the target application is downloaded and started. The scope
window opens automatically.
3-33
3 Basic Tutorial
If you select Signal Triggering, then in the Trigger signal box, enter
the index of a signal. In the Trigger level box, enter a value for the signal
to cross before triggering. From the Trigger slope list, select either,
rising, or falling. You do not need to specify scope triggering.
If you select Scope Triggering, then in the Trigger scope number box,
enter the scope number of a Scope block. If you use this trigger mode, you
must also add a second Scope block to your Simulink model. You do not
need to specify signal triggering.
If you want the scope to trigger on a specific sample of the other scope,
enter a value in the Sample to trigger on box. The default value is 0 and
indicates that the triggering scope and the triggered (current) scope start
3-34
Simulink® Model
10 In the Filename box, enter a name for the file to contain the signal
data. By default, the target PC writes the signal data to a file named
C:\data.dat.
11 From the Mode list, select either Lazy or Commit. Both modes open a file,
write signal data to the file, then close that file at the end of the session.
With the Commit mode, each file write operation simultaneously updates
the FAT entry for the file. This mode is slower, but the file system always
knows the actual file size. With the Lazy mode, the FAT entry is updated
only when the file is closed and not during each file write operation. This
mode is faster, but if the system crashes before the file is closed, the file
system might not know the actual file size (the file contents, however,
will be intact). If you experience a system crash, you can expect to lose a
WriteSize amount of data.
12 In the WriteSize box, enter the block size, in bytes, of the data chunks.
This parameter specifies that a memory buffer of length Number of
samples write data to the file in WriteSize chunks. By default, this
parameter is 512 bytes, which is the typical disk sector size. Using a block
size that is the same as the disk sector size provides optimal performance.
14 Select the AutoRestart check box to enable the scope of type file to collect
data up to Number of samples, then start over again, appending the new
data to the end of the signal data file. Clear the AutoRestart check box to
have the scope of type file collect data up to Number of samples, then stop.
If the named signal data file already exists, the xPC Target software
overwrites the old data with the new signal data.
Your next task is to simulate the model. See “Simulating the Model” on page
3-37.
3-35
3 Basic Tutorial
The following sections describe how to simulate your model and run the target
application. With scopes of type file, the xPC Target software generates a
signal data file on the target PC after you run the target application. For
further details on working with these files, see “Working with Target PC Files
and File Systems” in the xPC Target User’s Guide.
3-36
Simulating the Model
For procedures to run your target application in real time, see “Running the
Target Application” on page 3-54.
my_xpc_osc2
3-37
3 Basic Tutorial
MATLAB loads the oscillator model and displays the Simulink block
diagram, as shown below.
3 From the Simulation menu, click Normal, and then click Start.
3-38
Simulating the Model
4 You can either let the simulation run to its stop time, or stop the simulation
manually. To stop the simulation manually, from the Simulation menu,
click Stop.
Your next task is to create an xPC Target application. See “xPC Target
Application” on page 3-43.
After you load your Simulink model into the MATLAB workspace, you can
run a simulation. This procedure uses the Simulink model my_xpc_osc2.mdl
as an example and assumes you have already loaded that model. To create
this model, see “Creating a Simple Simulink Model” on page 3-2.
sim('my_xpc_osc2')
3-39
3 Basic Tutorial
plot(tout,yout)
You entered the MATLAB variables tout and yout in the Data I/O pane
on the Configuration Parameters dialog box. The signals are logged to
memory through Outport blocks. To add an Outport block, see “Adding a
Simulink Outport Block” on page 3-10 and “Entering Parameters for the
Outport Blocks” on page 3-13.
3-40
Simulating the Model
MATLAB opens a plot window and displays the output response. The
signal from the signal generator is added to the Outport block and shown
in the figure below.
Note When your target application is running in real time, data is not saved
to the variables tout and yout. Instead, data is saved in the target PC
memory and can be retrieved through the target object properties tg.TimeLog,
tg.StateLog, and tg.OutLog. However, in the Configuration Parameters
dialog box, you must still select the Time, States, and Output check boxes
for data to be logged to the target object properties.
3-41
3 Basic Tutorial
Your next task is to create a target application. See “xPC Target Application”
on page 3-43.
3-42
xPC Target™ Application
After you have configured the xPC Target product using the xPC Target
Explorer and created a target boot disk for that setup, you can boot the
target PC. You need to boot the target computer before building your target
application because the build process automatically downloads your target
application to the target PC. Be sure that you have followed the instructions
from Chapter 2, “Installation and Configuration” before continuing.
1 Insert the target boot disk into the target PC disk drive.
3-43
3 Basic Tutorial
In the example above, the status window shows that the kernel is in loader
mode and waiting to load a target application. 1 MB of memory is reserved for
the application, 3 MB is used by the kernel, and 28 MB is available from a
total of 32 MB. The xPC Target kernel uses the 28 MB for the heap, running
scopes, and acquiring data.
Your next task is to enter the simulation and real-time run parameters for
Real-Time Workshop. See “Entering the Real-Time Workshop Parameters”
on page 3-45.
Possible Problem
When booting the target PC, it might display a message like the following
The target PC displays this message when it cannot read and load the kernel
from the target boot disk. The probable cause is a bad disk.
Solution. If you have a 3.5-inch target boot disk, reformat the disk or use a
new formatted floppy disk and create a new target boot disk. If you have a CD
target boot disk, create a new disk.
Possible Problem
When booting the target PC, you get a message similar to the following:
Solution. If the xPC Target Explorer window is not already open, open
it. In the MATLAB Command Window, type xpcexplr. In the xPC Target
Explorer xPC Target Hierarchy pane, select a target PC Configuration
node. For example, select the Configuration node for TargetPC1. In the
configuration pane, select your desired boot mode. Create a new boot disk or
network boot image.
3-44
xPC Target™ Application
After you load a Simulink model and boot the target PC, you can enter
the simulation parameters. This procedure uses the Simulink model
my_xpc_osc2.mdl as an example and assumes you have already loaded that
model (see “Simulink Model” on page 3-2).
my_xpc_osc2
MATLAB loads the oscillator model and displays the Simulink block
diagram, as shown below.
3-45
3 Basic Tutorial
3-46
xPC Target™ Application
If you have the Real-Time Workshop Embedded Coder, you can build an
ERT target application. To build an ERT target application, in the Target
selection section, click the Browse button at the System target file list.
Click xpctargetert.tlc, and then click OK.
Note that if the Real-Time Workshop Embedded Coder is not installed and
you select xpctargetert.tlc, the build fails.
7 From the Real-time interrupt source list, select a source. The default
value is Timer.
8 Select the Log Task Execution Time check box to log task execution
times to the target object property tg.TETlog.
The task execution time is the time in seconds to complete calculations for
the model equations and post outputs during each sample interval. If you do
not select this box, your average TET value appears as Not a Number (NaN).
9 In the Signal logging buffer size in doubles box, enter the maximum
number of sample points to save before wrapping, for example, 100000.
This buffer includes the time, states, outputs, and task execution time logs.
10 In the Name of xPC Target object created by build process box, enter
the name of the target object created by the build process. The default
target object name is tg.
3-47
3 Basic Tutorial
The Real-Time Workshop pane should now look like the figure shown.
11 Click OK.
3-48
xPC Target™ Application
12 From the File menu, click Save as. Enter a filename. For example, enter
my_xpc_osc3 and then click Save.
Your next task is to create (build) the target application. See “Building and
Downloading the Target Application” on page 3-49.
After you enter your changes in the Configuration Parameters dialog box, you
can build your target application. This procedure uses the Simulink model
my_xpc_osc3.mdl as an example. To create this model, see “xPC Target
Application” on page 3-43. By default, the build procedure downloads the
target application to the default target PC, as designated in the xPC Target
Explorer. See “xPC Target Options Node” on page 3-53 for further details on
setting the target PC for a target application.
3-49
3 Basic Tutorial
my_xpc_osc3
MATLAB loads the oscillator model and displays the Simulink block
diagram.
2 In the Simulink window and from the Tools menu, select Real-Time
Workshop. From the Real-Time Workshop submenu, click Build
Model.
tg
If you do not have a successful build, see “Troubleshooting the Build Process”
on page 3-51.
3-50
xPC Target™ Application
Your next task is to run the target application in real time on the target PC.
See “Running the Target Application” on page 3-54.
1 If the xPC Target Explorer is not already up, in the MATLAB window, type
xpcexplr
3-51
3 Basic Tutorial
For a working connection between the host PC and target PC, xPC Target
Explorer displays a pop-up dialog box.
You can increase the time-out value in one of the following ways.
3-52
xPC Target™ Application
tg.set('CommunicationTimeOut',20)
For both methods, the host PC waits for about 20 seconds before declaring
that a time-out has occurred. Note that it does not take 20 seconds for every
download. The host PC polls the target PC about once every second, and if a
response is returned, declares success. Only in the case where a download
really fails does it take the full 20 seconds.
• xpctarget.tlc
Generate code for an xPC Target target.
• xpctargetert.tlc
Generate code for an xPC Target target using the required Real-Time
Workshop Embedded Coder software.
The xPC Target Options node allow you to specify how the software
generates the target application. You might need to enter and select these
options before you create (build) a target application. However, the default
values of these options are reasonable for target application creation. See
“Configuration Parameters” in the xPC Target User’s Guide for a description
of the options on this node.
3-53
3 Basic Tutorial
Introduction
During the build process, the xPC Target software creates a target object that
represents the target application running on the target PC. The target object
is defined by a set of properties and associated methods. You control the
target application and computer by setting the target object properties.
For procedures to simulate your model in nonreal time, see “Simulating the
Model” on page 3-37.
xpcexplr
2 To connect to the target PC, right-click the target PC icon for which you
have downloaded the application and select Connect.
3-54
Running the Target Application
To view the model hierarchy for the downloaded application, one of the
following must be true:
• You must be in the same folder in which you build the target application.
Otherwise, xPC Target Explorer returns an error.
• When you built the target application, you selected the Include model
hierarchy on the target application check box in the xPC Target
Options pane.
If you are in the appropriate folder, a node for the target application
appears in the xPC Target Hierarchy under the target PC node and
displays information about the previously loaded target application.
3-55
3 Basic Tutorial
Note, if, in your current folder, you have a prebuilt target application that
you want to download to the target PC, left-click and drag the desired
target application to the target PC to which you want to download the
target application.
3 If you want to rebuild the current target application, in the xPC Target
Explorer window, right-click the target application node and select Go To
Simulink Model.
3-56
Running the Target Application
The xPC Target software recompiles, links, and downloads the target
application to the target PC.
5 Start the target application. For example, in the xPC Target Explorer
window, select the downloaded target application.
6 From the toolbar, click the Start Application button . The target
application begins running on the target PC, and stops when it reaches
the stop time.
7 With the target application still selected in the Target Hierarchy pane of
xPC Target Explorer, enter a new value for the Stop time value for the
application and click Apply. For example,
inf
3-57
3 Basic Tutorial
8 Again, click the Start Application button. The target application now
runs until you stop it.
See also “Signal Tracing with xPC Target Explorer” and “Signal Logging with
xPC Target Explorer” in the xPC Target User’s Guide.
• In your current working folder, you have a prebuilt target application that
you want to download to a target PC.
• You have installed xPC Target software and booted the target PC to which
you want to download a target application.
3-58
Running the Target Application
• You have a physical connection between the xPC Target Explorer host
machine and the target PC to which you want to download a target
application.
1 In the xPC Target Explorer, left-click the File menu. (Note that you can
also change this folder from the MATLAB window or by right-clicking the
DLM node.)
A browser is displayed.
3 Browse to the folder that contains the prebuilt target applications you want.
4 Click OK.
3-59
3 Basic Tutorial
5 In xPC Target Explorer, check that the DLM(s) node in the xPC Target
Hierarchy has the pathname of the folder that contains the prebuilt target
application you want to download to the target PC.
Target Application
Directory (DLMs)
6 Right-click a target PC that you booted with xPC Target software, for
example, TargetPC1.
7 Select Connect.
The target PC icon changes and the red X is removed . The target PC
information changes to reflect file system and PCI device information.
8 Left-click and drag the desired target application to the target PC to which
you want to download the target application.
3-60
Running the Target Application
xPC Target Explorer downloads the target application to the target PC. A
node for the target application appears in the xPC Target Hierarchy
under the target PC node.
Note If you want to rebuild or revisit the model, click the Go to Simulink
Model button. The Simulink model for the target application appears.
3-61
3 Basic Tutorial
The context menu appears and lists the operations you can perform on
the target application.
10 Select Start.
11 Stop the target application (described here) or let the target application run
to the end. To stop the target application, right-click the target application
node (for example, xpcosc) and select Stop from the list.
See also “Signal Tracing with xPC Target Explorer” and “Signal Logging
with xPC Target Explorer” within “Signals and Parameters” in the xPC
Target User’s Guide.
3-62
Running the Target Application
1 In xPC Target Explorer, select the node of the loaded target application in
which you are interested. For example, xpcosc.
The right pane changes to the target application properties pane for the
application.
• Stop time
• Sample time
• Log mode
3 Change the Stop time parameter to 9999. Click Apply. For example,
3-63
3 Basic Tutorial
After the xPC Target software downloads your target application to the target
PC, you can run the target application. This procedure uses the Simulink
model my_xpc_osc3.mdl as an example, and assumes you have created and
downloaded the target application for that model. It also assumes that you
have assigned tg to the appropriate target PC.
The target application starts running on the target PC. In the MATLAB
window, the status of the target object changes from stopped to running.
3-64
Running the Target Application
xPC Object
Connected = Yes
Application = my_xpc_osc3
Mode = Real-Time Single-Tasking
Status = running
The xPC Target software allows you to change many properties and
parameters without rebuilding your target application. Two of these
properties are StopTime and SampleTime.
3 Change the stop time. For example, to change the stop time to 1000
seconds, type either
4 Change the sample time. For example, to change the sample time to 0.01
seconds, type either
Although you can change the sample time between different runs, you can
only change the sample time without rebuilding the target application under
certain circumstances.
3-65
3 Basic Tutorial
If you choose a sample time that is too small, a CPU overload can occur. If
a CPU overload occurs, the target object property CPUOverload changes to
detected. In that case, change the Fixed step size in the Solver node to
a larger value and rebuild the model. (See “User Interaction” on page 1-27
for further limitations on changing sample times.)
Note Do not use Simulink external mode while xPC Target Explorer is
running. Use only one interface or the other.
After you create and download a target application to the target PC, you
can run the target application. This procedure uses the Simulink model
my_xpc_osc2.mdl as an example (see “Building and Downloading the Target
Application” on page 3-49). It assumes that you have specified the correct
target PC environment on the xPC Target options node of the Real-Time
Workshop parameters dialog. In particular, you must specify the target PC to
which you want to connect. See the Use the default target PC check box
description in “xPC Target Options Node” on page 3-53.
1 In the Simulink window, and from the Simulation menu, click External.
A check mark appears next to the menu item External, and Simulink
external mode is activated. Simulink external mode connects your Simulink
model to your target application as a simple graphical user interface.
2 In the Simulink window, and from the Simulation menu, click Connect
to target.
3-66
Running the Target Application
tg.stop or -tg
You cannot stop the target application from the Simulink window by clicking
Stop real-time code from the Simulation menu.
Note Opening a dialog box for a source block causes Simulink to pause. While
Simulink is paused, you can edit the parameter values. You must close the
dialog box to have the changes take effect and allow Simulink to continue.
3-67
3 Basic Tutorial
You can build models using a local PC, or using PCs running Windows
systems (remote workers). Depending on how you want to build, the following
products must be installed:
See “Reducing Build Time for Referenced Models” in the Real-Time Workshop
User’s Guide for a description of how to build referenced models in parallel
with a local host or a pool of remote workers.
1 Ensure that each remote worker has the same compiler configuration.
For example, all remote PCs must have the same compiler version and
installation path as the host PC..
2 Ensure that each remote worker has the xPC Target software installed.
3 After you call the matlabpool command to start the pool of remote workers,
in the MATLAB Command Window of the host PC, call the pctRunOnAll
command. This command configures the compiler for all the remote
workers. For example type a sequence like the following all on one line:
pctRunOnAll('setxpcenv(''CCompiler'',''VisualC'',''CompilerPath'',
''C:\Program Files\Microsoft Visual Studio 9.0'')')
3-68
Menu Bar and Toolbar Contents and Shortcut Keys
The xPC Target Explorer menu bar has the following menus:
3-69
3 Basic Tutorial
The xPC Target Explorer toolbar has buttons for some of the more commonly
used operations available from the menu bar. These buttons include
Button Description
Add Target button
3-70
Menu Bar and Toolbar Contents and Shortcut Keys
Button Description
Scope Viewer button
Action Shortcut
Add target Ctrl+A
Remove target Ctrl+R
Close Ctrl+W
Stop/start target Ctrl+T
Ping target Ctrl+P
Delete scope Select scope and click Delete
3-71
3 Basic Tutorial
3-72
Glossary
Glossary
application
See target application.
build process
Process of generating a target application from your Simulink model,
compiling, linking, and downloading the generated code to create a
target application.
execution
Running the target application on the target PC in real time.
executable code
See target application.
kernel
Real-time software component running on the target PC that manages
the downloaded target application.
model
Simulink and/or Stateflow model.
parameter tuning
Process of changing block parameters and downloading the new values
to a target application while it is running or not running.
sample rate
Rate the target application is stepped in samples/second. Reciprocal
of the sample time.
sample time
Interval, in seconds, between the execution of target application steps.
signal logging
Acquiring and saving signal data created during a real-time execution.
signal monitoring
Getting the values of one or more signals without time information.
Glossary-1
Glossary
signal tracing
Acquiring and displaying packages of signal data during real-time
execution.
simulation
Running a simulation of the Simulink and Stateflow model on the host
PC in nonreal time.
target application
Executable code generated from a Simulink and Stateflow model, which
can be executed by the xPC Target kernel on the target PC.
Glossary-2
Index
A
Index CD target boot disk
advantages of network communication 1-16 creating 2-49
analog input (A/D) code generation options
driver support 1-17 for Real-Time Workshop 3-45
analog output (D/A) reference 3-53
driver support 1-17 COM API 1-34
API command-line interface
custom GUI 1-34 MATLAB 1-29
API for Microsoft .NET framework 1-33 target PC 1-32
communication
between computers 1-20
B network 2-25
before you boot network advantages 1-16
checklist 2-45 serial 2-37
BIOS compiler
target PC 1-5 required 2-4
BIOS settings 2-13 computer
block parameters communication 1-20
scope 3-21 desktop PC for host 1-13
boot options 2-44 desktop PC for target 1-14
boot floppy disk 2-52 host PC 1-13
CD 2-46 industrial PC 1-14
dedicated network 2-55 notebook PC 1-13
booting PC/104 and PC/104+ 1-14
target PC 3-43 target PC 1-14
troubleshooting 3-44 connections
build process computers 1-15
target application 3-49 I/O boards 1-17
troubleshooting 3-51 real-world 1-17
controlling target applications
with MATLAB 3-64
C
with Simulink external mode 3-66
C compiler counter timers
network setup 2-30 driver support 1-17
required product 2-4 creating boot media
serial setup 2-39 checklist 2-45
CAN field bus creating CD target boot disks 2-49
driver support 1-17 creating target applications 3-43
CD creating target boot disks 2-54
creating for booting 2-46 creating target objects 3-49
Index-1
Index
Index-2
Index
H hardware 2-37
hardware environment network communication 2-25
requirements for target PC 2-10 on the host PC 2-15
hardware-in-the-loop process 1-24 serial communication 2-37
host computer testing 2-62
see host PC 1-13 ISA bus
host PC 2-15 Ethernet card 2-28
communication 1-20
configuring 2-19 K
connections 1-15
kernel
downloading software 2-15
target boot disk 1-5
files 2-16
target PC BIOS 1-5
hardware 2-37
xPC Target 1-5
license file 2-15
requirements 2-8
L
I license
obtaining 2-16
I/O boards
supported by xPC Target 1-17
I/O driver support M
analog input (A/D) 1-17 MathWorks
analog output (D/A) 1-17 technical support 2-68
CAN field bus 1-17 valid license 2-16
counter timers 1-17 MATLAB
digital 1-17 controlling target application 3-64
encoder 1-17 required product 2-2
GPIB 1-17 MATLAB Compiler support 1-11
RS-232 1-17 memory model
RS-422 1-17 target application 1-8
RS-485 1-17
shared memory 1-17
UDP 1-17 N
industrial PC 1-14 network boot 2-55
initial working folder 2-17 network communication
installation prerequisite advantages 1-16
obtaining a valid license 2-16 environment 2-30
installing hardware 2-25
Ethernet card for ISA 2-28 host PC 2-25
Ethernet card for PCI 2-27 installing and setting up 2-25
Index-3
Index
Index-4
Index
Index-5
Index
Index-6