You are on page 1of 15

An Overview of National Instruments LabVIEW Part 1

*This tutorial was developed for LabVIEW 7 and the LabVIEW: Getting Started with LabVIEW tutorial.

An Overview of National Instruments LabVIEW Part 1 Purpose: The purpose of this tutorial is to introduce you to the basic workings of the LabVIEW software produced by National Instruments (NI). By the end of this tutorial, you should be able to create your own Virtual Instruement (to be explained later) to do some basic signal processing. What is LabVIEW? LabVIEW is a graphical programming language that can be used for acquiring signals, measurement analysis, and data presentation. Basically, LabVIEW allows you to create a Virtual Instrument (VI) that allows you to manipulate signals and obtain measurements. You can also store the data you acquire into separate documents or simply display it on the screen. You can think of it as all those pieces of equipment you have on your lab bench rolled into one neat package. The reason LabVIEW is called a graphical programming language is that you are really creating a program that will do everything you want to do, but instead of having to learn the code and figure out how to link it all together, you simply grab an icon that does a certain function and place it on the work space. Once you have all the functions you want to perform, you simply connect them in the order you want them to be performed. Say you want to take a sin wave, scale its amplitude, add another signal to it (maybe a square pulse train), then display this new wave on an oscilloscope display. To write the code to do this in a traditional programming language would not be an easy task, especially if youre not familiar with the syntax. With LabVIEW, all you need to do is grab two signal generators, a signal summer, something to scale the amplitude, and the waveform grapher, link them together (like you might do to several components in SPICE), and you have a Virtual Machine that will do exactly what you want. This might not sound all that interesting at the moment, since manipulating signals will not help you a great deal with your projects. However, the real power of this program will be demonstrated during the second part of this skill session. When LabVIEW is used in conjunction with one of the National Instrument work stations now available at Smittys, you can create a signal, output it to your circuitry, then acquire the signal you get out of your circuit and do some of the signal processing and data acquisition functions you learn in this tutorial to that signal. There will be a follow up skill session down at Smittys to get you acquainted with these new machines and how to use what you will learn during this skill session to test your own circuitry.

-1-

An Overview of National Instruments LabVIEW Part 1 Task 1: Getting Started This first task, as the title indicates, is going to show you how to start up LabVIEW and begin building your Virtual Instrument. 1) Start up the LabVIEW program by going to the start menu. - the program should be in Start\ECN Software\LabVIEW 7.0\National Instruments LabVIEW 7.0 2) Once LabVIEW is started, the following screen (figure 1) will show up (unless you have used LabVIEW before and checked the Do not show this dialog box again box). Click continue.

Figure 1 3) Now, the following screen (figure 2) should show up. From this screen, click on the New button on the right hand side of the screen.

Figure 2

-2-

An Overview of National Instruments LabVIEW Part 1 4) Again, the following screen (figure 3) will show up. Make sure the Blank VI is highlighted in the Create new: box and click ok.

Figure 3 5) After clicking ok, the previous window should have disappeared and four new windows should have popped up. These are the windows that you will use to build your virtual machine. - The one with the gray, graph looking background is called the Front Panel (figure 4). This is what will actually display the information about the measurements that you create. - The window with the plane white background is called the Block Diagram (figure 5). This is where you will actually do most of the coding to create your measurements. - The third window is somewhat smaller then the previous two and is the Functions/Controls window. This is where you will locate the parts you wish to add to your virtual machine. The window is the Functions window in the Block Diagram and the Controls window in the Front Panel. - The last window that should have popped up is the Context Help window. This updates itself with useful information about parts. To see the help about a specific part, just hold the mouse over it and the context help updates automatically.

Figure 4 -3-

Figure 5

An Overview of National Instruments LabVIEW Part 1 Task 2: Initial setup You are now almost ready to start building your Virtual Instrument. This task will show you some of the initial steps you will need to perform in order to ensure you Virtual Instrument will function correctly. 1) Just as in any program, unless you have a loop of some kind, the program will only execute once. LabVIEW is the same. In order to have your Virtual Instrument run continuously and continue to process data, you will need to create a loop. Follow the next few steps to do this: - Click in the Block Diagram window - From the Functions window, click on the Exec Ctrl button, located in the bottom left corner - Click on the While Loop button - Click and drag to create a box on the Block Diagram window You should now have a gray box with something that says stop down in the lower right hand corner (figure 6). This is the while loop. Anything you place inside this loop will continue to run until you press the stop button.

