40
1 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 a waveform graph. The User Interface you create will enable you to change the attributes of the simulated signal. 1. If you have not already done so, launch LabVIEW. Click the LabVIEW icon on your quick launch toolbar, or click Start » Programs» National Instruments» LabVIEW 2009. Once you launch LabVIEW, the Getting Started window appears: The LabVIEW Getting Started window appears each time you launch LabVIEW to assist you in creating new applications or opening existing applications. Additionally you can use links on the Getting Started window to find local and online help resources or open example programs to aid in application design. 2. Click More… 3. Expand From Template. Notice the different categories on the left of the window that correspond to the types of tasks from which you can choose. You can select Blank VI to start from scratch. There are also Template VIs to use as a starting point for building your application. Projects and Other Files are more advanced components and will not be described in detail. To get more information on any of the listings in the New Dialog Box, click the Help button in the lower right corner of the window.

Labview Daq Hands on Exercises

Embed Size (px)

Citation preview

Page 1: Labview Daq Hands on Exercises

1  

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 a waveform graph. The User Interface you create will enable you to change the attributes of the simulated signal. 

1.  If you have not already done so, launch LabVIEW.  Click the LabVIEW icon on your quick launch toolbar, or click Start » Programs» National Instruments» LabVIEW 2009. 

 

 

 

Once you launch LabVIEW, the Getting Started window appears: 

 

  

The LabVIEW Getting Started window appears each time you launch LabVIEW to assist you in creating new applications or opening existing applications.  Additionally you can use links on the Getting Started window to find local and online help resources or open example programs to aid in application design. 

2.  Click More… 

3.  Expand From Template. Notice the different categories on the left of the window that correspond to the types of tasks from which you can choose. You can select Blank VI to start from scratch. There are also Template VIs to use as a starting point for building your application. Projects and Other Files are more advanced components and will not be described in detail. To get more information on any of the listings in the New Dialog Box, click the Help button in the lower right corner of the window. 

 

 

Page 2: Labview Daq Hands on Exercises

2  

4.  Select VI»From Template»Tutorial (Getting Started) »Generate and Display and click OK.   

 

Two windows appear. The grey window is the front panel, and the white one is the block diagram. The front panel contains the parts of your VI used for presenting information, whereas the block diagram contains the code that controls the functionality of the VI.  

 

5.  Examine the front panel and block diagram of this template VI. The front panel contains a Waveform Chart and a STOP button as shown in the following figure. 

 

 

 

Page 3: Labview Daq Hands on Exercises

3  

Hover the cursor over the different objects on the front panel.  Notice that your cursor turns to a pointer finger when above the Stop button, and turns to a text editor when above a text field.  By default, LabVIEW’s Automatic Tool Selection will change the cursor depending on what operations are possible.  Also notice that as you move over any object, resizing boxes appear on its edges.  Try resizing a few objects’ sizes. 

 

You can toggle between the two windows by selecting Window»Show Block Diagram or Window»Show Front Panel. You can also switch between the windows by pressing <Ctrl‐E> on the keyboard. 

The block diagram contains a Simulate Signal VI, which is currently configured to simulate a sine wave and plot it to the chart. 

 

6.  Switch back to the front panel by pressing <Ctrl‐E>. Notice the menu bar at the top of the window. Since the Run button (the white arrow in the top left corner) is solid, you can run this VI as it is. Click the Run button and examine the operation of the VI. When you are finished, click the STOP button on the front panel to stop running the VI. 

 

Note: As you will see later in the exercise, when the Run button in the upper left corner of both the front panel and the block diagram changes from a solid white arrow, to a broken grey arrow, indicates that there are unresolved errors in the code. You can press the broken Run arrow to assist you in resolving these errors. 

 

Page 4: Labview Daq Hands on Exercises

4  

7.  We will now add controls to adjust signal frequency and amplitude while the program is running.  Open the Controls 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.  

 

8.  Click the Numeric Controls palette, and select a Knob to be placed on the front panel. To do this, click the Knob and drag it to the front panel. Click once to place it 

 

9.  Double‐click on the knob’s label and change it to “Amplitude.” 

 

10.  Repeat steps 7‐9 to make another knob for frequency.  Change its label to Frequency.  Double‐click the maximum value on Frequency’s scale and change it to 50. 

 

 

 

 

