Example Code

Generate Finite Digital Pulse On Demand

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:
Demonstrates on generating  a finite digital pulse train from a Counter Output Channel on demand.

Description:
Finite digital pulse train will be generated when user press on the Start button which will trigger the channel. The Frequency, Duty Cycle, Initial Delay and Idle State are all configurable during run time.
This example shows how to configure the pulse in terms of Frequency and Duty Cycle, but can easily be modified to generate a pulse in terms of Time or Ticks. The counter will output the pulse train on the output terminal of the counter specified in the Physical Channel I/O control.  In this example the output will be sent to the default output terminal on ctr0. For more information on the default counter input and output terminals for your device, open the NI-DAQmx Help, and refer to Counter Signal Connections found under the Device Considerations book in the table of contents.

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 at which the signal will be output on the DAQ device.
  2. Enter the Frequency and Duty Cycle to define the pulse parameters.  Enter the Number of Pulses into the DAQmx Timing VI to determine the duration of the generation.
    Additionally, you can set the Initial Delay (in seconds) which will delay the beginning of the pulse train from the start call.  Also, you can change the Idle State to set the state the line will remain in after the generation is stopped.
  3. Setup the Trigger Parameters.  In this example the VI is expecting a Rising Edge Digital Trigger on PFI9 (ctr0 default gate).
    Note:  Use the Measure Period example to verify you are outputting the finite pulse train on the DAQ device.


Block Diagram Steps:

  1. Create a Counter Output channel to produce a Pulse in terms of Frequency.  If the Idle State of the pulse is set to low the first transition of the generated signal is from low to high.
  2. Use the DAQmx Timing VI (Implicit) to configure the duration of the pulse generation and the number of pulses to generate.
  3. Use the DAQmx Trigger VI to configure a trigger to start on a digital edge.
  4. Use a DAQmx Trigger Property Node to set the operation for triggerable.
  5. Call the Start VI to arm the counter and begin the pulse train generation.
  6. Loop continuously until the user presses the Stop button. Check for errors every 100 ms using the Is Task Done? VI
  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

 

Block Diagram.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange.**
Best regards,
Rohan B

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