Data Acquisition Toolbox

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. Configure your device to start acquiring data when you hit a switch that sends a rising edge signal to your device.

Create Session and Add Analog Input Channel

Create a session, and add an analog input channel with the Voltage measurement type, using National Instruments® PCIe 6363, with ID Dev4.

s = daq.createSession('ni');
s.addAnalogInputChannel('Dev4', 0, 'Voltage');

Configure the Session to start on an External Event

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

Add Start Trigger Connections to Session

A trigger connection has a source and a destination. In this example, the source is the switch, which is external to the session. Choose 'External' as the source. The destination is the PFI0 terminal on Dev4 , choose 'PFI0/Dev4' as the destination. Use addTriggerConnection to add a connection of type StartTrigger

s.addTriggerConnection('External','Dev4/PFI0','StartTrigger');

For a quick summary of the connections, type

s.Connections
ans = 


Start Trigger is provided externally and will be received by 'Dev4' at terminal 'PFI0'.

     TriggerType: 'Digital'
TriggerCondition: RisingEdge
          Source: 'External'
     Destination: 'Dev4/PFI0'
            Type: 'StartTrigger'


Set Trigger Parameters

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

s.ExternalTriggerTimeout = 30;

You can configure a session to receive multiple triggers, where a session responds to multiple external events. In this example, set the session to receive two external triggers. This would enable the device Dev4 to start acquiring when it receives the second trigger.

s.TriggersPerRun = 2;

Start the Acquisition

Use the startForeground command to start the acquisition.

[data,timeStamps,triggerTime] = s.startForeground();
plot(timeStamps,data,'.')

You will see a discontinuity based on the time between the two trigger starts.

Find the Time for the First Trigger

The absolute time of the first trigger is returned by startForeground in the triggerTime variable. triggerTime is a MATLAB serial date time stamp. Use basic MATLAB date conversion operations to analyze these.

datestr(triggerTime)
ans =

08-Feb-2014 04:05:16