Page 5: Labview Daq Hands on Exercises

5  

11.  On the block diagram, move the Amplitude and Frequency controls inside of the while loop and connect them to the associated inputs of the Simulate Signal Express VI.  Once both terminals are inside the while loop, on the left side of the Simulate Signal Express VI, hover your cursor over the right side of each terminal until the wiring tool appears on the cursor.  Left‐click and drag the connection to the identically named input on the Express VI. Your block diagram should look like the image below. 

Front Panel            Block Diagram 

12.  Use Block Diagram Cleanup to organize your block diagram.  As you program, and especially as you learn how to program in LabVIEW, you are not always thinking about layout and readability.  This can result in poorly organized block diagram. Press the Block Diagram Cleanup icon found on the menu bar which will organize the block diagram for you. 

 

Note: To customize how the Block Diagram Cleanup tool organizes your code you can change settings in the “Block Diagram: Cleanup” section of the Options menu (Tools» Options…). 

 

13.  Highlight Execution is a debugging tool that allows you to observe how your application runs.  Press the Highlight Execution button on the menu bar. Notice that the light bulb icon now appears to be on. Then hit the Run button whilst still on the block diagram and watch the data flow through the wires. Stop the application and press the Highlight Execution button to disable it. 

 

 

Page 6: Labview Daq Hands on Exercises

6  

14.  Use Context Help to identify object details while programming.  Press the Context Help button in the upper right portion of the block diagram. 

 

15.  With the Context Help active, hover your cursor over different objects on the block diagram and front panel of your VI.  As you do so, the Context Help Window provides details including descriptions and wiring diagrams.  

 

16.  Right‐click on the block diagram and navigate around the palettes.  Notice that the Context Help window provides details on the objects while they are in the palettes. Also notice that for some objects, the Context Help window provides a link for “Detailed Help…”  This link will open the LV Help and give you more information. 

 

17.  Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder by using the File menu and name it Exercise1.vi. 

Note: Be sure to save this VI, as you will be using it later in the seminar. You can access the folder by the folder shortcut on the desktop 

End of Exercise 1 

 

 

 

 

Page 7: Labview Daq Hands on Exercises

7  

Exercise 2a: Take a Basic Measurement with CompactDAQ The purpose of this exercise is to use LabVIEW and NI CompactDAQ to quickly set up a program to acquire temperature data. 

Set up the Hardware 

1.  Make sure that the NI CompactDAQ chassis (cDAQ‐9172) is powered on. 

2.  Connect the chassis to the PC using the USB cable. 

3.  The NI‐DAQmx driver installed on the PC automatically detects the chassis and brings up the following window. 

 

4.  Click on Configure and Test This Device Using NI Measurement & Automation Explorer (MAX). 

Note: NI Measurement & Automation Explorer is a configuration utility for all National Instruments hardware. 

5.  The Devices and Interfaces section under My System shows all the National Instruments devices installed and configured on your PC. The NI‐DAQmx Devices folder shows all the NI‐DAQmx compatible devices. By default, the NI CompactDAQ chassis NI cDAQ‐9172 shows up with the name “cDAQ1”.  

6.  This section of MAX also shows the installed modules as well as empty slots in the CompactDAQ chassis. 

7.  Right‐click on NI cDAQ‐9172 and click on Self‐Test. 

 

8.  The device passes the self test, which means it has initialized properly and is ready to be used in your LabVIEW application. Close MAX. 

 

Page 8: Labview Daq Hands on Exercises

8  

Program LabVIEW Application 

9.  Create a new VI.  On the LabVIEW menu bar click File» New VI.  Once opened, Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder under the name “Exercise 2a.vi.” 

10.  Press <Ctrl +T> to tile front panel and block diagram windows. 

11.  Pull up the Functions Palette by right‐clicking on the white space on the LabVIEW block diagram window. 

12. Move your mouse over the Express» Input palette, and click the DAQ Assistant Express VI. Left‐click on the empty space to place it on the block diagram. 

 

13.  The Create New Express Task… window then appears: 

 