Figure 6 Note: If you click back over to the Front Panel there is now a stop button. LabVIEW automatically updates the front panel with any displays that are necessary for the objects you place in the Block Diagram window. Task 3: Creating your Virtual Instrument You are now ready to start constructing your Virtual Instrument. This task will help you to build a basic Virtual Instrument that will generate a signal and do some signal processing and data acquisition on it. 1) First we will need to get something that will create a signal. To do this, we will want to grab the Simulate Signal Express VI (Express VI is the terminology used by LabVIEW to label the block diagram objects). To do this, follow the steps below: - Click on the Block Diagram window if you are not already there - Click on the Input button located in the upper left corner of the Functions window (you may still be in the Exec Ctrl section, so to get -4-

An Overview of National Instruments LabVIEW Part 1 back to the main menu, click the up arrow located in the far upper left corner) Click on the Simulate Sig button Click somewhere inside the box you created in the previous task to place the Simulate Signal Express VI in your block diagram The Configure Simulate Signal window (figure 7) will pop up

Figure 7 From this window, you can change most of the properties of the signal you want to create. For now, we will only want to change the sampling rate, so in the Samples per second box, type 100000, then click ok. You now have a signal generator for your Virtual Instrument. The icon to the left (figure 8) should now appear on your block diagram. Figure 8 Note: If you click on the two down arrows at the bottom of the Simulate Signal Express VI and drag down, you will see a number of different boxes show up. These are different ways you can affect the signal generator. Boxes with arrow heads on the left are inputs while boxes with arrow heads on the right are outputs. You can change the attribute that appears in the box by right clicking on it and going to Select Input/Output. We will only be using the Amplitude and frequency inputs and the Sine output for this activity, so leave only the Sine, error out and Amplitude showing, and change error out to frequency (figure 9). Figure 9

-5-

An Overview of National Instruments LabVIEW Part 1 2) Now, we shall add two knobs to the front panel to control the amplitude and frequency of the Sine wave created by the Simulate Signal Express VI. To do this, follow the steps outlined below: - Click on the Front Panel window - From the Controls window (the Function window for the Front Panel) click on the Num Ctrls button located in the upper left corner - Click on the Knob button - Click somewhere on the Front Panel window to place the knob - Right click on the knob icon (figure 10) and click properties - On the window that pops up, change the Label to Amplitude (there are options available for the knob, but we wont we worried about those now) - Notice how the label on the Front Panel now says Amplitude - If you now click back over to the Block Diagram, there will be a block for the knob automatically inserted - To connect this knob to control the amplitude of the Sine wave, move the mouse over the arrow on the knob block - The cursor should change to a what looks like a spool of thread (figure 11) - Click, then move the cursor over to the arrow next to the Amplitude box of the Simulate Signal Express VI and click again You have now connected your knob to control the amplitude of the Sine wave generate by the Simulate Signal Express VI. Perform the same steps to place a knob to control the frequency (label it as Frequency). One addition step you will need to perform is to rescale the range: - Right click on the knob for the frequency on the Front Panel and go to properties - Click on the scale tab at the top of the window that pops up - Type 10000 in the maximum box Lets also add a couple of numerical indicators to let us know what the exact value each of our knobs is showing. Follow the steps below to add these numerical indicators: - On the Front Panel, click on the Num Inds button in the Controls window - Click on the Num Inds button and place a Numerical Indicator Express VI on the front panel and change its name to Amplitude in the same way you changed the knobs name - To attach this numerical indicator to the knob, click on the output arrow of the knob and draw a connection to the input arrow of the indicator You now have a numerical display to tell you what the value of the knob is. Repeat this procedure for the frequency knob.

-6-

An Overview of National Instruments LabVIEW Part 1 3) We shall now add a waveform graph display to the Virtual Instrument. Follow the steps listed below to add this: - Click on the Front Panel window - From the Controls window, click on the Graph Inds button - Click on the Graph button - Click somewhere on the Front Panel to place the Waveform Graph on the Front Panel - The waveform graph (figure 12) should now be visible on the Front Panel

Figure 12 Note: By right clicking on the waveform graph, you can change a number of the properties. For this exercise, we wont change any, but just be aware of the options available. - To connect the output of the Simulate Signal Express VI to the Waveform Graph, you will again need to go to the Block Diagram, place the cursor over the arrow head for the Sine output, click, then click again on the input arrow head of the Waveform Graph You have now connected the output of your signal generator to the waveform output. To see the results, run the Virtual Instrument by going to the Front Panel and clicking on the forward arrow under the menu bar. To stop the Virtual Instrument, click the red circle on that same line, or click the stop button on the Front Panel. 4) Now lets set up something to collect some data from our signal. For this, we are going to need a number of tools. Follow the steps below to add some noise to the signal and display and record the peak values: - To add noise to your input signal, right click on the Simulate Signal Express VI and go to properties - Place a check mark in the Add Noise box - Leave the Noise Type as Uniform White Noise, but change the Noise Amplitude to 0.25 and click ok - Run your Virtual Instrument to see the effects of the noise - Now back on the Block Diagram window, click on the Analysis button on the Functions window -7-

