Example Code

Generate Digital Waveform with Adjustable Duty Cycle - Provides Visuals

Code and Documents

Attachment

Overview

This VI will generate a digital waveform with a given number of samples per cycle at a specified duty cycle.  It shows the output of this waveform as if it were generated in continuous mode.  A visual for a data pointer to elements in the waveform is also provided and is most useful for demonstrating glitches in waveform output if duty cycle is changed during generation (e.g. increase duty cycle beyond current pointer position after current cycle has already transitioned to low).

Additionally, LabVIEW does not natively provide a Digital Waveform Chart.  I have implemented one in this VI so that samples can be written one at a time (per loop iteration) to a buffer, which is then written to a Digital Waveform Graph.  The window size on this "chart" is adjustable.  I will post this functionality separately for individual use and searchability.

Update - Digital Waveform chart functionality has been loaded here: https://decibel.ni.com/content/docs/DOC-26532

Description

There are a few sections of code in this VI:

  • Create one cycle of waveform: Use a For Loop and conditionally write True or False to the auto-indexed tunnel based on specified duty cycle.
  • Generate full waveform: Use the single cycle of data and concatenate it with itself to generate the requested number of cycles.
  • Maintain history length: This is part of the "Digital Waveform Chart" functionality; it checks buffer size and adjusts accordingly.
  • Update Digital Waveform Graph: This simply converts the "chart" buffer to a Digital Waveform data type so that it may be writen to the Digital Waveform Graph.
  • Calculate pointer position and update Boolean array visual: This simply performs a modulus on the loop index to show a sliding True value in an otherwise False Boolean array to demonstrate a data pointer as data is "clocked out" from the waveform.

Steps to Implement or Execute Code

  1. Adjust controls on Front Panel to the desired number of samples per cycle, number of cycles, duty cycle, and chart window size.
  2. Adjust the size of the Boolean array indicators if desired.
  3. Run the VI.

Requirements

Software

LabVIEW 2012 or later

Hardware

None

VI Snippet

Update Duty Cycle.png

Regards,
Chris Elliott
x36772

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

Contributors