14.  To configure a temperature measurement application with a thermocouple, click on Acquire Signals» Analog Input» Temperature» Thermocouple. Click the + sign next to the cDAQ1Mod1 (NI 9211), highlight channel ai0, and click Finish. This adds a physical channel to your measurement task. 

Page 9: Labview Daq Hands on Exercises

9  

15.  Change the CJC Source to Built In and Acquisition Mode to Continuous Samples. Click the Run button. You will see the temperature readings from the thermocouple in test panel window. 

 

16.  Click Stop and then click OK to close the Express block configuration window to return to the LabVIEW block diagram.  

 

17.  LabVIEW automatically creates the code for this measurement task. Click Yes to automatically create a While Loop. 

 

 

 

 

 

 

 

Page 10: Labview Daq Hands on Exercises

10  

18. Right‐click the data terminal output on the right side of the DAQ Assistant Express VI and select Create» Graph Indicator.  Rename “Waveform Graph” to Temperature. 

 

19.  Notice that a graph indicator is placed on the front panel. 

20.  Your block diagram should now look like the figure below. The while loop automatically adds a stop button to your front panel that allows you to stop the execution of the loop. 

 

21.  Rather than displaying our data in a graph indicator, we want to display our temperature readings in a thermometer indicator. To do this, go to the front panel by pressing <Ctrl‐E>. Right‐click the graph indicator and select Replace. The Controls palette will appear. Select Modern»Numeric»Thermometer. The thermometer indicator should now appear instead of the graph indicator. 

 

Page 11: Labview Daq Hands on Exercises

11  

22.  Also, right‐click on the stop (F) button and select Replace. The Controls palette will appear. Select Boolean»Stop Button. 

 

 

23.  You can use the property page for any front panel object to change any of its associated properties. Modify the thermometer indicator by right‐clicking it and selecting Properties. On the Appearance Tab, change the Label to Temperature. 

 

 

 

 

 

Page 12: Labview Daq Hands on Exercises

12  

24.  On the Scale tab, change the Minimum to 20 and the Maximum to 30. 

 

 

 

 

 

 

 

 

 

 

 

25.  Click OK when you are finished and save the VI. 

 

Express VIs make creating basic applications very easy.  Their configuration dialogs allow you to set parameter and customise inputs and outputs based on your application requirements.  However, to optimize your DAQ application’s performance and allow for greater control you should use standard DAQmx driver VIs.  Right Click on block diagram Functions» Measurement I/O Palette» NI‐DAQmx. 

26.  Before you generate DAQmx code you need to remove all the code that was automatically created by the Express VI.  Right click on the while loop and select “Remove While Loop.”  Then click on the Stop button control, and press the Delete key to remove the Stop button.  Repeat actions for Temperature Graph as well as any additional wires that may remain.  You can press <Control + B> to remove all unconnected wires from a block diagram. 

 

 

 

 

 

 

Page 13: Labview Daq Hands on Exercises

13  

27.  Convert Express VI code to standard VIs.  While not all Express VIs can be automatically converted to standard VIs, the DAQ Assistant can.  This will allow for greater application control and customization.  Right‐click on the DAQ Assistant Express VI you created in this exercise and select “Generate NI‐DAQmx Code.” 

 

Your block diagram should now appear something like this: 

 

The Express VI has been replaced by two VIs.  We’ll examine their functionality in the following steps. 

28.  Open Context Help by clicking on the Context Help icon on the upper right corner of the block diagram.  Hover your cursor over each VI and examine their descriptions and wiring diagram. 

29.   DAQmx Read.vi reads data based on the parameters it receives from the currently untitled VI on the far left. 

30.  Double‐click on the untitled VI and open that VI’s block diagram (code shown below). 

 

 

Page 14: Labview Daq Hands on Exercises

14  

All the parameters that are wired as inputs to the different DAQmx setup VIs reflect the setting you originally configured in the DAQ Assistant Express VI. 

Note:  By moving these parameters and setup VIs onto the block diagram, you can now programmatically change their values without having to stop your application and open the Express VI configuration dialog, saving development time and possibly optimizing performance by eliminating unnecessary settings depending on your application. 

 

Using the LabVIEW Example Finder 

The LabVIEW Example Finder provides hundreds of example application to use as reference or as the starting point for your application.   

