| xPC Target™ | ![]() |
| On this page… |
|---|
The xPC Target environment is a solution for prototyping, testing, and deploying real-time systems using standard PC hardware. In support of this, the software allows you to add I/O blocks to your model. The blocks of the xPC Target library provides a particular function of an I/O board. By using I/O blocks in your model, you can generate executable code tuned specifically for your hardware.
You add I/O driver blocks to your Simulink® model to connect your model to physical I/O boards. These I/O boards then connect to the sensors and actuators in the physical system.
In addition to the blocks contained in the xPC Target library, you can also use third-party driver blocks in your xPC Target model. The description of these blocks is beyond the scope of the xPC Target documentation. See the provider of the third-party driver blocks for information on those boards and driver blocks.
A driver block does not represent an entire board, but an I/O section supported by a board. Therefore, the xPC Target library can have more than one block for each physical board. I/O driver blocks are written as C-code S-functions (noninlined S-functions). The source code for the C-code S-functions is included with the xPC Target software.
Note, if your model contains I/O blocks, take hardware latency values into account for the model sample time. Use the xPC Target Interactive Guide tool to find latency values for the supported boards:
The xPC Target system supports PCI and ISA buses. If the bus type is not indicated in the driver block number, you can determine the bus type of a driver block by checking the block's parameter dialog box. The last parameter is either a PCI slot, for PCI boards, or a base address, for ISA boards.
You can open the I/O device driver library with the MATLAB® command xpclib. The library xpclib contains sublibraries grouped by the type of I/O function they provide.
Note Opening a dialog box for a source block causes the Simulink software to pause. While the Simulink software is paused, you can edit the parameter values. You must close the dialog box to have the changes take effect and allow the Simulink software to continue. In particular, hardware input blocks in the xPC Target library (blocks that acquire data from hardware) are affected by this change. |

This window also contains the following blocks:
xPC Target Driver Demos — When you double-click this block, the Demos tab in the MATLAB Help Navigator opens, displaying the xPC Target demos and demo groups.
Help for xPC Target — When you double-click this block, the xPC Target roadmap page is displayed. You can access the xPC Target documentation with this block.
Note The xPC Target documentation describes only the xPC Target blocks. It does not describe the actual board. Refer to the board manufacturer documentation for information about the boards. |
When you double-click one of I/O block groups, the sublibrary opens, displaying a list grouped by manufacturer as shown below.

Double-clicking one of the manufacturer groups then displays the set of I/O device driver blocks for the specified I/O functionality (for example, A/D, D/A, Digital Inputs, Digital Outputs, and so on).
The following figure shows the A/D drivers for the manufacturer Measurement Computing, Inc.

