Main Content

Start a Multi-Trigger Acquisition on an External Event

This example shows how to set up and start a multi-trigger acquisition on an external event. In this instance, the device is configured to start acquiring data on a rising edge signal.

Create a DataAcquisition and Add Analog Input Channels

Create a DataAcquisition object, and add an analog input channel with the Voltage measurement type, using an NI PCIe 6363, with ID Dev4.

dq = daq("ni");
addinput(dq,"Dev4","ai0","Voltage");

Configure the DataAcquisition to Start on an External Trigger

Configure the device to acquire data on the external trigger. A trigger that starts an acquisition is called a Start Trigger. In this example, the switch is wired to terminal PFI0 on device Dev4. Represent this physical connection (between the switch and terminal PFI0) as a start trigger.

Add Digital Start Trigger

A trigger has a trigger type (Digital). The allowed value for the Digital trigger type is StartTrigger.

A trigger has a source and a destination. In this example, the source is the switch (choose 'External' as the source). The destination is the PFI0 terminal on Dev4 ('PFI0/Dev4'). Use addtrigger to add this trigger on the DataAcquisition.

addtrigger(dq,"Digital","StartTrigger","External","Dev4/PFI0");
dq.DigitalTriggers
ans = 

  DigitalTrigger with properties:

         Source: "External"
    Destination: 'Dev4/PFI0'
           Type: 'StartTrigger'
      Condition: 'RisingEdge'

Set Trigger Parameters

By default the DataAcquisition waits for 10 seconds for the rising edge digital trigger. Increase the timeout to 30 seconds using DigitalTriggerTimeout property.

dq.DigitalTriggerTimeout = 30;

You can configure a DataAcquisition to receive multiple triggers, when it should respond to multiple events. In this example, two external trigger signals are expected, enabling the device Dev4 to start acquiring scans on receipt of the second trigger.

dq.NumDigitalTriggersPerRun = 2;

Start the Acquisition

Use read to acquire scans on receipt of each configured digital start trigger. The specific sequence of events is:

  1. The DataAcquisition starts

  2. One second of actual acquisition begins on receipt of the first trigger unless the timeout period expires

  3. One second of actual acquisition begins on receipt of the second trigger unless the timeout period expires

  4. Data is returned

[data, startTime] = read(dq, seconds(1));

Plot the Data

Observe the discontinuity based on the time between the two trigger starts.

plot(data.Time, data.Variables, '.')