Example Code

Creates Hardware Timed Triggers Using X4 Encoding

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview:
This example uses DAQmx events to monitor X4 encoding. This allows the user to create hardware timed triggers and pulses off specific number of counts.

Description:
The user monitors the A and B lines for rising AND falling edges (X4 Encoding).
Then, a trigger is created based on the number of A and B rising and falling edges using X4 encoding.
With minimum modification this example can be used to allow different encoding mechanisms.

Requirements:
LabVIEW 2012 or compatible.
NI-DAQmx 15.5.1 or compatible.
National Instruments DAQ device with counters.

Steps to Implement:

  1. Wire encoder A and B lines to port 0 lines 0 and 1 respectively.
  2. Select ctr1 as the value of Counter control and wire the output to input terminal to monitor the data.
  3. On the Source of Ticks control, select ChangeDetectionEvent for the device (e.g. /Dev1/ChangeDetectionEvent).
  4. Run


Block Diagram Steps:

  1. a. Creates channel to generate digital pulses defined by the number of timebase ticks that the pulse is at a high state and the number of timebase ticks that the pulse at a low state.
    b. Sets only the number of samples to generate without specifying timing as pulse train generation does not require sample timing.
    c. Transitions the task to the running state to begin the generation.
    d. Queries the status of the task before clearing the task.
    e. Clears the task and display any error occurs.
  2. a. Creates channel to measure digital signals.
    b. Configures the task to acquire samples on the rising and/or falling edges of the lines or ports you specify. To detect both rising and falling edges on a line or port, wire the name of that line or port to both rising edge physical channels and falling edge physical channels.
    c. Registers the DAQmx events. This settings will fire an event every time the Change Detection Event fires. The Register Events Node is found in the Dialog & User Interface >> Events pallete.
    d. Starts the task.
    e. Clears the task.
    f. Unregister the events associated with the refnum and displays any error occurs.

Front Panel.PNG

 

bd.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Best Regards,
Song Mu
National Instruments San Diego

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.