31.  Open the LabVIEW Example Finder to find DAQ examples that use DAQmx standard VIs.  Go to Help» Find Examples… to launch the LabVIEW Example Finder. LabVIEW then indexes all the examples installed on the local machine. 

32.  Browse to the DAQmx Temperature folder from the Browse tab at Hardware Input and Output » DAQmx » Analog Measurements » Temperature. Double Click on the “Acq Thermocouple Sample.vi” to open it. 

 

 

 

 

 

 

 

Page 15: Labview Daq Hands on Exercises

15  

33.  The following VI will then appear:  

 

34.  Set the Physical Channel to match the CompactDAQ chassis channel and run the application.  Expand the physical channel control from the Front Panel and select cDAQ1Mod1/ai0. 

 

Press the Run button several times while holding and releasing the thermocouple on the CompactDAQ chassis and observe the value change on the front panel. 

35.  Open the block diagram and examine the code.  This VI only uses standard VIs instead of Express VIs, which allows much more customization of inputs and run‐time configuration.  Acq Thermocouple Sample.vi has no while loop to allow for continuous execution, and the remaining steps of this exercise will focus on adding that functionality. 

 

 

Page 16: Labview Daq Hands on Exercises

16  

36.  Add a while loop and Stop button to Acq Thermocouple Sample.vi.  Right‐click on the block diagram to bring up the Functions palette.  Find the While Loop on the Programming» Structures palette and drag a while loop over the DAQmx Read.vi.  You may need to spread the VIs across the block diagram so that there is room.  You can create additional space by holding the Control key and dragging a box on the block diagram or front panel. 

 

37. Right click on the While Loop’s Conditional terminal and select “Create Control.”  This automatically wires a Stop button to the terminal. 

 

Notice that the Stop button has appeared on the front panel. 

38.  Run the VI.  Acq Thermocouple Sample.vi now runs continuously.   

39.  Save the customized example VI.  Go to File» Save As…, select Copy» Substitute Copy for Original and name the VI “Temperature.vi”  Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder. This allows for further development without overwriting the LabVIEW example. 

End of Exercise 2a 

 

 

Page 17: Labview Daq Hands on Exercises

17  

Exercise 2b: Add Analysis and Digital Output to the DAQ Application Set up Hardware 

1.  Confirm that the CompactDAQ chassis is powered on and connected to the PC via the USB cable.  If not, or if it is not behaving as expected, repeat steps 1‐8 from Exercise 2a. 

LabVIEW Application – Compare signal to user‐defined alarm  

2.  Exercise 2b is functionally the same as the end result of Exercise 2a.  You can open Exercise 2b.vi from the Exercises folder to synchronise with the illustrations in this section. The VI will appear like the image below, with additional space on the block diagram to add functionality: 

 

3.  Create an alarm that signals if acquired temperature goes above a user‐defined level.  On the front panel, right‐click to open the Controls palette Express» Numeric and place a Vertical Pointer Slide on the front panel. 

Page 18: Labview Daq Hands on Exercises

18  

4.  Right‐click the Vertical Pointer Slide and select Properties. A property page will appear. Examine the different properties that you can modify. Make the following changes on the Appearance. 

Label: Alarm Level 

Slider 1: Check Show digital display(s) 

 

5.  On the Scale tab make the following changes to Scale Range and click OK to apply the changes. 

Maximum: 30

Page 19: Labview Daq Hands on Exercises

19  

6.  Use the Comparison Express VI to compare the acquired temperature signal with the Alarm Level control.  Switch to the block diagram, right‐click on an empty space and open the Functions palette.  Place the Comparison Express VI on the block diagram from Functions» Express» Arithmetic & Comparison» Comparison.   

 

7.  Once placed on the block diagram, the Comparison Express VI's configuration dialog will appear. 

 

Select "> Greater" in the Compare Condition section and "Second signal input" from the Comparison Inputs section then click OK. 

Page 20: Labview Daq Hands on Exercises

20  

8.  Connect the acquired temperature data and Alarm Level inputs to the Comparison Express VI.  Hover over the output of the DAQ Assistant until the wiring tool appears on your cursor, then left‐click and drag you mouse to the Operand 1 input on the Comparison Express VI.  Perform the same hover, drag and connect to wire the Alarm Level control and the Operand 2 input on the Comparison Express VI.  Your block diagram should now look like this: 

 

