Main Content

Acquire Digital Data Using a Shared Clock

This example shows how to share the clock with the analog input subsystem on your device with the digital subsystem to acquire clocked data that is automatically synchronized. You do not need any physical connections to share the clock. For more information, see Automatic Synchronization.

Create a DataAcquisition object and add a digital input line from port 0 line 0 on Dev1.

d = daq("ni");
addinput(d,"Dev1","Port0/Line0","Digital")

Note

Not all devices support clocked digital I/O operations with hardware timing. For these devices you can use software timed operations with single scan calls to read and write.

Devices that support clocked digital I/O operations might not support them on all ports. Check your device specifications.

Add an analog input channel to your DataAcquisition.

addinput(d,"Dev1",0,"Voltage");
d.Channels
ans = 

    Index    Type     Device       Channel       Measurement Type          Range                  Name       
    _____    _____    ______    _____________    ________________    __________________    __________________

      1      "dio"    "Dev1"    "port0/line0"    "InputOnly"         "n/a"                 "Dev1_port0/line0"
      2      "ai"     "Dev1"    "ai0"            "Voltage (Diff)"    "-10 to +10 Volts"    "Dev1_ai0"

Read and plot the acquired digital data. The device acquires digital data at the scan rate determined by its analog subsystem.

dataIn = read(d,seconds(1),"OutputFormat","Matrix");
plot(dataIn(1:100,1)) % Column 1 is data from the first channel.

Related Examples

More About