acquire digital data using an external clock
this example shows how to acquire digital data in the foreground by using an external scan 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 and .
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))