0.60

ReferenceHardwareNational InstrumentsCounter read task

NI counter read task

Read frequency, edge counts, pulse widths, and encoder positions from NI counters into channels.

An NI counter read task reads the counter inputs of NI devices into channels. A counter measures digital pulses: their frequency, their count, their width, or the position and speed of an encoder. For example, it can record the speed of a flow meter on ctr0 of a USB-6343.

Before you start, you need configured devices.

Counters and timing

Each channel reads one counter, set by its Port: port 0 is ctr0. The pulses come in on a PFI terminal. Set Input terminal to choose the terminal, or leave it empty to use the default terminal of the counter. The device manual lists the counters and their terminals.

The Driver reads the counters on the computer clock, at the Sample rate. See timing.

Create an NI counter read task

Enterprise
  1. In the devices toolbar, right-click a device and select Create counter read task.
  2. Set Sample rate and Stream rate.
  3. Click Add channel. In Source, select the Device and the Port.
  4. In Signal, select the Channel type, then set its fields. See the channel reference.
  5. Click (Start).

The Console creates the channels. For a device with the identifier dev1, counter 0 gives dev1_ctr_0, with the index channel dev1_ctr_time.

Tare channels

Tare sets the current value of a channel to zero. The task must be running.

  1. In the channel list, click Tare on a channel. To tare several channels, select them, right-click, and select Tare.
  2. The values of those channels start from zero.

Task options

Console label Python field Default Notes
Sample rate sample_rate 10 Hz Up to 1,000,000 Hz in the Console.
Stream rate stream_rate 5 Hz Up to 20,000 Hz. See read tasks.
Data saving data_saving_disabled On See data saving.
Auto start auto_start Off Starts the task each time the Driver starts.

Channel reference

Every channel has a channel, the Synnax channel that records the value, a device, the key of the device (Device), and a port, the counter number (Port). In Python, a channel with no device uses the device of the task.

Each table shows the Console label of a setting, with its Python field under it. The Notes column lists the values that code uses. The Console shows the same values in plain words. Every type except edge count also has Custom scaling.

Frequency

Python CIFrequencyChannelTypeScript ci_frequencyNI-DAQmx

Measures the frequency of a digital signal.

Setting Default Notes
Range min_val, max_val 2 to 100 In Units.
Starting edge edge Rising Rising, Falling.
Units units Hz Hz, Ticks.
Input terminal terminal PFI0 to PFI15. Empty uses the default terminal of the counter.
Measurement method meas_method DynamicAvg LowFreq1Ctr, HighFreq2Ctr, LargeRng2Ctr, DynamicAvg.
Measurement time (s) meas_time 0.000006 In seconds. Shows for HighFreq2Ctr.
Divisor divisor 4 Shows for LargeRng2Ctr.

Custom scaling

Channels with Custom scaling convert the raw value before the Driver writes it. In the Console, the options are in the Scale section of the channel. In code, set custom_scale to one of these scales:

Console option Python class Fields
None NoneScale No scaling. This is the default.
Linear LinearScale Slope (slope, 1) and Y-intercept (y_intercept, 0).
Map MapScale Pre-scaled min and max to Scaled min and max (pre_scaled_min, pre_scaled_max, scaled_min, scaled_max).
Polynomial PolynomialScale Forward coefficients (forward_coeffs) and Reverse coefficients (reverse_coeffs), from c0 up.
Table TableScale Pre-scaled and Scaled pairs (pre_scaled_vals, scaled_vals). A CSV file can fill them.

Every scale except None also has Prescaled units (pre_scaled_units, Volts) and Scaled units (scaled_units).

Troubleshooting

For other problems, see Configure an NI device and Troubleshoot hardware.