From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Example Code

VirtualBench: Generate Standard or Arbitrary Waveforms With the FGEN

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

  • VirtualBench All-in-One Instrument

Code and Documents

Attachment

Description

Overview
This example automates the VirtualBench function generator (FGEN) and outputs either a standard sine, square, triangle/ramp, or constant DC waveform or a user-defined arbitrary waveform.


[+] Enlarge Image

Steps to Run Program

    1. Download the example program on the right under downloads.
    2. In LabVIEW software, open the program by going to File » Open… and navigating to the file.
    3. Connect the VirtualBench device.
    4. Select the correct VirtualBench device in the pull-down menu of the VirtualBench Device control.
    5. Specify the waveform settings.
    6. Click the Run button to output the waveform.

 

Program Explained


[+] Enlarge Image

 

    • Initialize Session
      • A new session to the FGEN is initialized by passing the VirtualBench device information from the VirtualBench Device control into the FGEN Initialize VI.
    • Configure Instrument
      • Instrument and error information is passed into a Case structure. 
      • The tab selected on the front panel is passed through the Waveform Type control to the selector terminal of the Case structure. 
      • If standard waveform is chosen:
        • Instrument and error information are passed into the FGEN Configure Standard Waveform VI. 
        • The following waveform information is passed from their controls to the VI: duty cycle, frequency, waveform function, amplitude, and DC offset. 
      • If arbitrary waveform is chosen:
        • Instrument and error information are passed into the FGEN Configure Arbitrary Waveform VI. 
        • The start frequency, delta frequency, and sampling information are passed into the Basic Multitone with Amplitudes VI. The constants Ramp Pattern and Amplitude are also passed into the VI. The amplitude is set to one so that the gain is directly changing the voltage. This VI generates a waveform that is the sum of integer cycle sine tones. 
        • This generated waveform is passed into the FGEN Configure Arbitrary Waveform VI. 
        • Instrument and error information are passed into the FGEN Configure Arbitrary Waveform Gain and Offset VI. The gain and offset defined in their respective controls are also passed into the VI. 
    • Perform Operation
      • The instrument and error information are passed out of the Case structure and into the FGEN Run VI. This begins the output of the waveform. 
      • Even after the program has finished, it will continue to output the specified waveform until the FGEN settings are adjusted again. 
    • Close Session
      • The instrument and error information are passed into the FGEN Close VI. This closes the FGEN session and deallocates any resources for the next time a session is created with the FGEN.
    • Handle Errors
      • Finally, the error information is passed into the Simple Error Handler VI. If an error has occurred, a dialog box will open to notify the user.

 

Additional Resources

 

VirtualBench Examples

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