Archived: Traditional NI-DAQ (Legacy) Data Acquisition Triggering Tips and Techniques

NI does not actively maintain this document.

This content provides support for older products and technology, so you may notice outdated links or obsolete information about operating systems or other relevant products.


Note: This page is about NI-DAQ also known as Traditional NI-DAQ (Legacy). NI-DAQmx replaced Traditional NI-DAQ (Legacy) in 2003. NI strongly recommends using NI-DAQmx for new designs and migrating existing Traditional NI-DAQ (Legacy) applications to NI-DAQmx. Please review the Getting Started with NI-DAQmx guide for more information on migration.

Synchronization of the data acquisition (DAQ) process relative to an external event is an important criterion in many DAQ applications. For example, you may want to collect data after receiving a pulse signal from an encoder or when the temperature of a chamber exceeds a critical value. In such instances, the DAQ system must be set up to start the analog-to-digital (A/D) conversions as soon as the external event, or trigger, occurs.

A triggered acquisition provides two key benefits to the user: It times the input signal relative to the trigger event so the user captures the signal only in the region of interest and thus conserves hardware bandwidth and memory.


Trigger Types – Analog vs Digital

The trigger signals to which DAQ hardware responds are classified in two ways: analog and digital.

  • Analog Trigger – The level and slope of an analog signal triggers the acquisition (Figure 1). In such a system, analog trigger circuitry (ATC) on the DAQ hardware continuously monitors the analog signal to determine if it satisfies the trigger conditions. Once the trigger conditions are met, the ATC generates an internal trigger signal to initiate the acquisition.

    Figure 1. Analog Trigger Condition of Level and Slope
  • Digital Trigger – The rising or falling edge of a TTL signal initiates the data acquisition (Figure 2).

Figure 2. Digital Trigger 

Acquisition Type -- Posttrigger vs. Pretrigger

Triggered data acquisition applications can be classified in two ways: posttriggered and pretriggered.

  • Posttriggered Acquisition – In a posttriggered acquisition, the hardware starts the A/D conversions after the trigger is received (Figure 3).

Figure 3. Posttriggered Acquisition
  • Pretriggered Acquisition – In a pretriggered acquisition, the hardware starts acquiring data before the trigger signal is received (Figure 4). With this type of acquisition, the user can view the signal before the trigger event. In such applications, the hardware initiates data acquisition with a software function and stores the data in a circular buffer in the PC memory. The buffer is large enough to ensure that the required number of pretrigger samples are stored. When the buffer is full, it simply wraps around and stores each subsequent sample over the oldest sample in memory. The primary responsibility of the trigger mechanism is to stop the acquisition so that the samples left in memory represent the “slice-in-time” the user wants. The trigger signal in this case is referred to as the "stop trigger."

Figure 4. Pretriggered Acquisition

Developing Triggered Applications with LabVIEW and NI-DAQ

This application note focuses on implementing various types of triggered applications using National Instruments DAQ hardware and NI-DAQ driver software. NI-DAQ provides a powerful, yet easy-to-use interface for developing sophisticated DAQ applications from a variety of programming environments, such as LabVIEW, Measurement Studio, C++ and Visual Basic. To develop DAQ applications in LabVIEW, use the Data Acquisition VIs from the LabVIEW functions palette. In other programming environments, make function calls within the NI-DAQ DLL. Details about the Data Acquisition VIs and NI-DAQ functions can be obtained from the online documentation that is shipped with LabVIEW and NI-DAQ, respectively. Sample DAQ programs illustrating several of the concepts discussed in this document can be found in the LabVIEW/examples/daq and NIDAQ/samples directories.

DAQ applications typically consist of the four building blocks shown below (Figure 5).

Figure 5. Flowchart for a Typical DAQ Application

Trigger conditions for any application are specified in the configuration section by calling the appropriate Traditional NI-DAQ (Legacy) functions or Data Acquisition VIs in LabVIEW. The rest of this document discusses how to implement various triggering types using LabVIEW and Traditional NI-DAQ (Legacy) functions.

A. Posttriggered Acquisition with a Digital Start Trigger
In a posttriggered acquisition, the A/D conversions start after the DAQ hardware receives the trigger signal. The digital trigger is typically wired to the external trigger input of the I/O connector of the specified device.