9.  Display the result of the Comparison Express VI on the front panel.  On the front panel, right click, open the Controls palette and add a Square LED indicator.  The square LED is found at Express» LED.  Resize the Square LED so that it is easier to see and rename it "Alarm."  Your front panel should look like this: 

 

 

 

 

 

 

Page 21: Labview Daq Hands on Exercises

21  

10.  On the block diagram, wire the output of the Comparison Express VI to the input of the Alarm indicator's terminal.   

 

11.  Run the application.  Press the Run button and then change the Alarm Level control to some level above the current acquired temperature signal.  Hold the thermocouple until the temperature exceeds the Alarm Level value.  The Alarm LED turns on when the acquired temperature signal goes above the level set on the front panel. 

 

Output Alarm to CompactDAQ Chassis 

12.  Use another DAQ Assistant Express VI to output Alarm's status to the CompactDAQ's 9472 module.  Open the Functions palette on the block diagram and find the DAQ Assistant Express VI at Functions» Express» Output. 

 

 

 

 

Page 22: Labview Daq Hands on Exercises

22  

13.  Select Generate Signals» Digital Output» Line Output from the Create New Express Task… window.  

 

14.  Select the physical channel you want to use as output.  Expand the + sign next to cDAQ1Mod4 in the following window and select port0/line0. 

 

15.  Press OK in the DAQ Assistant window that appears, since all of its settings are correct for the application. 

 

 

 

 

Page 23: Labview Daq Hands on Exercises

23  

16.  Create an additional wire that connects the Comparison Express VI’s Result output to the data input on the new DAQ Assistant Express VI.  A Convert from Dynamic Data function appears automatically.  LabVIEW will always try to coerce unlike data types when two nodes are wired together.  In this case, the output of the Compare Express VI is a Dynamic Data type, and the input of the DAQ Assistant is Boolean.  LabVIEW placed the Convert from Dynamic Data node in between the two nodes so they could be connected.  You can double‐click the Convert from Dynamic Data to view its configuration.  Your block diagram should now look like this: 

 

17.  Run the VI.  Press the Run button.  Notice that the LED bank on the CompactDAQ 9472 module turns on and off to match Alarm's value on the front panel. 

18.  Save and close the VI. 

 End of Exercise 2b 

 

 

 

Page 24: Labview Daq Hands on Exercises

24  

Exercise 3a: Writing Data to File with LabVIEW 1.  If not already opened, open “Exercise 2b.vi” from the Exercises folder found in C:\Seminars\DAQ Hands On\Exercises. 

2.  Right‐click on the block diagram and select Functions» Express» Output» Write to Measurement File and place it inside the While Loop on the block diagram.

 

3.  A configuration window will appear. Configure the window as shown below and click OK. 

 

Note: Click on the Help button for a more detailed explanation of the settings in this dialog box.  

Page 25: Labview Daq Hands on Exercises

25  

4.  Wire the output of the DAQ Assistant Express VI to the input of the Write to Measurement File Express VI.   

5.  Your block diagram should now resemble the following figure. 

 

6.  Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder by using the File» Save As… menu, select the Copy» Substitute Copy for Original and name it Exercise 3a.vi. 

7.  Run the VI momentarily and press STOP to stop the VI. 

8.  Your file will be created in the folder specified.  

9.  Open the file using Microsoft Office Excel or Notepad. Review the header and temperature data saved in the file.  

10.  Close the data file. 

End of Exercise 3a 

 

 

 

 

 

 

 

 

 

 

 

 

Page 26: Labview Daq Hands on Exercises

26  

Exercise 3b: Controlling Program Execution In this exercise you will use a Case Structure to add intelligence into your application. You are going to modify the VI so that the temperature is only logged to disk if the alarm condition is met. 

1.  If not already opened, open “Exercise 3a.vi” from the Exercises folder found in C:\Seminars\DAQ Hands On\Exercises. 

2.  Select the Case Structure from the Execution Control palette and place it around the Write to Measurement File Express VI as shown below. 

 

