QUARC Monitor Communications navigation bar

Table of Contents > QUARC > User's Guide

Accessing Hardware

QUARC supports a variety of data acquisition cards, including Quanser's own Q4 and Q8 Hardware-in-the-Loop (HIL) boards, the National Instruments PCI-6259 and many more. Hardware connected to these boards can be accessed by simply placing the appropriate blocks in your Simulink diagram. More specifically, the blocks found in the Simulink Library Browser under the QUARC Targets/Data Acquisition/Generic library are designed such that once placed in a Simulink diagram, you are only a few clicks away from interacting with your hardware, whether it is reading one or more analog channels or writing to digital channels. In addition, as will be explained in detail, these blocks are board-independent, meaning that changing boards does not require replacing all the associated blocks in the Simulink diagram.

The blocks used to access hardware may be divided into three categories as listed below.

Before starting to explain each of the HIL block categories above, the HIL Initialize block needs to be explained since this block has to be placed in all models that require hardware access regardless of the type of board being used or the type of access required.

HIL Initialize Block

This block can be found in the Simulink Library Browser under the QUARC Targets/Data Acquisition/Generic/Configuration library and should be placed in all models that require hardware access of some type. The block initializes a HIL board and associates a name with the board. The dialog box for the HIL Initialize block is depicted in the figure below.

The HIL Initialize block associates a board name with a particular HIL board. For example, in the figure above the name HIL-1 has been assigned to the Q8 board. The name assigned to each board will appear in the list of boards for every other HIL block in the diagram. This naming scheme is actually a great advantage because this property of the HIL Initialize block makes switching between different HIL boards as simple as changing the board type in the dialog box for this block. All other HIL blocks are designed to be board-independent.

An important function of the HIL Initialize block is to configure the I/O on the card. For example, many cards allow the digital I/O lines to be programmed as inputs or outputs. The Digital Inputs and Digital Outputs tabs are used to configure which digital I/O lines are inputs and outputs respectively. Similarly, many cards permit the range of the analog inputs and outputs to be programmed. The Analog Inputs and Analog Outputs tabs are used for this purpose. Many other features of data acquisition cards are configured using the tabs of the HIL Initialize block. Be sure to check the settings on each tab carefully to ensure that your card is set up properly.

Please refer to the HIL Initialize block reference page for details on this block.

Immediate I/O HIL Blocks

These blocks are found in the Simulink Library Browser under the QUARC Targets/Data Acquisition/Generic/Immediate I/O library. The immediate I/O blocks read from or write to the specified channels every time the block is executed. The channels are read from or written to immediately. In control applications where reads from hardware such as sensors and writes to hardware such as motors are required, the immediate I/O blocks can be used in a configuration similar to the one shown below to achieve the control objective. Please keep in mind that this figure serves as an illustration only and does not necessarily implement a complete control system. In addition remember that the HIL Initialize block should always be included in models that require hardware access, as mentioned earlier.

As seen in the above figure, the HIL Read block has been used to read analog, encoder and digital channels of the connected data acquisition board. The immediate I/O blocks read these channels immediately every time they are executed. The values read are manipulated in the Controller Sub-system and the calculated control commands are written to the data acquisition board's analog and digital channels. Reading from and writing to the channels seen in the figure above could also have been done using the HIL Read Analog, HIL Read Encoder, HIL Read Digital, HIL Write Analog and HIL Write Digital blocks separately, as illustrated below. However, in situations where different channels are being read using the immediate I/O blocks, it is more efficient to have a single HIL Read block rather than using multiple immediate I/O blocks specific to each channel type. The same principle applies to writing to different channel types where having a single HIL Write block is more efficient than using channel specific immediate I/O blocks. Not all boards support the HIL Read and HIL Write blocks though.

For more information about each of the available immediate I/O blocks, please refer to the Immediate I/O section of the Generic HIL Blocks page.

Buffered I/O HIL Blocks

These blocks are found in the Simulink Library Browser under the QUARC Targets/Data Acquisition/Generic/Buffered I/O library. The buffered I/O blocks can be used to read in buffered data. This can be done by specifying the number of samples to be buffered (ie. buffer size) in the dialog box associated with the block. The specified number of samples are then read at the given sampling rate and buffered. These values are output from the block once all the samples have been read. This property of the buffered I/O blocks makes them more suitable for data acquisition applications rather than control because they process inputs in bulk as opposed to one sample at a time.

If different channels such as analog, digital or encoder are to be read with the buffered I/O HIL blocks, it is more efficient to have a single HIL Read Buffer block rather than using multiple buffered I/O blocks specific to each channel type. The dialog box for the HIL Read Buffer block is depicted below.

As seen in the figure above, the dialog box gives you the ability to specify all the different channel types to be read at one time. Clearly the channel numbers to be read should be specified for each channel type under the appropriate field. As mentioned earlier, the buffer size can be specified under the Number of samples field. For more information about each of the available buffered I/O blocks, please refer to the Buffered I/O section of the Generic HIL Blocks page.

Timebase HIL Blocks

These blocks are found in the Simulink Library Browser under the QUARC Targets/Data Acquisition/Generic/Timebases library. The timebase blocks read from or write to the specified channels at the sampling rate of the model and act as a timebase for the model. More specifically, whenever hardware is accessed via the Timebase HIL blocks, acquisition timing is done by a timebase on the data acquisition card rather than the QUARC system timebase. On the Windows target, use of a hardware timebase results in better performance because hardware timebases are more efficient than the QUARC system timebase on the Windows target (at least for sample times faster than two milliseconds).

It should be noted that you can only have one timebase block in a Simulink model. More than one timebase block per Simulink model is not supported since using two separate timebases to interrupt the same model will result in incorrect execution and possible instability.

Similar to buffered and immediate I/O HIL blocks, if more than one channel type is being read using the HIL Timebase blocks, it is more efficient to use a single HIL Read Timebase block rather than using one timebase for a specific channel type and multiple immediate I/O read blocks specific to the other channel types. The same principle applies to writing to different channel types where having a single HIL Write Timebase block is more efficient than using one channel-specific HIL Timebase block and multiple immediate I/O blocks. The dialog box for the HIL Write Timebase block is shown below.

As seen in the figure above, the dialog box gives you the ability to specify all channel types to be written to at once. Clearly the channel numbers to be written to should be specified for each channel type under the appropriate field. For more information about each of the available HIL Timebase blocks, please refer to the Timebases section of the Generic HIL Blocks page.

 

navigation bar