Clocks Analog Inputs Analog Outputs Digital Inputs Digital Outputs Encoder Inputs PWM Outputs Other Inputs Other Outputs Interrupts Watchdog Board-Specific Options Properties Targets See Also navigation bar

Quanser Q2-USB

The Quanser Q2-USB is an innovative, low-cost, and portable H.I.L. control board with a basic range of input and output support. A wide variety of devices with analog and digital sensors as well as quadrature encoders are easily connected to the Quanser Q2-USB. For more information, visit the website for the Quanser Q2-USB.

The features of the Quanser Q2-USB are:

Hint

USB devices are packet based, so all information is read and written in a single packet at once. To use your DAQ most efficiently, try to use just a single hil_read call and a single hil_write/hil_task_write call.

The QUARC driver name for this card is q2_usb.

Clocks

The Quanser Q2-USB supports has a single hardware "clock", as well as one system timer. The system timer has 1ms resolution. The hardware clock is actually the USB data rate from which the diagram can base its timing. Its functionality is fixed as a hardware time base, though there are some limited configuration options in the Board-Specific Options. Theoretically, if you use the hardware time base using a HIL Read Timebase, you can achieve any timebase that is a multiple of 125us (8kHz), but realistically for most computers, the limit is 1000us (1kHz) to 500us (2kHz).

Analog Inputs

The Quanser Q2-USB supports two 12-bit single-ended analog inputs with a ±10V range. Hence analog channel numbers range from 0 to 1.

The range of the analog inputs is fixed at ±10V.

Analog Outputs

The Quanser Q2-USB supports two 12-bit single-ended analog outputs with a ±10V range. Hence analog channel numbers range from 0 to 1.

To set the analog output values when the watchdog expires, use the hil_watchdog_set_analog_expiration_state function.

Warning

Each analog output can source up to 5mA of current and maintain the specifications listed in the user manual.

Digital Inputs

The Quanser Q2-USB supports 8 bidirectional digital I/O lines. Hence digital input channel numbers range from 0 to 7. A digital I/O line cannot be used as an input and output at the same time.

Since the digital I/O lines may be individually programmed as inputs or outputs on the Quanser Q2-USB, all of those 8 channels which will be used for digital inputs should be configured using the hil_set_digital_directions function. Set the input_channels argument to all the digital I/O channels that will be used as digital inputs on the board.

Digital Outputs

The Quanser Q2-USB supports 8 bidirectional digital I/O lines and 1 LED. Hence digital output channel numbers range from 0 to 8. A digital I/O line cannot be used as an input and output at the same time. The LED can be controlled as digital output 8 when configured for user mode with the Board-Specific Options.

Since the digital I/O lines may be individually programmed as inputs or outputs on the Quanser Q2-USB, all the channels which will be used for digital outputs must be configured using the hil_set_digital_directions function. Set the output_channels argument to all the digital I/O channels that will be used as digital outputs on the board.

Hint

If you do not set the digital directions, the card will default to inputs. However, this will not prevent a hil_write_digital call from writing to those digital outputs. This can be used to preinitialize the outputs if you switch from digital input to digital output at a later point in time.

To set the digital output states when the watchdog expires, use the hil_watchdog_set_digital_expiration_state_c function. States 0 (low), 1 (high), and 3 (leave at the current state) are supported by the Quanser Q2-USB.

Warning

Each digital output can source or sink up to 4mA of current maximum at 3.3V. Do not exceed these maximums!

Encoder Inputs

The Quanser Q2-USB supports two quadrature encoder inputs with 16-bit count values. Hence encoder channel numbers range from 0 to 1.

Set the encoder counters to a particular count using the hil_set_encoder_counts function.

The Quanser Q2-USB only supports the 4X quadrature mode. Since the Quanser Q2-USB has 16-bit counters, valid initial count values range from -32,768 to +32,767.

PWM Outputs

The Quanser Q2-USB driver supports two PWM output channels. The PWM outputs are shared with digital I/O lines 0 and 1. To change from digital function to PWM function, you must first set the appropriate Board-Specific Options.

These two channels are driven by independent timebases so they may operate at different frequencies and in different modes. The PWM base frequencies can range from 2.384Hz up to 40MHz. The resolution of your PWM can be as high as 16-bits or as low as 1-bit depending on the selected frequency. Use the PWM configuration wizard (the "..." button to the right of any of the active PWM fields on the PWM Outputs tab) to get more information about what resolution you will get at what frequencies.

The PWM output channels support mode 0 (duty cycle, fixed frequency), and mode 4 (active pulse time, fixed frequency). Both modes will only update after a given cycle is complete to ensure "glitchless" transitions. Therefore, for slow base frequencies, it may take several samples of your model before the update is seen on the output. RC servos for instance typically run with a period of 20ms, so a 1ms controller may need to wait up to 20 samples before the desired output is observed.