An Overview of National Instruments LabVIEW Part 1 Choose the Amp & Level button Click on the Block Diagram window to place the Amplitude and Level Measurements Express VI into your Virtual Instrument A window (figure 13) should pop up

Figure 13 Click the boxes next to Maximum Peak and Peak to peak and click ok We now need to connect this measurement device to your signal, do this the same way you have connected the other devices - We now need to add something to the Front Panel to display the measurements we are collecting, so go back to the Front Panel - From the controls window, click the Text Inds button - Click on the Table button, then click on the Front Panel window to place the table - Since we are only taking two measurements, we can get rid of all but two of the columns, so right click on the table and go to properties - Change the number of columns to 2, then click ok - Now we need to connect the table display to the signals, so go back to the Block Diagram window - Notice that the Build Table Express VI and the Table display are already placed on the Block Diagram (they may have been placed outside the loop created earlier, so drag a box around them to select them, then move them inside the loop) - Now connect each of the outputs from the Amplitude and Level Measurements Express VI to the Signals input of the Build Table Express VI - Notice that a new icon is inserted after you connect the second wire - This new icon is called the Merge Signals Express VI and allows you to put 2 or more inputs into one terminal Run your Virtual Instrument and watch as the table is automatically updated with the peak to peak and the maximum peak values. Now we should add something to write this data to a file so we dont lose it. - Go back to the Block Diagram window and click on the Output button on the Functions window

-8-

An Overview of National Instruments LabVIEW Part 1 Click on the Write LVM button, then click on the Block Diagram window to place your Write LabVIEW Measurement File Express VI into your Virtual Instrument A new window (figure 14) should pop up

Figure 14 Change the File name to a name and location that you have access to Click the One header only button under Segment Headers and the Overwrite file button under If a file already exists and click ok - Click and drag the double arrow at the bottom of the Write LabVIEW Measurement File Express VI until you see the Enable input - Connect the two outputs from the Amplitude and Level Measurements Express VI to the Signals input of the Write LabVIEW Measurement File Express VI - We now want to add a button to control when the file is actually written to, so go back to the Front Panel - From the Controls window, click on the Buttons button - Select the Push Button and place it on the Front Panel - Right click on the Push Button and go to properties - Change the Label to Write to File - Back on the Block Diagram, connect this new button to the Enable input of the Write LabVIEW Measurement File Express VI - Run your Virtual Instrument and press the button a couple of times to write to the file, maybe changing the amplitude or frequency with your knob to see what happens to the data Note: You can also specify the file location in a more dynamic way. Lets see how to specify the file location using a File Path Control Express VI. - Select the Front Panel window - From the Controls window, select the Text Ctrl button - Click on the File Path Ctrl button and place it on the Front Panel - Return to the block diagram and connect the File Path Control Express VI to the File Name input on the Write LabVIEW Measurement File Express VI You can now dynamically change the location of the file by simply browsing for the file using the File Path Control Express VI on the front panel instead of going into the properties of the Write LabVIEW Measurement File Express VI. -9-

An Overview of National Instruments LabVIEW Part 1 6) Now lets say there is a certain voltage level you dont want your Virtual Instrument to experience. We can set up an indicator to let you know if you exceed that voltage. Complete the following steps to add this feature to your Virtual Instrument: - From the Block Diagram window, click on the Arith/Compare button on the Functions window - Click on the Comparison button, then select the Comparison Express VI and place it on your Block Diagram - The following window (figure 15) should come up

Figure 15 Click on the >= Greater or equal button under Compare Condition, then change the constant value to 15 under Comparison Inputs and click ok Connect the Peak to Peak output of the Amplitude and Level Measurements Express VI to the Operand 1 input of the Greater or Equal Express VI Now we need an indicator to tell us if we hit this level, so go to the Front Panel From the Controls window, click on the LEDs button Select either of the two options and place the LED on your Front Panel Right click on the LED, go to properties, uncheck the box next to Visible in the Label box, check the box next to Boolean Text, the box next to Lock text in center, then enter Warning in the box next to On text and delete the text in the box next to Off text (you can also change the colors to red, since this will be a warning light) We now need to go back to the Block Diagram and connect the LED to the comparator Connect the Result output of the Greater or Equal Express VI to the input arrow head of the LED Run your Virtual Instrument and change the amplitude to see if the warning light will come on when you get to the appropriate level

