Example Code

Dividing Digital Pulses Using Counter With DAQmx

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:
Demonstrate on dividing an external signal into two or more depending on the value wired to the High Ticks and Low Ticks terminals of the DAQmx Create Channel VI.

Description:
Since the count register has a minimum value of 2, using a default Counter Output task only allows the user to divide-down an external signal by 4 i.e. 2 high ticks, 2 low ticks which means that in every 2 ticks of of the input signal or timebase, the Counter Output will generate a high and followed by a low in another two ticks.

Instead of Toggle Mode as explained earlier, developer may program the counter to use Pulse mode which means that the counter will pulse every time it switches between High Ticks and Low Ticks registers.  
Which means that the counter is now configured to emit a short pulse every number of high and low ticks as specified by wiring a constant/control to the High Ticks and Low Ticks input terminals of the DAQmx Create Channel VI.

In this example, wiring a control value of 2 has the effect of dividing down an external signal by 2 i.e. every 2 complete pulses of a timebase signal will generate 1 complete pulse.

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 you want to output your signal to on the DAQ device.
  2. Enter the High and Low Ticks to define the pulse parameters.


Block Diagram Steps:

  1. Creates a 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 is at a low state.
  2. Configures the Sample Clock and the sample mode to Continuous Sample.
  3. Specifies whether the exported Counter Output Event pulses or changes from one state to the other when the counter reaches terminal count. Upon reaching terminal count, the counter can issue a pulse.
  4. Runs the configured task.
  5. Loop continuously until the user presses the Stop button and check for errors every 100 ms using the DAQmx Is Task Done VI.
  6. Clears the task and displays any error that occurs.

bd.jpg

 

FP.jpg

 

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

John Passiak

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