To set the PWM output values when the watchdog expires, set the PWM outputs on watchdog expiry to states to match the channel assignments in the PWM output channels field.

Warning

Each PWM output can source or sink up to 4mA of current maximum at 3.3V. Do not exceed these maximums!

Other Inputs

The Quanser Q2-USB card does not support other inputs.

Other Outputs

The Quanser Q2-USB card does not support other outputs.

Interrupts

The Quanser Q2-USB card, or its driver, does not support any interrupt sources.

Watchdog

The Quanser Q2-USB supports the watchdog functionality with a dedicated timer. The timer may be programmed with any interval between 125us and 8.1 seconds. The board is capable of resetting the analog outputs, digital outputs and PWM outputs to any state upon expiration of the watchdog timer. Resetting of the outputs occurs without software intervention, and therefore may be used as a safety mechanism in the event of software failure.

To enable the resetting of the analog, digital or PWM outputs, configure the output values for each of the channels using the hil_watchdog_set_analog_expiration_state, hil_watchdog_set_digital_expiration_state and hil_watchdog_set_pwm_expiration_state functions respectively. Then use the hil_watchdog_start function to start the watchdog timer. Be sure to reload the watchdog timer periodically using the hil_watchdog_reload function to prevent it from expiring under normal operation.

Once the watchdog has expired, further output is disabled until the watchdog state is cleared. To clear the watchdog state, use the hil_watchdog_clear function. Stop the watchdog using the hil_watchdog_stop function. Note that stopping the watchdog does not clear the watchdog state. The watchdog state must be cleared explicitly.

Board-Specific Options

The Quanser Q2-USB has a number of board-specific options to control specialized functionality of the card. These options control the PWM configuration and the ability to change the USB communications bandwidth.

d0

This option configures line 0 of the digital I/O to digital input or output (digital) or PWM (pwm). Note that if the line is configured as pwm, this will supersede any digital input or output settings. By default, it is configured as a digital line.

d1

This option configures line 1 of the digital I/O to digital input or output (digital) or PWM (pwm). Note that if the line is configured as pwm, this will supersede any digital input or output settings. By default, it is configured as a digital line.

update_rate

This option is used to set the base rate for the hardware time base. The (normal) rate will use a 1ms (1khz) base rate. Alternatively, for higher speeds and lower latencies, the fast rate can be will use a 125us (8kHz) base rate. Your model may use a sample period of any multiple of these base rates. Using a 1ms sample rate for your model will work with either the fast or slow option for instance, but you should get lower latencies with the fast option. Using the fast mode will result in higher CPU utilization for the communications though.

Warning

It is recommended to use (normal) rate when running on non-Windows targets.

led

This option is used to switch between the default DAQ controlled use (auto) of the LED (see the Q2-USB user manual for details) or a user controlled mode (user). By default, it is configured for the DAQ controlled use.

decimation

Defaults to 1. This is an advanced feature that is designed to allow task reads and writes to only occur every N samples of the hardware timebase. At a decimation of 10 for instance, the DAQ will only read and write once every 10 samples. A typical scenario is that you want to run a simulation of your physical system at a higher resolution than your sample rate (particularly with a slower DAQ). Assume your DAQ is capable of a maximum of 1kHz, but you require the model to be simulated at 10kHz. Set your clock frequency in hil_task_start to 10kHz and the decimation option in the hil_set_card_specific_options to 10. When the task is started, the first sample will read and write to the DAQ. The next 9 samples will be executed as quickly as possible. Data read will be repeated, and writes will be ignored. The 11th sample will now wait on the hardware timebase, resynchronizing the task to real-time. When the hardware timebase occurs, new data will be sampled by the hil_task_read call and the current outputs will be output by the hil_task_write call.

Properties

The Quanser Q2-USB card does not support any properties.

Targets

Target

Supported

Comments

QUARC Win32 Target

Yes

Fully supported.

QUARC Win64 Target

Yes

Fully supported.

QUARC Linux Nvidia Target

Yes*

Support for this target is in beta. If you are using it, we would appreciate any feedback.

QUARC Linux Raspberry Pi 3 Target

Yes*

Support for this target is in beta. If you are using it, we would appreciate any feedback.

QUARC Linux Raspberry Pi 4 Target

No

Not supported.

QUARC Linux RT ARMv7 Target

No

Not supported.

QUARC Linux x64 Target

No

Not supported.

QUARC Linux DuoVero Target

No

Not supported.

QUARC Linux DuoVero 2016 Target

No

Not supported.

QUARC Linux Verdex Target

No

Not supported.

QUARC QNX x86 Target

No

Not supported.

Rapid Simulation (RSIM) Target

Yes

Supported with no communication to the hardware.

Normal simulation

Yes

Supported with no communication to the hardware.

See Also

 

navigation bar