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
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
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
addtrigger to add this trigger on the DataAcquisition.
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
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
read to acquire scans on receipt of each configured digital start trigger. The specific sequence of events is:
The DataAcquisition starts
One second of actual acquisition begins on receipt of the first trigger unless the timeout period expires
One second of actual acquisition begins on receipt of the second trigger unless the timeout period expires
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, '.')