The following code snippet shows how to set up a posttriggered application using NI-DAQ functions:

/* Specify that a trigger is being used */
DAQ_Config (deviceNumber, startTrig, extConv );// set startTrig = 1
/* Start the acquisition */ 
DAQ_Start (deviceNumber, …)

Note: The code snippets using NI-DAQ functions are not complete programs; they only show the functions necessary to set up a particular triggered operation.

Figure 6 illustrates how to set up a digital posttriggered acquisition in LabVIEW.

Figure 6. Posttriggered Acquisition with a Digital Trigger

With the National Instruments E Series multifunction I/O (MIO) devices, you can choose from one of 10 different lines (labeled PFI0-9 on the I/O connector) as the trigger input. The default trigger source is PFI0, but an alternate trigger source (e.g., another PFI line or RTSI line) can be selected by calling the Traditional NI-DAQ (Legacy) function Select_Signal.

The following code snippet shows how to set the trigger source to be the falling edge of a TTL signal wired into the PFI3 pin on the I/O connector:

/* Select trigger source */
Select_Signal(deviceNumber, ND_IN_START_TRIGGER, ND_PFI_3, ND_HIGH_TO_LOW);
/* specify that a start trigger is to be used */
DAQ_Config(deviceNumber, startTrig, extConv); // set startTrig = 1
/* start the acquisition */ 
DAQ_Start(deviceNumber, …)

Alternately, you can use the Scan_Start function to read from multiple channels.

Figure 7 illustrates how to specify an alternate trigger source in the AI in LabVIEW.

Figure 7. Triggered Acquisition on E Series Device

B. Pretriggered Acquisition on a Digital Stop Trigger
In a pretriggered acquisition, the A/D conversions are initiated with a software function call. Traditional NI-DAQ (Legacy) stores the digitized data in computer memory in a circular buffering scheme, replacing the oldest points in the buffer with the new samples. Once the trigger signal is received, a specified number of points before and after the trigger are returned to the calling application (e.g., LabVIEW, C++, etc.) by Traditional NI-DAQ (Legacy).

The following code snippet shows how to configure a pretriggered acquisition using Traditional NI-DAQ (Legacy) function calls:

/* Configure pretriggered acquisition */
DAQ_StopTrigger_Config (deviceNumber, stopTrig, ptsAfterStopTrig ); 
// Set stopTrig to 1.
// Set ptsAfterStoptrig to (total scans -  # of pretrig scans).

Figure 8 illustrates how to create a pretriggered application in LabVIEW by specifying the desired number of pretrigger scans in AI Note that setting the pretrigger scans to zero creates a posttriggered acquisition.

Figure 8. Pretriggered Acquisition with a Digital Stop Trigger

C. Pretriggered Acquisition with Start and Stop Triggers
You can also set up an acquisition that uses both start and stop triggers. In this case, a digital or analog trigger starts the acquisition instead of a software function. Once the acquisition starts, a circular buffering scheme (similar to the previous case) is implemented until the stop trigger signal is received. The data returned consists of the specified number of pretrigger and posttrigger samples relative to the stop trigger signal (Figure 4).

E Series devices use PFI0 as the default start trigger input and PFI1 as the default stop trigger input. An alternate trigger source can be selected by calling the Trigger in LabVIEW. The following code snippet shows how to call the Select_Signal function in Traditional NI-DAQ (Legacy) to select an alternate trigger source:

/* specify a start trigger */
DAQ_Config (board, startTig, extConv ); // Set startTrig to 1.
/* specify a stop trigger */
DAQ_StopTrigger_Config (board, stopTrig, ptsAfterStopTrig);
     // Set stopTrig to 1; Set ptsAfterStoptrig to (total scans –  # of pretrig scans).

On older legacy MIO boards there are dedicated STARTRIG* and STOPTRIG inputs on the I/O connector for the start and stop trigger, respectively.

Figure 9 illustrates how to implement an acquisition in LabVIEW with a start and stop trigger by specifying the trigger type in the AI

Figure 9. Acquisition with a Digital Start and Stop Trigger

