Skip to content
Tutorials Center
My learning

Topics

Lesson 21 of 36 ยท Instrument Control and DAQ

DAQ Tasks, Channels and Timing

Understand data acquisition in LabVIEW with NI-DAQmx: devices, channels, tasks, the DAQmx Create Channel, Timing, Start, Read, Stop, Clear sequence and scaling raw readings.

A data acquisition (DAQ) device converts real-world signals (voltage, current, temperature, strain, pulses) into numbers and back. NI's driver for these devices is NI-DAQmx, and its VIs live on the Measurement I/O > DAQmx palette. Where VISA talks to instruments that have their own brains, DAQmx talks to the converters directly: your program decides the rate, the range and when each sample is taken.

LabVIEW and DAQ hardware are not available on this site, so this lesson explains the workflow exactly and runs a small simulated DAQ in Python to show the logic. No real readings appear here.

Devices, channels, tasks

  • A device is a card or module (for example "Dev1"). NI MAX lists devices and lets you run a test panel, and you can create a simulated device there to develop without hardware.
  • A physical channel is one input or output on a device: Dev1/ai0 (analog input 0), Dev1/ao1, Dev1/port0/line3 (digital line), Dev1/ctr0 (counter).
  • A virtual channel adds configuration: min and max values, terminal configuration (differential, RSE, NRSE), units, scaling, and for sensors the excitation and sensor type.
  • A task groups one or more virtual channels of the same measurement type with one timing and trigger configuration. You can mix channels of one type (ai0 to ai7) but not analog input and analog output in one task.

The standard sequence

Every DAQmx program follows the same five steps, wired left to right with the task reference and error cluster:

flowchart LR
    A["DAQmx Create<br/>Virtual Channel"] --> B["DAQmx Timing"]
    B --> C["DAQmx Start Task"]
    C --> D["DAQmx Read<br/>(in a loop)"]
    D --> E["DAQmx Stop Task"]
    E --> F["DAQmx Clear Task"]

Create the channel, set timing, start, read in a loop, then stop and clear.

  1. DAQmx Create Virtual Channel (choose Analog Input > Voltage, Temperature > Thermocouple, and so on). Enter the physical channel, the minimum and maximum expected values and the terminal configuration. A tighter range gives better resolution.
  2. DAQmx Timing (Sample Clock): pick the source (onboard clock), the rate in samples per second per channel, the sample mode and samples per channel.
  3. DAQmx Start Task (optional: Read starts the task automatically, but explicit start avoids restarting every loop iteration, which is very slow).
  4. DAQmx Read: choose the version that matches your needs, for example Analog > Multiple Channels > Multiple Samples > 1D Waveform.
  5. DAQmx Stop Task and DAQmx Clear Task to release the hardware.

The DAQ Assistant Express VI does these steps from a dialog and is a quick start, but a hand-written DAQmx sequence is faster, easier to reuse and clearer to maintain.

Sample modes

Mode Behaviour Typical use
Finite Samples Acquire N samples then stop One-shot capture, triggered burst
Continuous Samples Acquire until stopped; a buffer wraps Monitoring, streaming to disk
1 Sample (On Demand) One software-timed reading Slow signals, simple checks
1 Sample (HW Timed) One reading per clock tick Control loops

In continuous mode the driver fills a circular buffer while you read chunks in a loop. If you read too slowly the buffer overflows and DAQmx returns an error (-200361 or similar), so read about as many samples as arrive per loop iteration (a common choice is rate divided by 10 for a 100 ms loop).

Scaling and units

Raw ADC readings are integers. With a voltage channel DAQmx returns scaled volts. For other quantities you either let DAQmx do it (thermocouple type K returns degrees C, a strain-gauge channel returns strain) or apply a custom scale: a linear y = m x + b, a table, or a polynomial. A 4-20 mA pressure transmitter reading 0 to 10 bar, for example, measured across a 250 ohm resistor gives 1 to 5 V, so bar = (V - 1) * 10 / 4.

Python Linear scaling and a simulated DAQ read

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Digital, counter and output tasks

  • Digital I/O: lines are grouped in ports; you write a boolean array or an integer to a port and can read a line at a time. Digital input tasks can use a change-detection clock.
  • Counters measure frequency, period, pulse width, edge count and position (encoders), or generate pulse trains. Counter channels are also useful as a hardware timebase.
  • Analog output tasks write voltages (or currents) with DAQmx Write. On-demand writes are fine for set points; waveform output needs a sample clock and a buffer.

Synchronising and triggering

Input and output tasks can share a clock or start together: set the Start Trigger with DAQmx Trigger to a digital edge, an analog level, or another task's ai/StartTrigger signal. Reference triggers capture pre-trigger data like an oscilloscope. For multichannel accuracy, remember that low-cost multiplexed cards sample channels one after another, so simultaneous phenomena are offset by the convert-clock interval.

Do not put DAQmx Create Virtual Channel inside the loop. Creating and clearing a task every iteration takes tens of milliseconds and can lose samples. Create once before the loop, read inside it, and clear after it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is a DAQmx task?

    A task bundles channels of the same type with common timing and triggering.
  2. 2. Which is the right order for a basic acquisition?

    You configure the channel and timing, start, read in a loop, then stop and clear.
  3. 3. Why set a tight minimum and maximum on an analog input channel?

    A narrower range lets the ADC spend its counts on the values you expect.
  4. 4. A continuous acquisition reports a buffer overflow. What is the likely cause?

    If reads fall behind, the circular buffer is overwritten before you read it.

Summary

  • DAQmx works with devices, physical channels, virtual channels and tasks.
  • Use the Create, Timing, Start, Read, Stop, Clear sequence; create and clear once, outside the loop.
  • Choose finite, continuous or on-demand sampling to match the job.
  • Scale raw values to engineering units, with built-in sensor support or a custom scale.
  • Read at the rate data arrives to avoid buffer overflows.

Next: Sampling, Nyquist and Aliasing