Example Code

Output Trigger Upon Reaching Terminal Count.

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 VI uses the Counter Event to pause the counter acquisition after it has counted down to zero.

Description:
This example demonstrates on counting digital events on a Counter Input Channel.  The Initial Count, Count Direction and Edge are all configurable.
When the counter on your M Series DAQ Device rolls over it creates an event that can be routed to a PFI line and then used as an event to pause your count or even start another task.  
Edges are counted on the counter's default input terminal (refer to section IV, I/O Connections Overview for more information), but could easily be modified to count edges on a PFI or RTSI line.

Requirements:
LabVIEW 2012 or compatible.
NI-DAQmx 15.5.1 or compatible.

Steps to Implement or Execute Code:

  1. Select the Physical Channel which corresponds to the Counter Input Physical Channel at which count edges measurement will take place.
  2. Enter the Initial Count, Count Direction, and measurement Edge to specify how the counter counts.  
    Additionally, you can change the input terminal where events are counted using the channel property node.
    Note:  You might need another VI to verify the edge measurement is correct.

I/O Connections Overview:
The counter will count edges on the input terminal of the counter specified in the Physical Channel I/O control.

Block Diagram Steps:

  1. Create a Counter Input channel to Count Events.  The Edge parameter is used to determine if the counter will increment on rising or falling edges.
  2. Upon reaching terminal count, the output terminal of the counter can change state, or toggle. For example, if the terminal is initially at a low state, it changes to high state and stays at the high state until the next terminal count. The terminal then changes to low state. Use CtrOutEvent.Toggle.IdleState to select the initial state of the terminal. Then, specifies the terminal to which to route the Counter Output Event.
  3. Sets the Sample Clock Source and the rate of the Sample Clock.
  4. Configure the task to pause while the signal is high and defines the PFI pin as the output terminal of the digital signal which will be used as the source of the Pause Trigger.
  5. Call the Start Task VI to arm the counter and begin counting.  The counter will be preloaded with the Initial Count.
  6. The counter will be continually polled until the Stop button is pressed on the front panel.
  7. Call the Clear Task VI to clear the Task.
  8. Use the popup dialog box to display an error if any.

Front Panel.PNG

 

bd.png

 

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

Regards,
Dan King

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

Comments
nano2nd
Member
Member
on

I need to run a control task every n pulses received from a digital tach. The current system does this asynchronously, not by polling. I think this may be the analogous approach. So, i guess I would count down from a predetermined value and use an event to run the task...but I'm not sure.