Main Content

Acquire Digital Data Using an External Clock

This example shows how to acquire digital data in the foreground by using an external scan clock.

Sharing an external sampling clock

You can use a function generator or the on-board clock from a digital circuit. Here, a function generator is physically wired to terminal PFI9 on device NI 6255.

Create a DataAcquisition object and add a output line at port 0 line 2 on Dev1.

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

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

      1      "dio"    "Dev1"    "port0/line2"      "InputOnly"      "n/a"    "Dev1_port0/line2"

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.

Set the rate of your DataAcquisition to the expected rate of your external scan clock.

d.Rate = 1000;

Note

Importing an external clock does not automatically set the scan rate of your DataAcquisition. Manually set the DataAcquisition Rate property value to match the expected external clock frequency.

Programmatically add a scan clock to your DataAcquisition, indicating the source as external and the target as device terminal PFI9.

clk = addclock(d,"ScanClock","External","Dev1/PFI9")
clk = 

  Clock with properties:

         Source: 'External'
    Destination: 'Dev1/PFI9'
           Type: ScanClock

Acquire clocked digital data and plot it.

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

Related Topics