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 a session, and add an analog input channel with the
Voltage measurement type, using National Instruments® PCIe 6363, with ID
s = daq.createSession('ni'); addAnalogInputChannel(s,'Dev4', 0, 'Voltage');
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
For a quick summary of the connections, type
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'
By default the session waits for 10 seconds for the rising edge digital trigger. Increase the timeout to 30 seconds using
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;
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.
The absolute time of the first trigger is returned by
startForeground in the
triggerTime is a MATLAB serial date time stamp. Use basic MATLAB date conversion operations to analyze these.
ans = 23-Jul-2016 00:44:43