D. Analog Hardware Triggering
Several National Instruments E Series DAQ devices have onboard ATC that can be used to start an acquisition based on the level and slope of an analog signal. A typical application using an analog hardware trigger could be a temperature-monitoring system where the acquisition starts only when the temperature rises above a certain value. The trigger signal can be wired to either the PFI0 pin or to an analog input channel.

Analog hardware trigger conditions can be set by the following Traditional NI-DAQ (Legacy) function:

Configure_HW_Analog_Trigger (deviceNumber, onOrOff, lowValue, highValue, mode, trigSource);// set onOrOff = ND_ON

The lowValue and highValue parameters specify the levels to use for triggering. Details about the valid values for these and other parameters for the function can be found in the Traditional NI-DAQ (Legacy) Function Reference Online Help, which ships with NI-DAQ.

The following paragraphs describe the available modes and trigger-generation scenarios, and the figure following each paragraph illustrates that situation. Values specified by highValue and lowValue are represented using dashed lines, and the signal used for triggering is represented using a solid line.

ND_BELOW_LOW_LEVEL—The trigger is generated when the signal value is less than the lowValue. HighValue is unused.

ND_ABOVE_HIGH_LEVEL—The trigger is generated when the signal value is greater than the highValue. LowValue is unused.

ND_INSIDE_REGION—The trigger is generated when the signal value is between the lowValue and the highValue.

ND_HIGH_HYSTERESIS—The trigger is generated when the signal value is greater than the highValue, with hysteresis specified by lowValue.

ND_LOW_HYSTERESIS—The trigger is generated when the signal value is less than the lowValue, with hysteresis specified by highValue.

Figure 10 illustrates how to specify the appropriate parameters in the AI to implement analog hardware triggering in LabVIEW.

Figure 10. Analog Hardware Triggering in LabVIEW

E. Conditional Retrieval
If your hardware does not implement analog hardware triggering, you can implement a form of analog triggering known as “conditional retrieval.” Here, Traditional NI-DAQ (Legacy) transfers the acquired samples to a buffer in computer memory using a circular buffering scheme, checking each sampled point to determine if it satisfies user-specified voltage and slope conditions. When the trigger conditions are met, Traditional NI-DAQ (Legacy) returns the data to the calling application. The key difference between “analog hardware triggering” and “conditional retrieval” is the fact that the former is done by the ATC in hardware while Traditional NI-DAQ (Legacy) implements the latter in software.

Conditional retrieval is implemented in Traditional NI-DAQ (Legacy) using the function Config_ATrig_Event_Message:

Config_ATrig_Event_Message (deviceNumber, mode, chanStr, trigLevel, windowSize, trigSlope, trigSkipCount, pretrigScans, postTrigScans, handle, message, callbackAddr)

The driver generates a Windows message or executes a user-specified callback function when the trigger conditions are satisfied. Please refer to the National Instruments Developer Zone Online Application Note, Using DAQ Event Messaging Under Windows NT/95, for details on setting up the event message functions using Traditional NI-DAQ (Legacy) functions.

Figure 11 illustrates how to specify in the cluster input in the AI to implement conditional retrieval in LabVIEW.

Figure 11. Conditional Retrieval in LabVIEW

F. Synchronizing Several DAQ Devices
National Instruments DAQ hardware for PCI and ISA have the RTSI bus, with which two or more devices installed in the same computer can share certain timing and triggering signals. A RTSI bus cable connects to each device so that each device can either send or receive the signal from one of seven available lines (RTSI0-RTSI6) on the RTSI bus. A common application involving multiple devices is simultaneously starting the A/D conversions on all the devices. This task can be implemented with a “master-slave” type configuration, where the “slave” devices receive the start trigger signal from the “master” device over the RTSI bus. The “master” device routes its trigger signal to one of the RTSI lines and the slave devices receive the trigger signal from the RTSI line. The slave devices must start before the master so that they can receive the trigger signal.

The following code snippet shows how to route trigger signals on E Series devices using the NI-DAQ Select_Signal function:

/* master board: send start trigger signal to RTSI_0 */ 
Select_Signal (masterdevice, ND_RTSI_0, ND_IN_START_TRIGGER, ND_LOW_TO_HIGH)
/* slave board: receive start trigger signal from RTSI_0 */
Select_Signal (slave_device, ND_IN_START_TRIGGER, ND_RTSI_0, ND_LOW_TO_HIGH)
/* start slave device */ DAQ_Start (slave_device, …)
/* start master device */ DAQ_Start (masterdevice, …)