When you double-click one of these blocks, a Block Parameters dialog box opens, allowing you to enter hardware-specific parameters. Parameters typically include
Sample time
Number of channels
Voltage range
PCI slot (PCI boards)
Base address (ISA boards)
Some supported boards in the xPC Target I/O library are memory-mapped devices, for example, Burr-Brown boards. These memory-mapped boards are accessed in the address space between 640 K and 1 MB in the lower memory area. The xPC Target software reserves a 112 KB memory space for memory-mapped devices in the address range
C0000 - DBFFF
Some drivers for memory-mapped devices allow you to select an address range supported by the device, but not supported by the xPC Target software. For example, the CAN drivers for Softing allow you to select memory ranges above DBFFF. Base addresses of memory-mapped devices must be chosen within this memory space for your target application to work properly. Select a memory range supported by both the device and the xPC Target software.
There are two types of ISA boards:
Jumper addressable ISA cards
PnP (Plug and Play) ISA cards
The xPC Target software only supports jumper addressable ISA cards (non-PnP ISA boards) where you have to set the base address manually.
The xPC Target I/O library supports I/O boards with a PCI bus. During the boot process, the BIOS creates a conflict-free configuration of base addresses and interrupt lines for all PCI devices in the target system. The user does not need to define any base address information in the dialog boxes of the drivers.
All PCI device driver blocks have an additional entry in their dialog boxes. This entry is called PCI Slot (-1 Autodetect) and allows you to use several identical PCI boards within one target system. This entry uses a default value of -1, which allows the driver to search the entire PCI bus to find the board. If you specify a single number, X, greater than 0, the driver uses the board in bus 0, slot X. When more than one board of the same type is found, you must use a designated slot number and avoid the use of autodetection. For manually setting the slot number you use a number greater than or equal to 0. If the board is not able to locate this slot in the target PC, your target application will generate an error message after downloading.
If this additional entry is set to any value equal to or greater than 0, you must be aware of the manufacturer's identification number (Vendor ID) and the board identification number (Device ID) of those boards supported by the I/O library. When the target is booted, the BIOS is executed and the target PC monitor shows parameters for any PCI boards installed on the target PC. An example is shown below:
Bus No | Device No. | Func. No. | Vendor ID | Device ID | Device Class | IRQ |
0 | 4 | 1 | 8086 | 7111 | IDE controller | 14/15 |
0 | 4 | 2 | 8086 | 7112 | Serial bus controller | 10 |
0 | 11 | 0 | 1307 | 000B | Unknown PCI device | N/A |
1 | 0 | 0 | 12D2 | 0018 | Display controller | 11 |
In this example, the third line indicates the location of the Measurement Computing™ PCI-DIO48 board. This is known since the Measurement Computing vendor ID is 0x1307 and the device ID is 0xb. In this case, you now can see that the Measurement Computing board is plugged into PCI slot 11 (Device No.), and that this value must be entered in the dialog box entry in your I/O device driver for each model that uses this I/O device.
Properties for xPC Target I/O drivers are usually defined using the parameter dialog box associated with each Simulink block. However, for more advanced drivers, the available fields defined by text boxes, check boxes, and pull-down lists are inadequate to define the behavior of the driver. In such cases, a more textual description is needed to indicate what the driver has to do at runtime. Textual in this context refers to a programming-language-like syntax and style.
The xPC Target software currently uses a string description contained in message structures for the conventional RS-232, GPIB, CAN (initialization), and the general counter drivers (AMD9513).
What is a message structure? — A message structure is a MATLAB array with each cell containing one complete message (command). A message consists of one or more statements.
| First Message | Second Message | Third Message |
|---|---|---|
| Message(1).field | Message(2).field | Message(3).field |
| Message(1).field | Message(2).field | Message(3).field |
| Message(1).field | Message(2).field | Message(3).field |
Syntax of a message statement — Each statement in a message has the following format:
Structure_name(index).field_name = <field string or value>
The field names are defined by the driver, and need to be entered with the correct upper- and lowercase letters. However, you can choose your own structure name and enter that name into the driver parameter dialog box.
Creating a message structure — You could enter the message structure directly in the edit field of the driver parameter dialog box. But because the message structure is an array and very large, this becomes cumbersome very easily.
A better way is to define the message structure as an array in an M-file and pass the structure array to the driver by referencing it by name. For example, to initialize an external A/D module and acquire a value during each sample interval, create an M-file with the following statements:
Message(1).senddata='InitADConv, Channel %d' Message(1).inputports=[1] Message(1).recdata='' Message(1).outputports=[] Message(2).senddata='Wait and Read converted Value' Message(2).inputports=[] Message(2).recdata='%f' Message(2).outputports=[1]
This approach is different from other xPC Target driver blocks:
The M-file containing the definition of the message structure has to be executed before the model is opened.
After creating your Simulink model and message M-file, set the preload function of the Simulink model to load the M-file the next time you open the model. In the MATLAB window, type
set_param(gcs, 'PreLoadFcn', 'M-file_name')
When you move or copy the model file to a new directory, you also need to move or copy the M-file defining the message structure.
During each sample interval, the driver block locates the structure defined in the Block Parameters dialog box, interprets the series of messages, and executes the command defined by each message.
Specific drivers and structures — For detailed information on the fields in a message structure, see the following chapters in this document:
In PWM and FM driver blocks, your control over the output frequency and duty cycle is not always precise. In particular, these values are affected by the way that the base frequency is selected, as described in this section. The base frequency value is exact.
At the beginning of each sample time, two unsigned 16-bit integers, n and m, are computed based on the block parameters and the current values of the input signals. During the current sample period, the output signal is held high for m cycles of the base frequency, low for the next n-m cycles, high for the next m cycles, and so forth.

For a base frequency b, this results in a rectangular output signal of frequency b/n and duty cycle m/n. Because m and n must be integers, it is not possible to provide a continuous range of output frequencies and duty cycles with perfect exactness.
For example, assume that you want to configure an FM block with a duty cycle (m/n) of 1/2. The input signal f to this block is a relative frequency. It specifies an output frequency of b x f. Because m and n must be integers, it is not always possible to find values of m and n such that f will equal b/n exactly and n will equal 2 x m (duty cycle m/n = 1/2) exactly. Such an exact match is only possible when the input signal f equals 1/4, 1/6, 1/8, and so forth. The output frequencies for the intervening input signal f values are approximate. The errors are smaller as f approaches 0 and larger as f approaches 1.
Hint, to achieve the smallest margin of error, select the largest possible base frequency. The fact that n and m must be 16-bit integers imposes a lower limit of b / (216 - 1) on the frequencies that can be generated using a given base frequency.
The typical xPC Target block documentation briefly describes the supported board, then describes the parameters for each of the blocks that support the board. Included in the documentation for each board is a board characteristics table. Board characteristics tables can include the following information:
| Characteristic | Specifies... |
|---|---|
| Board name | Name of the board supported by the blocks. For example, National Instruments® PCI-6221. |
| Manufacturer | Manufacturer of the board. For example, National Instruments. |
| Bus type | Bus that is used by the board. For example, PCI or ISA. |
| Access method | Whether the board is memory mapped or I/O mapped. |
| Multiple block instance support | If you can use multiple blocks for the same function on the same board. For example, different blocks for different channels of an A/D device. |
| Multiple board support | If you can use multiple boards of the same type in one target application. |
![]() | xPC Target I/O Library | Adding I/O Blocks with the xPC Target Library | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |