cbSetTrigger()

Selects the trigger source and sets up its parameters. This trigger is used to initiate a scan using the following Universal Library functions:

Function prototype

C/C++

int cbSetTrigger(int BoardNum, int TrigType, unsigned short LowThreshold, unsigned short HighThreshold);

Visual Basic

Function cbSetTrigger(ByVal BoardNum&, ByVal TrigType&, ByVal LowThreshold%, ByVal HighThreshold%) As Long

Arguments

BoardNum

The number associated with the board when it was installed with InstaCal or created with cbCreateDaqDevice(). BoardNum may be 0 to 99. The board must have a software-selectable triggering source and/or options.

TrigType

Specifies the type of triggering based on the external trigger source. Set it to one of the constants in the TrigType argument values section below.

LowThreshold

Selects the low threshold used when the trigger input is analog. The range depends upon the resolution of the trigger circuitry. Must be 0 to 255 for 8-bit trigger circuits, 0 to 4,095 for 12-bit trigger circuits, and 0 to 65,535 for 16-bit trigger circuits. Refer to the Analog Trigger Notes section below.

When the trigger input is a digital pattern, LowThreshold selects the pattern value.

HighThreshold

Selects the high threshold used when the trigger input is analog. The range depends upon the resolution of the trigger circuitry. Must be 0 to 255 for 8-bit trigger circuits, 0 to 4,095 for 12-bit trigger circuits, and 0 to 65,535 for 16-bit trigger circuits. Refer to the Analog Trigger Notes section below.

When the trigger input is a digital pattern, HighThreshold selects the port mask.

Returns

TrigType argument values

Trigger sourceTypeExplanation
AnalogGATE_NEG_HYSScanning is enabled as long as the external analog trigger input is more positive than HighThreshold. Hysteresis is the level between LowThreshold and HighThreshold.
GATE_POS_HYSScanning is enabled as long as the external analog trigger input is more negative than LowThreshold. Hysteresis is the level between LowThreshold and HighThreshold.
GATE_ABOVEScanning is enabled as long as the external analog trigger input is more positive than HighThreshold.
GATE_BELOWScanning is enabled as long as the external analog trigger input is more negative than LowThreshold.
GATE_IN_WINDOWScanning is enabled as long as the external analog trigger is inside the region defined by LowThreshold and HighThreshold.
GATE_OUT_WINDOWScanning is enabled as long as the external analog trigger is outside the region defined by LowThreshold and HighThreshold.
TRIG_ABOVEScanning begins when the external analog trigger input transitions from below HighThreshold to above. Once conversions are enabled, the external trigger is ignored.
TRIG_BELOWScanning begins when the external analog trigger input transitions from above LowThreshold to below. Once conversions are enabled, the external trigger is ignored.
TRIG_RISINGScanning begins when the external analog trigger input transitions from below LowThreshold to above HighThreshold. Once conversions are enabled, the external trigger is ignored.
TRIG_FALLINGScanning begins when the external analog trigger input transitions from above HighThreshold to below LowThreshold. Once conversions are enabled, the external trigger is ignored.
Analog Trigger Notes
  • The value of the threshold must be within the range of the analog trigger circuit associated with the board. Refer to the board-specific information in the Universal Library User's Guide. For example, on the PCI-DAS1602/16 the analog trigger circuit handles ±10 V. A value of 0 corresponds to –10 V, whereas a value of 65,535 corresponds to +10 V.
  • If you are using signed integer types, the thresholds range from –32,768 to 32,767 for 16-bit boards, instead of from 0 to 65,535. In this case, the unsigned value of 65,535 corresponds to a value of –1, 65,534 corresponds to –2, …, 32,768 corresponds to –32,768.
  • For most boards that support analog triggering, you can pass the required trigger voltage level and the appropriate range to cbFromEngUnits() function to calculate the highThreshold and lowThreshold values.
  • For some boards, you must manually calculate the threshold: first calculate the least significant bit (LSB) for a particular range for the trigger resolution of your hardware, then use the LSB to find the threshold in counts based on an analog voltage trigger threshold. Refer below to the Manually calculating the threshold example for details. For board-specific information, refer to the Universal Library User's Guide section of the Help.
DigitalGATE_HIGHScanning is enabled as long as the external digital trigger input is 5V (logic HIGH or '1').
GATE_LOWScanning is enabled as long as the external digital trigger input is 0V (logic LOW or '0').
TRIG_HIGHScanning begins when the external digital trigger is 5V (logic HIGH or '1'). Once conversions are enabled, the external trigger is ignored.
TRIG_LOWScanning begins when the external digital trigger is 0V (logic LOW or '0'). Once conversions are enabled, the external trigger is ignored.
TRIG_PATTERN_EQScanning begins when the digital port value AND bitwise mask are equal to the pattern value AND bitwise mask. Once conversions are enabled, the external trigger is ignored.
TRIG_PATTERN_NEScanning begins when the digital port value AND bitwise mask are not equal to the pattern value AND bitwise mask. Once conversions are enabled, the external trigger is ignored.
TRIG_PATTERN_ABOVEScanning begins when the digital port value AND bitwise mask are greater than the pattern value AND bitwise mask. Once conversions are enabled, the external trigger is ignored.
TRIG_PATTERN_BELOWScanning begins when the digital port value AND bitwise mask are less than the pattern value AND bitwise mask. Once conversions are enabled, the external trigger is ignored.
TRIG_POS_EDGEScanning begins when the external digital trigger transitions from 0V to 5V (logic LOW to HIGH). Once conversions are enabled, the external trigger is ignored.
TRIG_NEG_EDGEScanning begins when the external digital trigger transitions from 5V to 0V (logic HIGH to LOW). Once conversions are enabled, the external trigger is ignored.
Digtal Trigger Notes
  • For pattern trigger types, the LowThreshold argument represents the pattern value, and the HighThreshold argument represents the port mask. Use the cbSetConfig() ConfigItem BIPATTERNTRIGPORT to set the pattern trigger port.

Manually calculating the threshold

To calculate the threshold, do the following:

  1. Calculate the LSB by dividing the full scale range (FSR) by 2resolution. FSR is the entire span from –FS to +FS of your hardware for a particular range. For example, the full scale range of ±10 V is 20 V.
  2. Calculate how many times you need to add the LSB calculated in step 1 to the negative full scale (–FS) to reach the trigger threshold value.
  3. The maximum threshold value is 2 resolution – 1. The formula is shown here:

Abs (–FS – threshold in volts) ÷ (LSB) = threshold in counts

Calculate the LSB: LSB = 20 ÷ 28 = 20 ÷ 256 = 0.078125

Calculate the threshold: Abs(–10 – (–5)) ÷ 0.078125 = 5 ÷ 0.078125 = 64 (round this result if it is not an integer). A count of 64 translates to a voltage threshold of –5.0 V.

Calculate the LSB: LSB = 20 ÷ 212 = 20 ÷ 4096 = 0.00488

Calculate the threshold: Abs(–10 – 1) ÷ 0.00488 = 11 ÷ 0.00488 = 2254 (rounded from 2254.1). A count of 2254 translates to a voltage threshold of 0.99952 V.