You can also set up multiple slave devices by calling the Select_Signal function as necessary.

Note: The trigger signal on the master device is typically internally generated; however, you can also set up the master device to start on an external analog or digital trigger using the techniques discussed earlier.

Figure 12. Trigger several devices simultaneously using RTSI bus.

In LabVIEW, you can call the Route on the master device to send the start trigger signal to the RTSI line. On the slave devices, you can call the Trigger and set up the RTSI line as the trigger source (Figure 12). You can set up as many slave configurations as necessary. The wiring scheme of the error clusters determines the execution order of the VIs and ensures that the slave devices start before the master.

The following code snippet shows how to use Traditional NI-DAQ (Legacy) functions to set up the master-slave configuration on older legacy MIO devices with RTSI bus:

/* connect EXTTRIG* line to RTSI 0 on master device*/
/* sigCode = 8 for legacy MIO devices, trigLine = 0 (for RTSI 0) and dir = 1 (transmit) */ RTSI_Conn(masterdevice,sigCode,trigLine,dir)
/* receive EXTTRIG* signal from RTSI 0  on slave device*/
/* sigCode = 8 for legacy MIO devices, trigLine = 0 (for RTSI 0) and dir = 0 (receive) */ RTSI_Conn(slavedevice,sigCode,trigLine,dir)
/* start the slave device */ 
DAQ_Start(slavedevice, ...)
/* start master device */ 
DAQ_Start(masterdevice, ...)

Figure 13 illustrates how to use the RTSI Control VIs in LabVIEW with legacy MIO devices.

Figure 13. Synchronizing Multiple Legacy MIO Devices using RTSI Bus

G. Synchronize Analog Input and Analog Output
Most DAQ devices have analog output circuitry to generate analog output signals on one or more channels. A typical use of the analog output capability of the hardware is as a function generator to generate periodic waveforms (sine, square, triangle, etc.). The analog output process can be synchronized with the analog input by the following methods:

  • Trigger analog input and output using the same external TTL signal – The following function calls initiate both input and output on the rising edge of a TTL signal wired into PFI0:
/*  trigger analog input on rising edge of signal on PFI0 */
Select_Signal(deviceNumber, ND_IN_START_TRIGGER, ND_PFI_0, ND_LOW_TO_HIGH)
/*  trigger analog output on rising edge of signal on PFI0 */
Select_Signal(deviceNumber,ND_OUT_START_TRIGGER, ND_PFI_0, ND_LOW_TO_HIGH)
Figure 14 shows how to implement such a triggered application in LabVIEW.

Figure 14. Trigger Analog Input and Output on External TTL Signal

  • Trigger analog output from the analog input – In this setup, the analog input is initiated by a software function that generates an internal start trigger pulse to indicate the start of the analog input acquisition. This signal can be used to trigger the analog output process.

    This following code snippet sets up the triggering using Traditional NI-DAQ (Legacy) functions:

    /* set ND_IN_START_TRIGGER as the source of the ND_OUT_START_TRIGGER */

    Figure 15 illustrates how to set the trigger source parameter in AO Trigger in LabVIEW.

Figure 15. Triggering Analog Output from Analog Input in LabVIEW

H. Event Triggering
In some applications, you may want to skip a certain number of trigger pulses before starting the acquisition. This trigger type is also referred to as an “event trigger” since you are triggering on the nth (n > 1) trigger event. Such an application can be implemented using the counters on a National Instruments E Series DAQ device. The general idea is as follows:

  1. Configure a counter as a “down counter” to divide down the TTL signal wired to its source input. For example, you can set the counter to generate an output pulse for every nth rising edge of the input.
  2. Use the output of this counter as the trigger source.

Figure 16 shows the timing diagram associated with event triggering.

Figure 16. Triggering on a Selected Edge of the Trigger Signal

The following code snippet illustrates how to implement event triggering using Traditional NI-DAQ (Legacy) functions to start the DAQ operation on the nth trigger signal:

