Acquire Counter Input Data

addCounterInputChannel

Use the addCounterInputChannel method to add a channel that acquires edge count from a device. You can acquire a single input data or an array by acquiring in the foreground. For details, see Session Architecture for more information.

Acquire a Single EdgeCount

This example shows how to acquire a single falling edge data from an NI USB-9402 with device ID 'cDAQ1Mod5'.

Step 1. Create a session object and save it to the variable s.

s = daq.createSession('ni');

Step 2. Add a counter channel with an 'EdgeCount' measurement type.

ch = addCounterInputChannel(s,'cDAQ1Mod5', 'ctr0', 'EdgeCount')
ans = 

Data acquisition session using National Instruments hardware:
   Will run for 1 second (1000 scans) at 1000 scans/second.
   Operation starts immediately.
      Number of channels: 1
      index Type  Device   Channel MeasurementType Range Name
      ----- ---- --------- ------- --------------- ----- ----
      1     ci   cDAQ1Mod5 ctr0    EdgeCount       n/a

Step 3. Change the ActiveEdge property to 'Falling' and view the channel properties to see the change:

ch.ActiveEdge = 'Falling'
ans = 

Data acquisition counter input edge count channel 'ctr0' on device 'cDAQ1Mod5':

      ActiveEdge: Falling
  CountDirection: Increment
    InitialCount: 0
        Terminal: 'PFI0'
IsCounterRunning: false
            Name: empty
              ID: 'ctr0'
          Device: [1x1 daq.ni.CompactDAQModule]
 MeasurementType: 'EdgeCount'

Step 4. Acquire a single scan.

inputSingleScan(s)
ans =

   133

Step 5. Reset counters from the initial count and acquire the count again.

resetCounters(s);
inputSingleScan(s)
ans = 

71

Acquire a Single Frequency Count

This example shows how to acquire a single frequency scan from an NI USB-9402 with device ID 'cDAQ1Mod5'.

Step 1. Create an acquisition session.

s = daq.createSession('ni');

Step 2. Add a counter channel with a 'Frequency' measurement type.

addCounterInputChannel('cDAQ1Mod5', 'ctr0', 'Frequency')
ans = 


      index Type  Device   Channel MeasurementType Range Name
      ----- ---- --------- ------- --------------- ----- ----
      1     ci   cDAQ1Mod5 ctr0    Frequency       n/a

Step 3. Acquire a single scan.

s.inputSingleScan
ans =

  9.5877e+003

Acquire Counter Input Data in the Foreground

This example shows how to acquire rising edge data from an NI USB-9402 with device ID 'cDAQ1Mod5', and plot the acquired data.

Step 1. Create an acquisition session.

s = daq.createSession('ni');

Step 2. Add a counter channel with an 'EdgeCount' measurement type.

addCounterInputChannel(s,'cDAQ1Mod5', 'ctr0', 'EdgeCount')
ans = 

Data acquisition session using National Instruments hardware:
   Will run for 10 seconds (10000 scans) at 1000 scans/second.
   Number of channels: 1
      index Type  Device   Channel MeasurementType Range Name
      ----- ---- --------- ------- --------------- ----- ----
      1     ci   cDAQ1Mod5 ctr0    EdgeCount       n/a

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 session. This example uses an NI 9205 device on the same chassis with the device ID 'cDAQ1Mod1'.

Step 3. Add an analog input channel with a 'Voltage' measurement type.

addAnalogInputChannel(s,'cDAQ1Mod1', 'ai1', 'Voltage');

Step 4. Acquire the data and store it in the variable data and plot it.

data =  startForeground(s);
plot (data)

The plot displays results from both channels in the session object:

  • EdgeCount measurement

  • Analog input data

Was this topic helpful?