The case structure has one or more subdiagrams, or cases, exactly one of which executes when the structure executes. The value wired to the selector terminal determines which case to execute and can be Boolean, string, integer, or enumerated type. Right‐click the structure border to add or delete cases. The code for these different states would reside within the boundaries of the case structure, and you would switch between the states with either buttons on a front panel or some combination of logic built into your LabVIEW application. 

3.  Examine the Case Structure. 

 

      

Page 27: Labview Daq Hands on Exercises

27  

4.  Wire the Result from the Compare Express VI to the selector terminal of the case structure as shown below. 

 

Now the data will only be logged to disk when the alarm is active. Because the False case is empty, nothing will happen when alarm condition is not met. 

5.  Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder by using the File» Save As… menu, select the Copy» Substitute Copy for Original and name it Exercise 3b.vi. 

6.  Run the VI. Change the alarm level and heat the thermocouple so that the alarm goes on and off a few times. Press STOP to stop the VI. 

7.  Your file will be created in the folder specified.  

8.  Open the file using Microsoft Office Excel or Notepad. Review the header and temperature data saved in the file.  

9.  Close the data file. 

 

 

 

 

 

 

 

 

 

 

Page 28: Labview Daq Hands on Exercises

28  

Optional Steps 

Add logic to the VI so it will stop either when you press the STOP button or when the loop iterations have exceeded 10,000. 

1.  Insert an Or gate from the Boolean palette before the STOP button, by right clicking on the green wire out of the stop terminal, as shown below. 

 

   2.  Next Select the greater than function from the Comparisons palette. 

 

Page 29: Labview Daq Hands on Exercises

29  

3.  Wire as follows. 

 

4.  Right‐click on the open terminal of the greater than block and select Create»Constant. 

5.  Change the constant to 10000 as shown below and Save and Run the VI. 

Page 30: Labview Daq Hands on Exercises

30  

6.  Save the VI in the C:\Seminars\DAQ Hands On\Exercises folder by using the File» Save As… menu, select the Copy» Substitute Copy for Original and name it Exercise 3b.vi. 

 

7.  Finally, open and examine the State Diagram template that ships with LabVIEW. Select File»New and select Standard State Machine from the list box as shown below. Examine the comments included on the template. There are several templates such as this one to help you get started with your LabVIEW applications. Take a few minutes to familiarize yourself with what is available.  

 

End of Exercise 3b. 

 

 

 

 

 

 

 

 

 

Page 31: Labview Daq Hands on Exercises

31  

(Optional) Exercise 4: Multiple Operations with Analog I/O  

1.  If you closed LabVIEW after the last exercise, launch it. Open a new VI.  

2.  Press <Ctrl‐E> to switch to the LabVIEW block diagram.  

3.  Browse to the Input subpalette on the Functions»Express palette and click the Simulate Sig Express VI as shown below. Place the VI on the block diagram. 

 

4.  In the Signal section of the window, set Amplitude to 5.  

5.  In the Timing section of the window, set Samples per second (Hz) to 10,000. Click OK. 

 

6.  Bring up the Functions»Express palette again, and browse to the DAQ Assistant Express VI on the Output subpalette of the Functions palette. Place the VI on the block diagram.  

 

Page 32: Labview Daq Hands on Exercises

32  

7.  In the Create New window, select Analogue Output as the Measurement Type and then select Voltage. 

 

 8.  In the next window, click the + sign next to cDAQ1Mod3 (NI 9263), select ao0, and click the Finish button.  

 

          

Page 33: Labview Daq Hands on Exercises

33  

9.  In the DAQ Assistant configuration window, select Continuous Samples from the Task Timing tab in the lower part of the window. Uncheck Use timing from waveform data, set the Samples to write and Rate (Hz) to 10,000. Click the OK button and select no when asked if you want to insert a while loop.  

 

10.  On the block diagram, move the DAQ Assistant Express VI to the right side of the Simulate Signal Express VI. Wire the Sine output of the Simulate Signal VI to the data input of the DAQ Assistant VI. To create a wire, move your cursor over the blue arrow on the Sine output terminal of the Simulate Signal VI and left‐click to start the wire. Move your cursor to the data input terminal of the DAQ Assistant VI and left‐click again to attach the wire. Your block diagram should resemble the following figure.  

 

Page 34: Labview Daq Hands on Exercises