/* reset counter 0 */
GPCTR_Control(deviceNumber, ND_COUNTER_0, ND_RESET);
/* set counter 0 for single pulse generation */
GPCTR_Set_Application(deviceNumber, ND_COUNTER_0,ND_SINGLE_PULSE_GNR);
/* set counter  0 source to PFI 8 */
GPCTR_Change_Parameter (deviceNumber, ND_COUNTER_0,ND_SOURCE, ND_PFI_8);
/* set counter 0 to generate pulsed output */
GPCTR_Change_Parameter (deviceNumber, ND_COUNTER_0, ND_OUTPUT_MODE, ND_PULSE);
/* set low count */
GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_COUNT_1,N+1);
/* set high count */
GPCTR_Change_Parameter(deviceNumber, ND_COUNTER_0, ND_COUNT_2,N+1);
/* To output a counter pulse, you must call Select_Signal. */
/* Setup Counter 0 output as the trigger source for analog input */
/* Configure the Analog Input operation */
DAQ_Config(deviceNumber, iStartTrig, iExtConv);//iStartTrig = 1 DAQ_Rate(dSampRate, …) DAQ_Start(deviceNumber, …)
/* arm the counter */
GPCTR_Control(deviceNumber, ND_COUNTER_0, ND_PROGRAM);

Figure 17 shows how to implement event triggering in LabVIEW.

Figure 17. Implementing Event Triggering in LabVIEW

I. Scan Clock Gating
Some DAQ applications may require the user to implement a pause/resume feature where an external signal controls when the DAQ hardware performs the A/D conversions during an acquisition. For these types of applications, National Instruments DAQ devices support a feature known as “scan clock gating.” Here, the internal scan clock is gated by an external signal such that the scan clock pauses while the external signal is low and resumes when the signal goes high (or vice versa). Scan clock gating can be classified into two types, digital or analog, depending on the nature of the gate signal.

  • Digital Scan Clock Gating – Here, the gate signal for the scan clock is a TTL signal. You can wire it into any of the available PFI lines on the E Series DAQ device. Figure 18 shows the timing diagram for high level digital scan clock gating. In the figure, each rising edge of the scan clock signal indicates the initiation of a scan (where a scan implies reading a point from each channel in the channel list).

Figure 18. Timing Diagram for High-Level Digital Scan Clock Gating
The following code snippet illustrates how to implement high level digital scan clock gating using Traditional NI-DAQ (Legacy) function calls:

/*  set up PFI 8 as gate signal source and gate action to pause while low */
Select_Signal (deviceNumber, ND_IN_EXTERNAL_GATE, ND_PFI_8,ND_PAUSE_ON_LOW);
/* configure the device */
DAQ_Config(deviceNumber, startTrig, extConv);   //startTrig = 0
/* set up sampling rate */
DAQ_Rate(rate, units, timebase, sampleInterval);
/* start the operation */ DAQ_Start(deviceNumber, …)

Figure 19 demonstrates how to implement this type of gating in LabVIEW. Note that any PFI line can be the source of the gate signal.

Figure 19. Digital Scan Clock Gating in LabVIEW
  • Analog Scan Clock Gating – Here, the gate signal is an analog signal with a voltage level that determines when the acquisition occurs. Only devices with analog trigger capability offer this feature. Figure 20 illustrates the timing diagram for high-level analog scan clock gating where the A/D conversions occur only while the analog signal is above a critical voltage level.

Figure 20. Timing Diagram for High-Level Analog Scan Clock Gating
The following code snippet shows how to set up analog scan clock gating using Traditional NI-DAQ (Legacy) function calls:

/* set up Analog Hardware Trigger conditions  */
Configure_HW_Analog_Trigger(deviceNumber, ND_ON, lLowValue, lHighValue,
/* Setup for external gating for the scan clock to pause while low. */ Select_Signal (deviceNumber, ND_IN_EXTERNAL_GATE, ND_PFI_0,ND_PAUSE_ON_LOW);
/* configure the device */
DAQ_Config(deviceNumber, startTrig, extConv);   //startTrig = 0
/* set up sampling rate */
DAQ_Rate(rate, units, timebase, sampleInterval);
/* start the operation */ DAQ_Start(deviceNumber, …)

Figure 21 illustrates how to set up analog scan clock gating in LabVIEW.

Figure 21. Analog Scan Clock Gating in LabVIEW

Was this information helpful?