Acquire Counter Input Data
Add Counter Input Channel
Use addinput
to add a channel that acquires edge counts from a device. You can acquire a single
input data or an array by acquiring in the foreground. For more information, see
Interface Workflow.
Acquire a Single Count
This example shows how to acquire a single count of falling
edges from an NI 9402 with device ID cDAQ1Mod5
. The example
assumes that some external source is providing an input to the counter channel,
and that the count is accumulating over time. You can read the accumulated count
at one point in time, then reset the counter and read it again at a later
time.
Step 1. Create a DataAcquisition object assigned to the variable
d
.
d = daq("ni");
Step 2. Add a counter input channel with an edge count measurement type.
ch = addinput(d,"cDAQ1Mod5","ctr0","EdgeCount")
ch = Index Type Device Channel Measurement Type Range Name _____ ____ ___________ _______ ________________ _____ ________________ 1 "ci" "cDAQ1Mod5" "ctr0" "EdgeCount" "n/a" "cDAQ1Mod5_ctr0"
Step 3. Change the channel ActiveEdge
property to
'Falling'
and view the channel properties to see the
change.
ch.ActiveEdge = 'Falling';
get(ch)
ActiveEdge: Falling CountDirection: Increment InitialCount: 0 Terminal: 'PFI0' SampleTimingType: 10388 Name: 'cDAQ1Mod5_ctr0' ID: 'ctr0' Device: [1x1 daq.ni.DeviceInfo] MeasurementType: 'EdgeCount'
Step 4. Acquire a single scan reading of the counter buffer.
count = read(d)
count = 133
Step 5. Reset counters from the initial count and acquire an updated count value. This value is the number of detections since resetting the counter.
resetcounters(d); count = read(d)
count = 71
Acquire a Single Frequency Count
This example shows how to acquire a single scan of frequency
measurement from an NI 9402 with device ID cDAQ1Mod5
.
Step 1. Create a DataAcquisition object.
d = daq("ni");
Step 2. Add a counter channel with a frequency measurement type.
addinput(d,"cDAQ1Mod5","ctr0","Frequency")
Index Type Device Channel Measurement Type Range Name _____ ____ ___________ _______ ________________ _____ ________________ 1 "ci" "cDAQ1Mod5" "ctr0" "Frequency" "n/a" "cDAQ1Mod5_ctr0"
Step 3. Acquire a single scan of counter data.
f = read(d,"OutputFormat","Matrix")
f = 9.5877e+003
Acquire Counter Input Data in the Foreground
This example shows how to acquire rising edge data from an NI
9402 with device ID cDAQ1Mod5
, and plot the acquired
data.
Step 1. Create a DataAcquisition object.
d = daq("ni");
Step 2. Add a counter input channel with an edge count measurement type.
addinput(d,"cDAQ1Mod5","ctr0","EdgeCount")
Index Type Device Channel Measurement Type Range Name _____ ____ ___________ _______ ________________ _____ ________________ 1 "ci" "cDAQ1Mod5" "ctr0" "EdgeCount" "n/a" "cDAQ1Mod5_ctr0"
Step 3. Add an analog input channel for a voltage measurement type.
The counter input channel requires an external clock to perform a
foreground acquisition. If you do not have an external clock, add an analog
input channel from a clocked device on the same CompactDAQ chassis to the
DataAcquisition. This example uses an NI 9205 device on the same chassis
with the device ID cDAQ1Mod1
. Alternatively, the analog
input channel could be on the same device as the counter channel.
addinput(d,"cDAQ1Mod1","ai1","Voltage");
Step 4. Acquire the data and assign it to the variable
data
, and plot the results.
data = read(d,seconds(1),"OutputFormat","Matrix"); plot(data)
The plot displays the results from both channels in the DataAcquisition:
Edge count measurement
Analog input data