34  

11.  To make the VI run continuously, create a While Loop. A While Loop causes all parts of the program inside the loop to run continuously until a Stop button is clicked. To create the While Loop, browse to the Exec Ctrl subpalette of the Functions palette and select a While Loop. 

 

12.  Draw the While Loop around your entire block diagram. Your block diagram should resemble the following figure. 

 

13.  To create a slide control for varying the frequency of the sine wave, press <Ctrl‐E> to switch to the LabVIEW front panel. Right‐click on the empty grey space to pull up the Controls palette. Select Vertical Pointer Slide from the Numeric Controls sub‐palette of the Controls palette. Place the vertical pointer slide on the front panel. 

 

Page 35: Labview Daq Hands on Exercises

35  

14.  Right‐click the slide control and select Properties. On the Appearance tab, change the label to Frequency. On the Scale tab, change the Scale Range so Minimum equals 0.00 and Maximum equals 1000.00. Click OK to close the Properties window.  

15.  Press <Ctrl‐E> to switch to the block diagram. Notice the orange Frequency slide control terminal. Move the control inside the While Loop to the left side of the Simulate Signal Express VI. Wire the knob control to the Frequency input terminal of the Simulate Signal Express VI (the second orange arrow on the left side of the Simulate Signal Express VI).  Note: Make sure that you wire the knob control to the correct input terminal of the Simulate Signal Express VI. If you make a bad wire connection, double‐click the wire to select it and press <Delete>.  Your block diagram should resemble the following figure.  

 

 

16.  This VI will now use the frequency slide on the LabVIEW front panel to generate a sine wave at the specified frequency. This sine wave is then generated on analog output channel 0 of the NI 9263 C Series module by the DAQ Assistant Express VI.  

17.  Save the VI as Analog output.vi in the C:\Seminars\DAQ Hands On\Exercises folder.  

18.  Increase the size of the block diagram window to make space for another While Loop to go below the existing Analog Output code. 

 

 

 

 

 

Page 36: Labview Daq Hands on Exercises

36  

19.  Place a DAQ Assistant Express VI from the Input sub‐palette of the Functions»Express palette. Select Analog Input as the Measurement Type and select Voltage. In the next window, expand channels of the cDAQ1Mod2 (NI 9215) by selecting the + sign, and select ai0. Click the Finish button.  

 

20.  In the DAQ Assistant window, select Continuous Samples from the Task Timing tab in the lower part of the window. Set the Samples to write and Rate (Hz) to 10,000 and click OK.  

 

 

Page 37: Labview Daq Hands on Exercises

37  

21.  Once you click OK, a dialog window will appear asking if you would like to create a While Loop around the DAQ Assistant. Select Yes to automatically create a While Loop for this continuous acquisition.  

 

 

22.  The block diagram should resemble the figure above. Next, create a graph indicator to display the analog input data. To create a graph indicator, right‐click the data output terminal of the DAQ Assistant Express VI, and select Create Graph Indicator. 

Page 38: Labview Daq Hands on Exercises

38  

23.  Below is a picture of the completed block diagram. 

 

24.  Press <Ctrl‐E> to switch to the LabVIEW front panel.  

25.  Locate the stop (F) Push Button control and right‐click to replace it with a Stop Button control, as shown on the diagram below. (Replace»Boolean»Stop Button) 

 

 

 

 

Page 39: Labview Daq Hands on Exercises

39  

26.  Rearrange the front panel controls and indicators to resemble the figure below. 

 

 

 

27.  Save the VI as Analog Input and Output.vi in the C:\Seminars\DAQ Hands On\Exercises folder.  28.  Run the VI  29.  The analog output loop is generating a sine wave on analog output channel 0, which is wired directly to channel 0 of the analog input module. Use the slider control on the front panel to control the sine wave frequency, and look at the graph on the front panel to monitor the sine wave.  30.  Press both stop buttons to stop the execution of both loops.  

 

 

 

 

 

 

 

 

 

Page 40: Labview Daq Hands on Exercises

40  

Beyond the Exercise For Loops can be used to generate arrays using a feature called automatic indexing, as shown in the following figure. 

 

Try building the following block diagram to further manipulate the waveform being generated. 

 

 

End of Exercise 4