combined exercises (without hardware)

Upload: hputra26

Post on 06-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Combined Exercises (Without Hardware)

    1/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar1

    Exercise 1: Create a Simple LabVIEW VI

    In this exercise, you will create a simple LabVIEW VI that simulates an analog signal and plots it on awaveform graph. The VI will test the input values against a user-specified limit and light an LED if theinput value exceeds that limit.

    Below are pictures identifying each of the palettes found in LabVIEW to assist you as you complete theseexercises. For a more detailed explanation of the palette contents, as well as other facets of the LabVIEWdevelopment environment, refer to Appendix B,The LabVIEW Environment.

    Note: LabVIEW has a built-in Automatic Tool Selection feature that changes the behavior of the cursordepending on what type of object you are currently pointing to.

    Controls Palette

    Functions Palette

    1. If you have not already done so, click theLabVIEW icon on your quick launch toolbar.

  • 8/3/2019 Combined Exercises (Without Hardware)

    2/37

    LabVIEW Graphical Development Hands-On Seminar ni.com2

    Once you launch LabVIEW, a splash screen like the following appears.

    2. Click on File and Select New... Notice the different categories on the left of the window thatcorrespond to the types of tasks from which you can choose. SelectFrom Template. You can alsoselect BlankVI to start from scratch. There also are Template VIs to use as a starting point forbuilding your application.Projects and OtherFiles are more advanced components and will not bedescribed in detail. To get more information on any of the listings in the New Dialog Box, click theHelp button in the lower right corner of the window.

  • 8/3/2019 Combined Exercises (Without Hardware)

    3/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar3

    3. Select VIFrom TemplateTutorial (Getting Started) Generate and Display and click OK.

    Two windows appear. The gray window is the Front Panel, and the white one is the Block Diagram. TheFront Panel contains the parts of your VI used for presenting information, whereas the Block Diagramcontains the code that controls the functionality of the VI. You can toggle between the two windows byselecting WindowShow Block Diagram orWindowShow Front Panel. You can also switch betweenthe windows by pressing on the keyboard.

  • 8/3/2019 Combined Exercises (Without Hardware)

    4/37

    LabVIEW Graphical Development Hands-On Seminar ni.com4

    4. Examine the Front Panel and Block Diagram of this template VI. The Front Panel contains aWaveform Chart and a STOP button as shown in the following figure.

    The Block Diagram contains a Simulate Signal VI, which is currently configured to simulate a sinewave and plot it to the chart.

  • 8/3/2019 Combined Exercises (Without Hardware)

    5/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar5

    5. Switch back to the Front Panel by pressing . Since theRun button (the white arrow in the topleft corner) is solid, you can run this VI as it is. Click theRun button and examine the operation of theVI. When you are finished, click theSTOP button on the Front Panel to stop running the VI.

    Note: As you will see later in the exercise, when theRun button in the upper left corner of both theFront Panel and the Block Diagram changes from a solid white arrow, to a broken gray arrow, thisnew icon indicates that the VI is currently not executable.

    6. Now we can add some functionality to this basic VI. We will modify the VI to flash an alarm wheneverthe signal value is above a certain level. Open theControls palette (if it is not open already) by right-clicking the Front Panel window. A small pushpin icon in the upper left corner of this palette appears.Click this pushpin to force the palette to remain on your screen.

    7. Click the Numeric Controls palette, and select aVertical PointerSlide to be placed on the FrontPanel. To do this, click theVertical PointerSlide and drag it to the Front Panel. Click once toplace it.

  • 8/3/2019 Combined Exercises (Without Hardware)

    6/37

    LabVIEW Graphical Development Hands-On Seminar ni.com6

    8. Click the Express menu item on the Controls palette to return to the Express Controls Palette. Clickthe LEDs subpalette, and place aRound LED on the Front Panel.

    9. Right-click the Vertical PointerSlide and select Properties. A property page will appear. Examinethe different properties that you can modify. Make the following changes on theAppearance tab andclick OK to apply the changes.

    Label: Limit

    Slider1: Check Show digital display(s)

  • 8/3/2019 Combined Exercises (Without Hardware)

    7/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar7

    10. Right-click the Round LED labeledBoolean, and select Properties. Examine the different propertiesthat can be modified. On the Appearance tab, change the label from Boolean toAlarm. Click OK toapply your change. Move the objects on the Front Panel so it resembles the following.

    11. Switch to the Block Diagram by pressing . Double-click theSimulate Signal Express VI tobring up its properties window. Examine the different properties you can modify. Change theAmplitude of the signal to 10. Click OK to apply this change and to close the properties window.

  • 8/3/2019 Combined Exercises (Without Hardware)

    8/37

    LabVIEW Graphical Development Hands-On Seminar ni.com8

    12. Bring up the functions palette by right-clicking the Block Diagram. SelectArithmetic &ComparisonComparisonand place theComparison Express VI on the diagram.

    NoteFinding functions can be challenging in any language. The newQuick Drop feature in LabVIEW 8.6

    helps you quickly find and place LabVIEW front panel and block diagram objects using predictive text.With the block diagram open, press to open the Quick Drop dialog window. The QuickDrop window will take a moment to index the VIs installed on your machine.

  • 8/3/2019 Combined Exercises (Without Hardware)

    9/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar9

    Type comparison into the Quick Drop window.Note that the list of functions shown in the window isinstantly filtered based on the text that you type. Highlight the correct function and left-click on the blockdiagram to place it.

    *With Quick Drop, you can also customize shortcuts for objects that are often used.

    When you place the Comparison Express VI on the Block Diagram, a dialog box appears that lets youconfigure what type of comparison you will be doing. Make the following selections, then clickOK toapply these changes and to close the dialog box.

    Compare Condition: Greater

    ComparisonInputs: Compare to second input

  • 8/3/2019 Combined Exercises (Without Hardware)

    10/37

    LabVIEW Graphical Development Hands-On Seminar ni.com10

    13. You can connect Controls, Functions, and Indicators on the Block Diagram by pointing to an objectand clicking it when the cursor changes to a spool of wire. You can then move the cursor to the objectyou want to connect it to and click again. Connect theLimit control to the Alarm indicator.

    Note: The Run button in the upper left corner of both the Front Panel and the Block Diagram haschanged from a solid white arrow, to a broken gray arrow. This new icon indicates that the VI iscurrently not executable. If you click theRun button when it is solid and white, it runs the VI. Clicking

    it when it is broken and gray brings up a dialog box that will help you debug the VI.

    14. Click the Run button now. The resulting dialog box shows that, in this case, the error results fromconnecting terminals of two different types. Since theLimit control is a Numeric type and the Alarmindicator is a Boolean type, we cannot wire these two terminals together. Highlight the error byclicking it, and then click Show Error. LabVIEW will highlight the location of the error.

    15. Notice that the wire betweenLimit and Alarm is dashed and a redv is displayed on it.

    To delete this broken wire, press . This keyboard shortcut removes all broken wires from theBlock Diagram.

    16. Make your Block Diagram resemble the following image by completing the following steps.

    a. Wire the Limit control to the Operand 2 input of the Comparison function.

    b. Connect the wire between theSimulateSignals block and theWaveform Graph to theOperand 1 input of theComparison block.

    c. Wire the Result output of theComparison block to the Alarm indicator.

  • 8/3/2019 Combined Exercises (Without Hardware)

    11/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar11

    Your Block Diagram should now resemble the following:

    17. Switch to the Front Panel by pressing .

    18. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu andname it Exercise1.vi.

    Note:Be sure to save this VI, as you will be using it later in the seminar.

    19. Run the VI. While running the VI, you can change theLimit value. Also notice that when a data pointreceived from the Simulate Signal VIis greater than the Limit value, the Alarm indicator lights up.

    20. While the VI is still running, switch to the Block Diagram by pressing . Enablehighlightexecutionby clicking the light bulb on the tool bar.

    This will allow you to see the flow of data through your program.

    21. When you are finished, stop the VI by clicking theStop button on the Front Panel.

    End of Exercise 1

  • 8/3/2019 Combined Exercises (Without Hardware)

    12/37

    LabVIEW Graphical Development Hands-On Seminar ni.com12

    Exercise 2: Data Acquisition in LabVIEW(Without Hardware)

    In this exercise, you will learn both how to use the Simulated Device Function in the Measurement &Automation Explorer (MAX) and also the DAQ Assistant to set up a channel and configure a virtualanalog measurement.

    To create an NI-DAQmx simulated device,NI-DAQmx 7.4 or later must be installed.

    1. Open Measurement & Automation Explorer (MAX). NI-DAQmx simulated devices are created withinMAX. Unless you unchecked the feature during installation, MAX was installed when NI-DAQmx wasinstalled. If MAX is not installed, you must reinstall NI-DAQmx7.4 or later.

    2. Right-click My System>>Devices and Interfaces and selectCreate New... In the subsequent dialog,select NI-DAQmx Device>>NI-DAQmx Simulated Device. The Choose Device window promptsyou to select a device.

    Figure 1. Create an NI-DAQmx simulated device in MAX.

  • 8/3/2019 Combined Exercises (Without Hardware)

    13/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar13

    3. Select the device you want to create as an NI-DAQmx simulated device. With this list, you canbrowse the hundreds of devices supported by NI-DAQmx. You can create an NI-DAQmx simulateddevice of any NI-DAQmx-supported device, with the exception of the SCXI-1600 (NI-DAQmx 7.4 andlater) and B Series devices (NI-DAQmx7.5 and later).

    Figure 2. Choose from hundreds of NI-DAQmx supported devices.

    4. Extend M Series DAQ and select PCI-6221 as your NI-DAQmx simulated DAQ device that you wouldlike to created. Click OK in the Choose Device window to close the window. The NI-DAQmx

    simulated device appears in MAX. The icon color of the NI-DAQmx simulated devices differs fromreal devices. Real devices are green, and simulated devices are yellow.

  • 8/3/2019 Combined Exercises (Without Hardware)

    14/37

    LabVIEW Graphical Development Hands-On Seminar ni.com14

    Figure 3. Extend M Series DAQ and choosing PCI-6221 as your NI-DAQmx simulated device.

    Figure 4. Real devices are green and simulated devices are yellow.

    An NI-DAQmx simulated device works just as a real device. You can use NI-DAQmx simulated devices tocreate NI-DAQmx tasks either through the DAQ Assistant or the API. Because a real device is no longer

    required to create an NI-DAQmx task, NI-DAQmx simulated devices allow developers to do the following:

    Begin application development and logic before without hardware

    Develop application logic on a machine other than the target system

    5. Right-click the PCI-6221 DAQ card and select Test Panels. This will bring up a window that will allowyou to perform the different data acquisition tasks that are available on your board.

  • 8/3/2019 Combined Exercises (Without Hardware)

    15/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar15

  • 8/3/2019 Combined Exercises (Without Hardware)

    16/37

    LabVIEW Graphical Development Hands-On Seminar ni.com16

    6. Click the AnalogInput tab. Under Channel Name, be sureDev1/ai0is selected. Under mode, select

    Finite. Make sure the Rate is set to 1000 Hz and Samples to Read100. Click the Start button.

  • 8/3/2019 Combined Exercises (Without Hardware)

    17/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar17

    7. You should see a sine wave. This shows the ability to use MAX as a troubleshooting and testing toolbefore you begin programming to ensure your hardware is set up properly. When you are finished,close the Test Panel window and Measurement & Automation Explorer and return to the LabVIEWBlock Diagram.

    8. Right-click the Block Diagram to bring up the functions palette. Place a While Loop on your BlockDiagram by selectingExpressExecutionControlWhile Loop.

  • 8/3/2019 Combined Exercises (Without Hardware)

    18/37

    LabVIEW Graphical Development Hands-On Seminar ni.com18

    9. Place a DAQ Assistant Express VI inside your While Loop. This is located in theInput subpalette ofthe Functions palette.

    A configuration window should appear. Make the following selections.

    MeasurementType: AnalogInputVoltage

    Channel:Dev1ai0

    Click Finish

  • 8/3/2019 Combined Exercises (Without Hardware)

    19/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar19

  • 8/3/2019 Combined Exercises (Without Hardware)

    20/37

    LabVIEW Graphical Development Hands-On Seminar ni.com20

    10. Another configuration window will appear. Make the following selections and clickOK.

    Task Timing: Acquisition Mode :Continuous

  • 8/3/2019 Combined Exercises (Without Hardware)

    21/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar21

    11. Right click on the output terminal of theAdd function and chooseCreate >> Graph Indicator. Placethe Time DelayExpress VI, located on theFunctionsExpressExecutionControl palette, withinthe While Loop on the Block Diagram. In theConfigure Time Delaydialog box that appears, type0.5and click OK to close the dialog box. This will cause the loop to execute every500 ms. Position andwire the elements to resemble the following:

    12. To perform analysis on your data, select theStatistics Express VI from the Express>>SignalAnalysis subpalette of the Functions palette and place it on your Block Diagram.

  • 8/3/2019 Combined Exercises (Without Hardware)

    22/37

    LabVIEW Graphical Development Hands-On Seminar ni.com22

    A properties window will appear. Make the following selections and clickOK.

    Statistical Calculations: Arithmetic Mean

    Extreme Values: Maximum, Minimum

    13. Right-click the Arithmetic Mean output of the Statistics VI and selectCreateNumeric Indicator. Thiswill create a numeric indicator on the Front Panel that will display the Arithmetic mean. Repeat thisstep for both the Maximum and Minimum outputs of the Statistics VI.

  • 8/3/2019 Combined Exercises (Without Hardware)

    23/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar23

    14. Switch to the Front Panel and rearrange your controls and indicators to resemble the following.

    15. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu andname it Exercise2.vi.

    16. Run the VI. A sine wave is read from the simulated DAQ device and this allows the developer todevelop the system without hardware. Click theSTOP button on the Front Panel.

    17. Right-click on the block diagram and selectExpress OutputWrite to Measurement File andplace it inside the while loop on the block diagram

  • 8/3/2019 Combined Exercises (Without Hardware)

    24/37

    LabVIEW Graphical Development Hands-On Seminar ni.com24

    A configuration window will appear. Enter the following parameters and clickOK.

  • 8/3/2019 Combined Exercises (Without Hardware)

    25/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar25

    Make the following connections.

    NoteLabVIEW 8.6 introduces aBlock Diagram Cleanup tool to rearrange an entire block diagram in

    seconds with a single mouse click, without changing the functionality of your code. Though the BlockDiagram Cleanup tool is not intended to perfect the layout of your block diagram, configuration options dogive you the ability to specify wire spacing, block spacing, and diagram compactness at the pixel level.To

    access the configurable options for Block Diagram Cleanup, select Tools>>Options and choose BlockDiagram: Cleanup from the category list.

    18. Run the VI momentarily and Stop it. Browse to the path that you have set earlier and open the filewith a spreadsheet program (eg. Microsoft Excel).

    19. Save your VI.

    End ofExercise 2b

  • 8/3/2019 Combined Exercises (Without Hardware)

    26/37

    LabVIEW Graphical Development Hands-On Seminar ni.com26

    Exercise 3: Mathscript

    LabVIEW MathScript adds math-oriented, textual programming to LabVIEW. At the heart of LabVIEW

    MathScript is a high-level text-based programming language with syntax and functionality that abstracts

    the complexity of tasks related to signal processing, analysis, and math. In this exercise, you will learn to

    utilize the hybrid approach to programming in LabVIEW. The goal of your application is to generate two

    test signals, add some noise to these signals, and then apply a moving-average filter to remove the noise.

    Using the LabVIEW front panel, you plan to test your moving-average filter using a variety of control

    inputs.

    1. Open Starting Exercise.viin the Exercises folder.

    2. Observe the Front Panel.

    a. There are three inputs to our application

    i. Desired Length of Filter: filter length

    ii. flow:lowest of two frequency components for input signal

    iii. fhigh:highest of two frequency components for input signal

    b. There are four graph indicators to our application

    i. Low frequency component: low frequency waveform

    ii. High frequency component: high frequency waveform

    iii. Input signal: input signal to the filter (sum of two above components)

    iv. Output signal: output signal from the moving-average filter

    3. Observe the Block Diagram

    a. The three controls on our front panel are passed into the MathScript Node as inputs

    b. Three of the four graph indicators have been populated by outputs from the MathScript

    Node.

    c. Notice the script highlighting:

  • 8/3/2019 Combined Exercises (Without Hardware)

    27/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar27

    i. LabVIEW MathScript comments are preceded by a % sign, which indicates to

    the compiler to ignore the text that follows on that line. Comments are turned

    green by default.

    ii. The blue color of the functionscos and ones as well as the defined constantpi.

    iii. You can edit the colors used for script highlighting using Tools >> Options andchoosing MathScript: Script Highlighting

    4. The MathScript Node is incomplete. Enter the following code on line10 of the Node

    outputsignal = filter(num,1,inputsignal)/M;

    This line defines our output signal by applying the moving-average filter.

    5. To complete the application, the last step is to pass the newly defined variableoutputsignalto the

    appropriate graph indicator.

    a. Right-click on the border of the MathScript Node below theinputsignaloutput, and select

    b. Type the string outputsignalinto this output. The name correlates the output to the

    appropriate variable in the script

    c. Next, define the variable datatype to be passed to the LabVIEW indicator by right-clicking

    on the output and choosing: > 1D-Array >> DBL 1D>

  • 8/3/2019 Combined Exercises (Without Hardware)

    28/37

    LabVIEW Graphical Development Hands-On Seminar ni.com28

    d. Wire the outputsignaloutput from the MathScript Node into theOutput signalgraph

    indicator

    e. The application is now complete

    6. Return to the Front Panel and press the Run Arrow. Change the values of the inputs to see how

    they affect the output signal from the filter.

    7. Return to the block diagram and use the new debugging tools to step through the application.

    a. Place a breakpoint on lines7 and 10 by hovering over the gray region to the left of the

    line. The mouse will turn into a breakpoint indicator, as shown below. Left-click to place

    the breakpoints.

    b. Activate the MathScript Probe to identify intermittent variable values within the Node by

    right-clicking on the border, and choosingProbe.

    8. Run the application. The Probe will populate the values of all variables defined up until the first

    breakpoint: fhigh, flow, M, n, s1, and s2

    a. Step over each line of the script by pressing theStep over Line ofScriptbutton on the

    toolbar

  • 8/3/2019 Combined Exercises (Without Hardware)

    29/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar29

    b. Use the highlight execution and stepping functions to explore the remainder of the

    application.

    END OFEXERCISE 3

  • 8/3/2019 Combined Exercises (Without Hardware)

    30/37

    LabVIEW Graphical Development Hands-On Seminar ni.com30

    Exercise 4: Report Generation

    In this exercise, you will learn how to present your data using the Report Express VI in LabVIEW. ThisExpress VI allows you to quickly and easily customize a report and present your data in an attractiveformat.

    22. Click the LabVIEW icon on your desktop toolbar. If you already have a VI open, selectFileClose all to return to the main LabVIEW start menu.

    23. Click the BlankVI to create a new VI.

    24. Switch to the Block Diagram by pressingCtrl-E. Place the Simulate Signal Express VI(Express>>Input>>Simulate Signal) on your Block Diagram and configure it as in the followingimage:

  • 8/3/2019 Combined Exercises (Without Hardware)

    31/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar31

    25. Place the Spectral Analysis Express VI (Express>>Signal Analysis>>Spectral Measurements) onyour Block Diagram and configure it as in the following image and clickOK.

    26. Connect the Sine with Uniform output of the Simulate Signal Express VI to theSignals input of theSpectral Measurements Express VI as shown here:

  • 8/3/2019 Combined Exercises (Without Hardware)

    32/37

    LabVIEW Graphical Development Hands-On Seminar ni.com32

    27. To report this data, select theReport Express VI from the Output subpalette of the Functions paletteand place it on your Block Diagram.

    A properties window will appear. Configure the Report VI according to the following figure and clickOK.

  • 8/3/2019 Combined Exercises (Without Hardware)

    33/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar33

    28. Wire the output of the DAQ Simulate Signal Express VI and the Spectral Measurement Express VI tothe inputs of the Report Express VI as demonstrated here:

  • 8/3/2019 Combined Exercises (Without Hardware)

    34/37

    LabVIEW Graphical Development Hands-On Seminar ni.com34

    29. Switch to the Front Panel by pressingCtrl-E.

    30. Save the VI in the C:\Seminars\HandsOn\LabVIEW\CustomerWork folder by using the File menu andname it Exercise4.vi.

    31. Run the VI.

    32. Navigate to C:\Seminars\HandsOn\LabVIEW\CustomerWork\report.html. Open the file usingMicrosoft Internet Explorer. The report will have all of the data you specified in the Report VI.

    33. Stop and close the VI and Web browser when you are finished.

    End of Exercise 4

  • 8/3/2019 Combined Exercises (Without Hardware)

    35/37

    National Instruments Corporation LabVIEW Graphical Development Hands-On Seminar35

    Exercise 5: Remote Panels (Optional)

    In this exercise, you will learn how to present your data using the Remote Panels feature in LabVIEW.This technology allows you to easily publish your VIs over the internet and allow remote users to run andcontrol your LabVIEW application.

    1. Open the VI from exercise 2a. The first thing we must do is start the LabVIEW Web Server. To dothis, open the Tools menu and selectWebPublishing Tool

    2. Click the Start Web Serverbutton to active the Server.

    3. Next, select your VI from the VI name ring and then clickNext.

  • 8/3/2019 Combined Exercises (Without Hardware)

    36/37

    LabVIEW Graphical Development Hands-On Seminar ni.com36

    4. The next window allows us to configure the text that is displayed on the web page. Fill in the fields asshown here and click Next.

    5. LabVIEW will now generate the HTML page which displays your application over the web. In the nextwindow, you are prompted to save this page. ClickSave to Disk. LabVIEW then provides the URL foryour new page. ClickConnect and LabVIEW will launch your new web page.

    6. To control the VI through your web browser, right-click on the Front Panel image and selectRequestControl ofVI.

  • 8/3/2019 Combined Exercises (Without Hardware)

    37/37

    7. Now click the Run arrow to run your VI.

    8. When you are finished, close the VI and web browser.