Example Code

VirtualBench: Source DC Voltage With the PWS

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 power supply (PWS) and outputs a voltage with a current limit. 


[+] 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 and the PWS channel from the pull-down menus of their respective controls on the Channel Settings panel.
    5. Specify the output voltage level and current limit in the Set Output panel.
    6. Click the Run button to begin outputting the specified voltage.
    7. The Measured Output panel will display the actual voltage and current output and specify if the PWS is in constant current or constant voltage state.
    8. Click the Stop button to end the program.

 

Program Explained

 


[+] Enlarge Image

    • Initialize Session
      • A new session to the PWS is initialized by passing the VirtualBench device information from the VirtualBench Device control into the PWS Initialize VI.
      • Instrument and error information are passed into a While Loop. The PWS channel is passed from the control into the same While Loop. 
    • Configure Instrument
      • Instrument and error information are passed into the PS Configure Voltage Output VI. The voltage level, current limit, and PWS channel are passed from the controls into the VI. 
      • Instrument and error information are then passed into the PS Enable All Outputs VI. The outputs have been enabled using a Boolean true constant. After this step, the PWS is outputting the desired voltage with the specified current limit. 
      • This step is inside the While Loop so that the voltage level and current limit can be adjusted without having to stop and restart the program.
    • Perform Operation
      • Instrument and error information are passed into the PS Read Output VI. The PWS channel is passed from the control to the VI. 
      • This VI outputs the measured voltage, current, and state of the channel to indicators located on the Measured Output panel. 
      • As indicated by the While Loop, this program will repeatedly output a voltage with a current limit and read back the voltage, current, and state information.
      • The error wire is unbundled in order to determine the error status. This information is then passed through an OR with the state of the Stop button into the conditional terminal of the While Loop. If either an error has occurred or if the user clicks the Stop button, the While Loop will finish executing.
      • Instrument and error information are passed into a Case structure. The OR value is used as the case selector. Select the down arrow next to the case name to select a different case to view. 
        1. False case: If the user has not pressed the Stop button and no error has occurred, the False case will be implemented. In this case, instrument and error information are simply passed through the structure.
        2. True case: If the user has pressed the Stop button or an error has occurred, the True case will be implemented. In this case, instrument and error information are passed into the PS Enable Outputs VI with the outputs disabled using Boolean constant false. This step ensures that when the program is finished, the PWS channels will be turned off for safety.
      • A 100 ms Wait has been added and will be performed in every iteration of the loop. While Loops are designed to  execute as fast as possible, but this can take up a lot of processor resources. The Wait is added to prevent  unnecessary use of computing resources.
    • Close Session
      • The instrument and error information are passed out of the While Loop and into the PWS Close VI. This closes the PWS session and deallocates any resources for the next time a session is created with the PWS.
    • 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.