Main Content

Acquire Voltage Data Using a Digital Trigger

This example shows how to use a falling edge digital trigger, which occurs when a switch closes on an external source. The trigger is connected to terminal PFI0 on device Dev1 and starts acquiring sensor voltage data.

Create a DataAcquisition object for NI devices.

 d = daq("ni");

Add a voltage input channel from NI USB-6211 with device ID Dev1.

addinput(d,"Dev1",0,"Voltage")

Physically connect the switch to terminal PFI0 on NI USB-6211. The trigger comes from the switch, which is an external source. Programmatically add the trigger to the DataAcquisition, indicating source, destination, and device PFI terminal.

t = addtrigger(d,"Digital","StartTrigger","External","Dev1/PFI0")
t = 

  DigitalTrigger with properties:

         Source: 'External'
    Destination: 'Dev1/PFI0'
           Type: StartTrigger
      Condition: 'RisingEdge'

Set the trigger Condition property to 'FallingEdge'.

t.Condition = 'FallingEdge';

Acquire data and store it in dataIn. The DataAcquisition waits for the trigger to occur, and starts acquiring data when the switch closes.

dataIn = read(d,seconds(1),"OutputFormat","Matrix");

Related Examples

More About