# set_trigger()

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

- a_in_scan(), if the EXTTRIGGER option is selected.
- d_in_scan(), if the EXTTRIGGER option is selected.
- c_in_scan, if the EXTTRIGGER option is selected.
- a_pretrig()

## Prototype

set_trigger(board_num, trig_type, low_threshold, high_threshold)

## Parameters

board_num (int)

The number associated with the board when it was installed with InstaCal or created with create_daq_device().

trig_type (TrigType)

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

low_threshold (int)

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, low_threshold selects the pattern value.

high_threshold (int)

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, high_threshold selects the port mask.

### trig_type parameter values

Trigger source | Type | Explanation
Analog | GATE_NEG_HYS | Scanning is enabled as long as the external analog trigger input is more positive than high_threshold. Hysteresis is the level between low_threshold and high_threshold.
GATE_POS_HYS | Scanning is enabled as long as the external analog trigger input is more negative than low_threshold. Hysteresis is the level between low_threshold and high_threshold.
GATE_ABOVE | Scanning is enabled as long as the external analog trigger input is more positive than high_threshold.
GATE_BELOW | Scanning is enabled as long as the external analog trigger input is more negative than low_threshold.
GATE_IN_WINDOW | Scanning is enabled as long as the external analog trigger is inside the region defined by low_threshold and high_threshold.
GATE_OUT_WINDOW | Scanning is enabled as long as the external analog trigger is outside the region defined by low_threshold and high_threshold.
TRIG_ABOVE | Scanning begins when the external analog trigger input transitions from below high_threshold to above. Once conversions are enabled, the external trigger is ignored.
TRIG_BELOW | Scanning begins when the external analog trigger input transitions from above low_threshold to below. Once conversions are enabled, the external trigger is ignored.
TRIG_RISING | Scanning begins when the external analog trigger input transitions from below low_threshold to above high_threshold. Once conversions are enabled, the external trigger is ignored.
TRIG_FALLING | Scanning begins when the external analog trigger input transitions from above high_threshold to below low_threshold. 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 board-specific information. If 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 from_eng_units() to calculate the high_threshold and low_threshold 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, and to board-specific information, for details.
Digital | GATE_HIGH | Scanning is enabled as long as the external digital trigger input is 5V (logic HIGH or '1').
GATE_LOW | Scanning is enabled as long as the external digital trigger input is 0V (logic LOW or '0').
TRIG_HIGH | Scanning begins when the external digital trigger is 5V (logic HIGH or '1'). Once conversions are enabled, the external trigger is ignored.
TRIG_LOW | Scanning begins when the external digital trigger is 0V (logic LOW or '0'). Once conversions are enabled, the external trigger is ignored.
TRIG_PATTERN_EQ | Scanning 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_NE | Scanning 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_ABOVE | Scanning 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_BELOW | Scanning 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_EDGE | Scanning 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_EDGE | Scanning 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 low_threshold parameter represents the pattern value, and the high_threshold parameter represents the port mask. Use the set_config() ConfigItemPATTERNTRIGPORT() to set the pattern trigger port.

#### Manually calculating the threshold

Perform this procedure to calculate the threshold:

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

- Here are two examples that use this formula — one for 8-bit trigger resolution, and one for 12-bit trigger resolution:

- 8-bit example using the ±10 V range with a –5 V threshold:

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.

- 12-bit example using the ±10 V range with a +1 V threshold:

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.