From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, 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: Frequency Sweep Generator and Acquisition With the FGEN and MSO

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 a frequency sweep with the VirtualBench function generator (FGEN) and displays the resulting voltage through the mixed signal oscilloscope (MSO). 


[+] 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 analog channel and the desired settings for the sine wave sweep. 
    6. Connect the FGEN to your device under test (DUT). Connect the DUT output to the MSO channel selected.
    7. Click the Run button to begin the sweep.
    8. The output signal will display on the graph on the front panel.
    9. Click the Stop button to end the program before the sweep is complete.

 

Program Explained

 


[+] Enlarge Image

    • Initialize Session
      • The VirtualBench device information is passed into the FGEN Initialize VI to initialize a new session to the FGEN and passed to the MSO Initialize VI to initialize a new session to the MSO.
    • Configure Instrument
      • Instrument and error information are passed into the FGEN Configure Standard Waveform VI. The function type is set to sine, and the start frequency, amplitude, and DC offset are passed from the controls to the VI. 
      • Instrument and error information are passed into the MSO Configure Analog Channel VI. The analog channel, amplitude, and DC offset are passed to the VI, and the channel is enabled using a Boolean true constant. 
      • Instrument and error information are passed into the MSO Configure Analog Edge Trigger VI. The trigger source is set to the analog channel specified on the front panel, and the trigger slope is set to rising.
    • Perform Operation
      • Instrument and error information are passed to the  FGEN Run VI and then into the While Loop. The loop will not run until all of the inputs are available, so this ensures that the FGEN is running before we start the MSO. 
      • Instrument and error information are passed to the FGEN Configure Standard Waveform VI. The frequency is calculated:
        • The range is calculated by subtracting the start frequency from the end frequency. 
        • The range is divided by the number of steps to determine the increment size. 
        • The increment size is multiplied by the iteration count to determine the total frequency difference from the starting frequency. 
        • The total difference is added to the start frequency to determine the frequency value for that iteration. 
        • This value is also compared to the the end frequency; if it is equal to or greater, then it will stop the While Loop.
        • The divide and multiply functions both have a coercion dot at an input.  LabVIEW places a red coercion dot to alert you that LabVIEW converted the value passed into the node to a different representation. In these cases, LabVIEW is converting a double-precision, floating-point number to an integer. While a conversion VI could have been used to convert the numeric type, it was unnecessary since LabVIEW can do it.
    • Close Session
      • The instrument and error information are passed out of the While Loop and into the FGEN Close VI and the MSO Close VI. This closes the sessions and deallocates any resources for the next time a session is created with the instruments.
    • Handle Errors
      • Finally, the error information is bundled together and 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.