7) Now lets get into a little more advanced functions. First, lets add a filter to try to get rid of some of the noise: - On the Block Diagram, click on the Analysis button from the Functions window - 10 -

An Overview of National Instruments LabVIEW Part 1 Click on the Filter button Click on the Block Diagram to add the Filter Express VI to your program The following window should pop up (figure 16)

Figure 16 Change the Cutoff Frequency to 1000 and the Order of the filter to 5 and click ok (if you click on the Transfer function button, you can see the transfer function of the filter you are creating) - Now connect the output of the Simulate Signal Express VI to the Signals input of the Filter Express VI, then connect the Filtered Signals output of the Filter Express VI to the Waveform Graph from before You will now see both the original and filtered waveforms on the same graph. Run your program and change the frequency using the knob to see the effects of the filter on the sine wave. 8) We can also plot the spectrums of the original and filtered signals. For this we will use the Spectral Measurements Express VI: - On the Block Diagram, select the Analysis button from the Functions window - Click on the Spectral button and place it on the Block Diagram - The following window should appear (figure 17) -

Figure 17 - 11 -

An Overview of National Instruments LabVIEW Part 1 We will not be changing any of the settings, so simply click ok Now wire the outputs from the Simulate Signal Express VI and the Filter Express VI to the Signals input of the Spectral Measurements Express VI - Go to the Front Panel and place a second Waveform Graph on it - Return to the Block Diagram and wire the FFT (RMS) output of the Spectral Measurements Express VI to the input of the Waveform Graph You now can view the spectrums of the original and filtered waveforms. Run your program and change the frequency and watch as the spike in the spectrum moves to match the changes you make. 9) So we are finally to the last part. We are now going to add another way of generating signals to the program and a way to select which method to use. Follow the steps below to add the Read LabVIEW Measurements File Express VI to your program and some logic to select whether to use the Simulate Signal or the Read LabVIEW Measurements File Express VIs. - On the Block Diagram, select the Input button from the Functions window - Click on the Read VLM button and place it in the Block Diagram - The following window should pop up (figure 18) -

Figure 18 Change the Delimiter to Tab and check the boxes next to First row is channel names and First column is time channel, then click ok - Add a File Path Control VI to the Front Panel and connect it to the File Name input of the Read LabVIEW Measurement File Express VI as you did for the Write LabVIEW Measurement File Express VI - Connect the Signals output of the Read LabVIEW Measurement File Express VI to the Sine output of the Simulate Signals Express VI You now have two signal sources, but now way of choosing with one to use, so lets add some controls: - 12 -

An Overview of National Instruments LabVIEW Part 1 On the Block Diagram, right click on the line coming out from the Sine output of the Simulate Signal Express VI (before the merge signals icon appears) and go to Insert Navigate over to the Sig Manip button and then to the Relay and left click This inserts the Relay Express VI in series with that line The following window should appear (figure 19)

Figure 19 Change the Output when Relay Off to 0 values, then click ok We now need to add a number of buttons and indicators, so return to the Front Panel - Add a horizontal Slide Switch and two LEDs to the Front Panel - Change the label of the Slide Switch so that the left side is the Simulate Signal side and the right side is the Read File side - Change the labels of the two LEDs so that one says Simulate Signal and the other says Read LVM - Return to the Block Diagram - Since the switch is either on or off, we will need to use a NOT gate to make the switch active when it is off - From the Functions window, select Arith/Compare, then Boolean, then select the Not button and place it on the Block Diagram - Connect the output of the Slide Switch to the input to the Not Express VI, then connect the output of the Not Express VI to the Enable input of the Relay Express VI as well as the input to the Simulate Signal LED - Now connect the output of the Slide Switch to the input to the Read LVM LED and the Enable Input of the Read LabVIEW Measurement File Express VI You now have a mechanism for choosing which signal generator you want to use. When the switch is to the left, the Simulate Signal LED will light up and the Relay Express VI will allow the signal to pass through. When the switch is to the right, the Relay Express VI will turn off and the Read LabVIEW Measurement File Express VI becomes enabled. Play around with your program to see how it functions. -

- 13 -

An Overview of National Instruments LabVIEW Part 1 Conclusion: You have now completed your first Virtual Instrument. This has shown you some of the basic applications available in LabVIEW, but there are certainly many more things you can do. From here, you should be able to build your own Virtual Instruments to perform a large number of functions. Below are images (figures 20 and 21) of what your Virtual Instrument might look like.

Figure 20

Figure 21 - 14 -

You might also like