LabVIEW DAQ Hands On Manual

Share Embed Donate


Short Description

Hands-On Introduction to Data Acquisition...

Description

n i . c o m/ e v e n t s

Hands onI nt r oduct i on t oDat aAcqui s i t i on wi t hL abVI EW

ni . com/ uk ni . com/ i r el and ni . com/ uk/ hands on

Introduction to LabVIEW and Computer-Based Measurements Hands-On Seminar

1

Company Profile •

Leaders in Computer-Based Measurement and Automation



Long-term Track Record of Growth and Profitability



$660M Revenue in 2006



$184.4M in Q3 2007 (12% YOY)



More than 4,300+ employees; operations in 40+ countries



Fortune’s 100 Best Companies to Work For 8th Consecutive Year



FT 50 Best Workplaces UK 2006 & 2007

2

National Instruments Vision “To do for test and measurement what the spreadsheet did for financial analysis.”

Virtual Instrumentation The software is the instrument

3

Hands-on Introduction to Data Acquisition with LabVIEW

1

The NI Approach – An Integrated Platform

PXI Modular Instrumentation

Multifunction High-Resolution Data AcquisitionDigitizers and DMMs Digital I/O

High-Speed Digitizers

Acoustics RF Signal

Keypad LCD Sound

Instrument Control

Dynamic Signal Acquisition

Temperature Monitoring

Process Control

Battery

Laptop PC

Desktop PC

Counter/ Timers

Machine Vision

Waste Monitoring

PDA

Distributed I/O and Embedded Control

Motion Control

Body & Chassis Audio Engine Durability

Motor and Valve Control

Emissions Electronics Safety Tire & Brake

4

Agenda • Introduction to LabVIEW 

Exercise 1: Create a simple LabVIEW VI

• Data Acquisition with LabVIEW 

Exercise 2a – 2c: Introduction to Data Acquisition with LabVIEW

• Decision making in LabVIEW 

Exercise 3: Controlling program execution

• Analogue Output and Digital Control 

Multiple operations with Analogue IO

5

Introduction to LabVIEW

6

Hands-on Introduction to Data Acquisition with LabVIEW

2

LabVIEW Graphical Programming

• Compiled graphical development environment • Development time reduction of four to ten times • Tools to acquire, analyze, and present your data

7

The LabVIEW Environment Front Panel – User Interface

Block Diagram – Compiled Code

8

Graphical Programming – Dataflow 1

Start of Data Flow

2

VIs execute once all inputs are available

10

Hands-on Introduction to Data Acquisition with LabVIEW

3

Automatic Multithreading in LabVIEW • LabVIEW automatically divides each application into multiple execution threads • LabVIEW introduced multithreading in 1998

11

Automatic Multithreading in LabVIEW • LabVIEW automatically divides each application into multiple execution threads • LabVIEW introduced multithreading in 1998 thread thread thread

12

Exercise 1: Create a Simple LabVIEW VI What you will learn: – Working in the LabVIEW environment

Create an application that: – Simulates data collection – Performs RMS Calculation – Turns on an a front panel indicator when threshold is reached

13

Hands-on Introduction to Data Acquisition with LabVIEW

4

PC-Based Data Acquisition with LabVIEW

14

PC-Based Data Acquisition (DAQ)

15

Measuring Analogue Input Signals Important Factors to Consider: • Architecture  

Multiplexed Simultaneous sampling

• Sampling rate • Resolution

To PC

… Analogue Input

• Signal conditioning

16

Hands-on Introduction to Data Acquisition with LabVIEW

5

Analogue Input – Architectures Multiplexed Channel 0

Channel 0

MUX

Channel 1

AMP

ADC

Channel 1

Interchannel delay

Simultaneous sampling Channel 0 AMP

ADC

Channel 1 AMP

ADC

Channel 0 Channel 1 No interchannel delay

17

Analogue Input – Sampling Rates

• Undersampling may result in the misrepresentation of the measured signal (aliasing). • After a signal is aliased, it is impossible to reconstruct the original signal. • For accurate frequency representation: 

Sample at least 2x the highest frequency signal being measured.

• For accurate shape representation 

Sample 5–10x the highest frequency signal being measured.

18

Analogue Input – Resolution • Number of bits analogue-to-digital converter (ADC) uses to represent a signal • Higher resolution – detect smaller voltage changes 16-Bit versus 3-Bit Resolution (5 kHz Sine Wave)

10.00

111

8.75 7.50

110

6.25

101

Amplitude 5.00 (Volts)

100

3-bit

011

3.75

010

2.50

001

1.25 0

16-bit

|

0

000 |

50

|

100

Time (ms)

|

|

150

200

19

Hands-on Introduction to Data Acquisition with LabVIEW

6

Analogue Input – Signal Conditioning High voltage signals and most sensors require signal conditioning to properly read the signal Sensors/Signals

Signal Conditioning

Thermocouples

Amplification, Linearisation, and Cold-Junction Compensation, Filtering

RTDs

Current Excitation, Linearisation, Filtering

Strain Gauges

Voltage Excitation, Bridge Configuration, Linearisation, Filtering

Common Mode or High Voltages

Isolation

DAQ Device

20

NI CompactDAQ Hi-Speed USB 2.0

Built-in signal conditioning

Synchronized I/O

Mix and match over 30 hot-swappable modules

21

C Series Modules  Accelerometer  Strain Gauge  Load Cells  Digital I/O

 Thermocouples  4 to 20mA  High Voltage (60V)  RTD

22

Hands-on Introduction to Data Acquisition with LabVIEW

7

Data Acquisition with LabVIEW NI-DAQmx driver software provides connectivity between LabVIEW and your hardware Configuration Based

Programmatic Interface

NI-DAQmx driver configures • Buffering • Signal routing • Sample rates • etc… • Clocking

• Triggering

23

Exercises 2a –2c: Introduction to Data Acquisition with LabVIEW What you will learn: • Taking measurements from scratch using NI CompactDAQ and NI LabVIEW • Create an application that 

Measures from a thermocouple



Logs data to a file

24

DAQ Solution for Your Application

Rugged and Modular Test

25

Hands-on Introduction to Data Acquisition with LabVIEW

8

Analysis in LabVIEW

26

Choose Your Analysis Approach LabVIEW has over 600 built-in analysis functions Express VIs

Standard VIs

Configuration Oriented

LabVIEW MathScript

Textual Math

27

LabVIEW Analysis Built-in functions available for signal processing, analysis and math • Signal synthesis • Curve fitting and interpolation • FFT-based frequency analysis • Mathematics • Probability and statistics • Time- and frequency-domain analysis • Digital signal processing • Waveform alignment and resampling • Much more… 28

Hands-on Introduction to Data Acquisition with LabVIEW

9

LabVIEW Toolkits Productivity enhancing functionality found in several toolkits, including… • • • • • •

Sound & Vibration RF and Communications Digital Filter Design Database Connectivity Reporting Interface to MS Office And many more…

29

Presenting Data in LabVIEW

30

Presenting Data Types of controls and indicators available: • Graphs and strip charts • Buttons and checkboxes • Knobs and sliders • Text and combo boxes • Tree controls • Tables • ActiveX objects • etc...

31

Hands-on Introduction to Data Acquisition with LabVIEW

10

Options for Professional UIs Displaying data, visualising processes and controlling machines

LabVIEW is optimised for creating technical user interfaces

32

LabVIEW File I/O Functions for saving your data to files and databases • ASCII

• Excel

• Binary

• Databases

NI TDM file format provides an easy way to make test data searchable

ni.com/tdm 33

LabVIEW Report Generation Functions for creating reports and documenting test results • HTML

• MS Office

• XML

• DIAdem

The Report Generation toolkit provides connectivity to MS Office

ni.com/diadem

NI DIAdem provides a WYSIWYG report editor 34

Hands-on Introduction to Data Acquisition with LabVIEW

11

Controlling Program Execution Start

Is Limit Met?

No

Yes

Turn On Output

Reset Output

• • • • • • •

Looping (For and While) Case structure Sequence structure State machines Event structure State diagram editor Timed loop

35

LabVIEW Looping Basics While Loop

For Loop

Run until stop condition met

Run N times

36

LabVIEW Case Structure Primary decision making block

37

Hands-on Introduction to Data Acquisition with LabVIEW

12

Exercise 3: Controlling Program Execution What you will learn: – How to incorporate logic into your LabVIEW application

Create an application that: – Charts a sine or triangle wave depending on toggle switch position – Turns on/off digital outputs based on user selections 38

Analogue Output – Considerations • Accuracy: digital-to-analog converter (DAC) resolution • Update Rate: settling time and waveform frequency • Range: fixed or adjustable output voltage/current Channel 0

DAC

Channel 1

DAC

Channel 0 Channel 1

• 16-bit • 100 kS/sec • ±10 VDC, 0–20 mA 39

Exercise 4: Multiple Operations with Analogue I/O What You Will Learn • Creating parallel operation in LabVIEW • Create an application that 

Outputs an analogue signal



Uses analogue input channel to acquire and display on front panel

Time: 20 minutes 40

Hands-on Introduction to Data Acquisition with LabVIEW

13

Analogue Output Functions – PID Control Analogue IO can be used in combination for control applications Read 1 Sensor

Calculate 2 PID value

Output to 3 Actuator

41

Additional Measurement Platforms

42

NI LabVIEW™ Everywhere Platforms: • • • •

Microprocessors

Desktop Mobile Industrial Embedded

FPGA Handheld Wireless Networked I/O PC Boards

PXI Tektronix open Windows oscilloscopes PC

43

Hands-on Introduction to Data Acquisition with LabVIEW

14

Modular Instrumentation

Modular Instruments

Data Acquisition   

Sensors, voltage and current I/O Measurements: DC to 10 MHz Resolution: ~18 to 24 bits

– DMMs, Switches, Oscilloscopes, High-speed digital, Power supplies, RF – Measurements: DC to 6 GHz – Resolution: Up to 26 bits 44

Interfacing with Benchtop Instruments • Benchtop instruments involve: – Fixed functionality – Vendor defined interface Processor

Display

RAM

Power Supply

ROM

Hard Disk

LabVIEW uses drivers for PC connectivity 45

Instrument Control with LabVIEW Over 5,000 Instrument drivers online, from over 250 vendors GPIB - USB - Ethernet RS 232 - RS 485 - LXI

ni.com/idnet

46

Hands-on Introduction to Data Acquisition with LabVIEW

15

Using NI CompactDAQ to Crash Test Safety Helmets Application: Designing a highly accurate and portable high-level impact test application for the certification of safety helmets. NI Products Used: NI CompactDAQ Solution: CompactDAQ is used to control the height from which the helmet under test is dropped, as well as acquiring data related to what a person's head would be subjected to upon impact. The system was chosen as it had sufficient throughput to ensure that each helmet test is thoroughly and accurately documented.

“A system upgrade such as the one we required is a major budget consideration, and for this reason we were very deliberate in our search for a new hardware package” 47

Microsoft Uses NI LabVIEW and PXI Modular Instruments to Develop Production Test System for Xbox 360 Controllers Application: Creating an updated versatile test system to test and validate new Xbox 360 controllers. NI Products Used: LabVIEW, Modular Instruments and PXI/CompactPCI Reasons for Choosing NI Products: “Using the LabVIEW graphical development environment, we created more than 100 tests, implemented Ethernet communication, and incorporated a data storage interface to our Microsoft SQL Server database…we implemented a test strategy that resulted in a 50 percent increase in our test throughput per test station.” Microsoft Uses NI LabVIEW and PXI Modular Instruments to Develop Production Test System for Xbox 360 Controllers

NI Customer Solutions

48

Your Next Steps • Visit ni.com/labview    

Try LabVIEW Online for FREE Read technical white papers View webcasts on-demand Find other seminars in your area

• Schedule a visit with your local field engineer to discuss your application

49

Hands-on Introduction to Data Acquisition with LabVIEW

16

Useful Resources Measurement Fundamentals www.ni.com/measurementfundamentals

50

LabVIEW Skill Development Plan New User

Experienced User

Advanced User

Courses

LabVIEW Advanced I LabVIEW Intermediate I

Core Courses Begin Here

LabVIEW Basics I

LabVIEW Basics II

Certifications Certified LabVIEW Associate Developer Exam

LabVIEW Intermediate II Certified LabVIEW Architect Exam

Certified LabVIEW Developer Exam

• Save development time and cost • Differentiate skills with professional credentials • Multiple training formats – Classroom, Onsite, Online, Self-Paced

ni.com/training 51

Questions or Comments?

ni.com/labview

52

Hands-on Introduction to Data Acquisition with LabVIEW

17

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 VI will test the input values against a user-specified limit and light an LED if the input value exceeds that limit. Below are pictures identifying each of the palettes found in LabVIEW to assist you as you complete these exercises. Note: LabVIEW has a built-in Automatic Tool Selection feature that changes the behavior of the cursor depending on what type of object you are currently pointing to.

Functions Palette Controls Palette

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

Hands-on Introduction to Data Acquisition with LabVIEW

18

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

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.

Hands-on Introduction to Data Acquisition with LabVIEW

19

4. Select VI»From Template»Tutorial (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. 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. 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 on the keyboard. 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.

Hands-on Introduction to Data Acquisition with LabVIEW

20

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 . 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 gray arrow, this new icon indicates that the VI is currently not executable. 7. Now we can add some functionality to this basic VI. We will modify the VI to flash an alarm whenever the signal value is above a certain level. 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.

Hands-on Introduction to Data Acquisition with LabVIEW

21

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

9. Click the Express menu item on the Controls palette to return to the Express Controls palette.

10. Click the LEDs subpalette, and place a Round LED on the front panel.

Hands-on Introduction to Data Acquisition with LabVIEW

22

11. 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 tab and click OK to apply the changes. Label: Limit Slider 1: Check Show digital display(s)

Hands-on Introduction to Data Acquisition with LabVIEW

23

12. Right-click the Round LED labeled Boolean, and select Properties. Examine the different properties that can be modified. On the Appearance tab, change the label from Boolean to Alarm. Click OK to apply your change. Move the objects on the front panel so it resembles the following.

13. Switch to the block diagram by pressing . Double-click the Simulate Signal Express VI to bring up its properties window. Examine the different properties you can modify. Change the Amplitude of the signal to 10. Click OK to apply this change and to close the properties window.

Hands-on Introduction to Data Acquisition with LabVIEW

24

14. Bring up the Functions palette by right-clicking the block diagram. Select Express & Signal Analysis and place the Amp & Level Express VI on the diagram.

15. When you place the Comparison Express VI on the block diagram, a dialog box appears. Select RMS as shown below.

16. As shown below, wire the output of the Simulate Signal VI to Signals input on the Amplitude and Level Measurements VI. Then right-click on RMS output and select Create»Numeric Indicator from the context menu.

Hands-on Introduction to Data Acquisition with LabVIEW

25

17. Bring up the functions palette by right-clicking the block diagram. Select Arithmetic & Comparison»Comparison and place the Comparison Express VI on the diagram

Hands-on Introduction to Data Acquisition with LabVIEW

26

When you place the Comparison Express VI on the block diagram, a dialog box appears that lets you configure what type of comparison you will be doing. Make the following selections, then click OK to apply these changes and to close the dialog box. Compare Condition: Greater Comparison Inputs: Compare to second input

18. You can connect Controls, Functions, and Indicators on the block diagram by pointing to an object and clicking it when the cursor changes to a spool of wire. You can then move the cursor to the object you want to connect it to and click again. Connect the Limit control to the Alarm indicator.

Note: The Run button in the upper left corner of both the front panel and the block diagram has changed from a solid white arrow, to a broken gray arrow. This new icon indicates that

Hands-on Introduction to Data Acquisition with LabVIEW

27

the VI is currently not executable. If you click the Run 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. 19. Click the Run button now. The resulting dialog box shows that, in this case, the error results from connecting terminals of two different types. Since the Limit control is a Numeric type and the Alarm indicator is a Boolean type, we cannot wire these two terminals together. Highlight the error by clicking it, and then click Show Error. LabVIEW will highlight the location of the error. 20. Notice that the wire between Limit and Alarm is dashed and a red  is displayed on it.

To delete this broken wire, press . This keyboard shortcut removes all broken wires from the block diagram. 21. 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 the Simulate Signals block and the Waveform Graph to the Operand 1 input of the Comparison block. c. Wire the Result output of the Comparison block to the Alarm indicator. Your block diagram should now resemble the following:

Hands-on Introduction to Data Acquisition with LabVIEW

28

22. Switch to the front panel by pressing . 23. Save the VI in the Desktop\CustomerWork 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. 24. Run the VI. While running the VI, you can change the Limit value. Also notice that when a data point received from the Simulate Signal VI is greater than the Limit value, the Alarm indicator lights up. While the VI is still running, switch to the block diagram by pressing . Enable highlight execution by clicking the light bulb on the tool bar. This will allow you to see the flow of data through your program.

25. When you are finished, stop the VI by clicking the STOP button on the front panel.

Hands-on Introduction to Data Acquisition with LabVIEW

29

Optional Exercise 1: The LabVIEW Help System The LabVIEW help system is a great place to learn about LabVIEW and to go when you have questions. This exercise will introduce you to the rich source of information that is available for you to take advantage of. 1. Go back to the VI you just created, and press on the keyboard to start the help system

2. Expand Fundamentals»LabVIEW Environment and explore the information available here, click around and get a feel for how it is organized.

3. Take a few minutes to explore other topics in the help system. 4. Click on the Search tab try searching on analysis functions for features you might need in your work applications.

Hands-on Introduction to Data Acquisition with LabVIEW

30

Optional Exercise 2: LabVIEW Example Finder As you learned in Optional Exercise 1, LabVIEW has a comprehensive help system. LabVIEW also includes an extensive set of examples that in many cases are the building blocks for your applications. This exercise will introduce you to what examples are available. 1. Go back to the VI you created, and from the Help menu select Find Examples.

2. Expand New Examples for LabVIEW 8.5»Express and double-click on Select Signals.vi. 3. Run the VI and explore the block diagram.

4. Take a few minutes to look around at the other example programs available, search on terms that you are familiar with, i.e., “analysis”, and try out as many as there is time for.

End of Exercise 1

Hands-on Introduction to Data Acquisition with LabVIEW

31

Exercise 2a: Data Acquisition with NI LabVIEW Exercise Overview Objective Learn about data acquisition in LabVIEW

Goals When you have completed this exercise, you will:  Know how to configure a data acquisition device  Know how to use the DAQ Assistant and take measurements with NI LabVIEW

Exercise Instructions Set up 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. NI-DAQmx driver installed on the PC automatically detects the chassis and brings up the following window.

Hands-on Introduction to Data Acquisition with LabVIEW

32

4. Click on Configure and Test This Device to open Measurement & Automation Explorer (MAX). Note: NI Measurement & Automation Explorer is a configuration utility for all National Instruments hardware.

Configure Hardware 5. 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 NIDAQmx 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 is configured properly and ready to be used in your LabVIEW application.

LabVIEW 9. Open NI LabVIEW 8.5 and press to open a blank VI. 10. Press 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 Assist Express VI. Click again on the white space of the LabVIEW block diagram to place the DAQ Assistant VI.

Hands-on Introduction to Data Acquisition with LabVIEW

33

13. The Create New Express Task… window appears:

14. To configure a temperature measurement application with a thermocouple, click on 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. 15. Change the CJC source to Built In and Acquisition Mode to Continuous. Click the Run

button. You will see the temperature readings from the thermocouple in test panel window.

Hands-on Introduction to Data Acquisition with LabVIEW

34

16. Click OK to close the Express block configuration window to return to the LabVIEW block diagram. 17. Notice that LabVIEW automatically creates the code for you for this measurement task. Click Yes to automatically create a While Loop.

18. Right-click the data terminal output of the DAQ Assistant Express VI (the blue output arrow on the right side) and select Create»Graph Indicator.

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.

Hands-on Introduction to Data Acquisition with LabVIEW

35

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 . 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. 22. Also, right-click on the stop (F) button and select Replace. The Controls palette will appear. Select Boolean»Stop Button.

Hands-on Introduction to Data Acquisition with LabVIEW

36

23. Modify the thermometer indicator by right-clicking it and selecting Properties. On the Appearance Tab, change the Label to Temperature.

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

Click OK when you are finished.

Hands-on Introduction to Data Acquisition with LabVIEW

37

24. Switch to the block diagram. Expand the While Loop. Your block diagram should now

resemble the following illustration.

25. To perform analysis on your data, select the Express»Signal Analysis»Statistics Express VI and place it on your block diagram.

26. A properties window will appear. Make the following selections and click OK. Statistical Calculations: Arithmetic Mean

Hands-on Introduction to Data Acquisition with LabVIEW

38

Extreme Values: Maximum, Minimum

27. Connect the data output of the DAQ Assistant VI to the Signals input of the Statistics VI.

Hands-on Introduction to Data Acquisition with LabVIEW

39

28. Right-click the Arithmetic Mean output of the Statistics VI and select Create»Numeric Indicator. This will create a numeric indicator on the front panel that will display the mean. Repeat this step for both the Maximum and Minimum outputs of the Statistics VI. Your block diagram should resemble the following.

29. Switch to the front panel and rearrange your controls and indicators to resemble the following.

30. Save the VI in the Desktop\CustomerWork folder by using the File menu and name it Exercise2.vi.

Hands-on Introduction to Data Acquisition with LabVIEW

40

31. Run the VI. Hold the thermocouple between your fingers to raise the temperature. Notice the change in temperature on the thermometer. If you are not seeing enough of a temperature fluctuation, stop the VI and decrease the range on your thermometer indicator. 32. Click the STOP button on the front panel when you are finished. 33. Close the VI.

End of Exercise 2a

Hands-on Introduction to Data Acquisition with LabVIEW

41

Exercise 2b: File I/O in LabVIEW Exercise Overview Objective How to log data to a file using LabVIEW.

Goals When you have completed this exercise, you will:  Know how to use Write to Measurement File express VI and how to log data to a file using LabVIEW.

Exercise Instructions 1. Open the VI from exercise 2a. 2. Right-click on the block diagram and select Express» Output» Write to Measurement File and place it inside the While Loop on the block diagram.

Hands-on Introduction to Data Acquisition with LabVIEW

42

3. A configuration window will appear. Enter the following parameters and click OK.

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 .

Hands-on Introduction to Data Acquisition with LabVIEW

43

6. Save the VI in the Desktop\CustomerWork folder by using the File menu and name it Exercise2b.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 and the LabVIEW VI.

End of Exercise 2b

Hands-on Introduction to Data Acquisition with LabVIEW

44

Exercise 2c (Optional): Automatic Code Generation in LabVIEW Exercise Overview Objective Create DAQmx code from the DAQ Assistant.

Goals When you have completed this exercise, you will:  Know how to generate code automatically from the DAQ Assistant.  Have experience using some of the NI-DAQmx VIs.

Exercise Instructions 1. Open the VI from Exercise 2a. 2. Delete all the functions and terminals from the block diagram except the DAQ Assistant. Delete all the wires as well. 3. Right-click on the DAQ Assistant and select Generate NI-DAQmx Code.

Hands-on Introduction to Data Acquisition with LabVIEW

45

4. NI-DAQmx will now generate LabVIEW code using the NI-DAQmx API. Your block diagram should now resemble this:

5. Double-click on the configuration VI (shown below) that NI-DAQmx generated for you on your block diagram

6. The block diagram of the configuration VI should appear as shown below. This is an example of how you can use the DAQmx VIs if you need to create customized DAQ code that includes features beyond those offered by the DAQ Assistant.

Hands-on Introduction to Data Acquisition with LabVIEW

46

In this block diagram, you will see 3 SubVIs: DAQmx Create Task.vi

DAQmx Create Channel.vi

DAQmx Timing.vi

To learn about each VI, hover your mouse over each one and press . This will bring up the Context Help which explains the parameters and functionalities of each VI. 7. Close the VI and do not save any changes.

End of Exercise 2c

Hands-on Introduction to Data Acquisition with LabVIEW

47

Exercise 3: Controlling Program Execution If you are up for challenge, try to build the following LabVIEW application without using the instructions; if you feel you need more guidance skip down to the section step-by-step for a complete set of instructions.

Challenge Application Using a While Loop, case structure, toggle switch and the Simulate Signal VI, create a simple application that charts a sine or triangle wave depending on toggle switch position. When you are done, save your VI as Exercise3-Decisions.vi. You will use it in the next exercise. If you are really up for a challenge 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.

Step By Step Instructions In this exercise, you will create a LabVIEW VI that will output a triangle or sine wave to a front panel graph depending on the state of a toggle switch. You will use a case structure to handle the logic of which signal is output and a While Loop to keep the application running until a Stop button is pressed. 1. Let’s start by placing a While Loop on the block diagram. Draw it large enough to accommodate the other code you will be placing inside it. You can locate the While Loop on the Express» Execution Control palette as shown below.

Hands-on Introduction to Data Acquisition with LabVIEW

48

2. Next select the Case Structure from the Execution Control palette and place it inside the While Loop as shown below.

3. Next we will add the simulate signal VIs two the case statement. Remember one will output a triangle wave, the other a sine wave. From the Express»Input palette, select Simulate Sig as shown below, and place it inside the case statement.

Hands-on Introduction to Data Acquisition with LabVIEW

49

4. Configure the first Simulate Sig to produce a triangle wave by selecting the Signal type as shown below.

5. Your block diagram should now look like the following.

Hands-on Introduction to Data Acquisition with LabVIEW

50

6. Next, switch the case statement from True to False, as shown below.

7. Repeat steps 3 and 4, except this time leave the default settings for the Simulate Sig VI so it will generate a sine wave. 8. Switch to your front panel and place a Waveform Graph as shown below.

Hands-on Introduction to Data Acquisition with LabVIEW

51

9. Also add a vertical toggle switch from the Boolean palette to the front panel as shown below.

10. Your front panel should look like the following.

Hands-on Introduction to Data Acquisition with LabVIEW

52

11. Switch back to the block diagram and wire the toggle switch to the input of the case statement as shown below.

12. Next, wire the outputs from both of the Simulate Signals to the waveform graph. Note that you will have to wire through the wall of case statement. Don’t forget wire both the cases, True and False.

13. You are ready to test your VI by switching the toggle switch back and forth. You should see the graph switch between a sine and triangle wave.

Hands-on Introduction to Data Acquisition with LabVIEW

53

Adding Digital Output to Your Project Often when you are creating control applications, controlling digital lines is necessary to interface with pumps, valves, lamps, etc. In the next part of this exercise we will extend our application to include control of the digital output lines. 8. Right-click on your front panel and select an empty array container as shown below.

9. Place the array container at the bottom of the VI, as shown below.

Hands-on Introduction to Data Acquisition with LabVIEW

54

14. You can create an array of controls by simply inserting them into the array. Right-click on the front panel and select a push button from the Boolean palette and drop it into the empty array.

15. It should look like the following.

16. Next we will increase the size of the array of Booleans so it contains eight elements. To do this, click on the right side of the array container and drag it to the right until eight push-buttons are visible.

Hands-on Introduction to Data Acquisition with LabVIEW

55

17. VERY IMPORTANT STEP- Click on the eighth switch to initialize the array size:

18. Next configure the hardware to recognize these switches and control one digital output per switch. Start by switching to the block diagram using . 19. Next select the DAQ Assistant from the Express»Output palette

20. In the DAQ Assistant select Digital I/O»Line Output as shown below. Click Next.

Hands-on Introduction to Data Acquisition with LabVIEW

56

21. Select all the digital output lines by clicking on the first then holding the shift key down before clicking on the last out, then click Finish.

22. Click OK at the following dialog.

Hands-on Introduction to Data Acquisition with LabVIEW

57

23. Finally wire the output of the array to the data input on the DAQ Assistant, as shown below.

24. Switch to the front panel and Run the VI. Use the push buttons to activate the digital outputs on the NI 9472 module and watch the LEDs change as you select different push buttons.

Hands-on Introduction to Data Acquisition with LabVIEW

58

Optional Steps 1. 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. 2. Do this by inserting an Or gate from the Boolean palette before the STOP button, as shown below.

Hands-on Introduction to Data Acquisition with LabVIEW

59

3. Next select the greater than function from the Comparisons palette.

4. Wire as follows.

Hands-on Introduction to Data Acquisition with LabVIEW

60

5. Right-click on the open terminal of the greater than block and select Create»Contant.

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

Hands-on Introduction to Data Acquisition with LabVIEW

61

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 3 Hands-on Introduction to Data Acquisition with LabVIEW

62

Exercise 4: Multiple Operations with Analogue I/O Exercise Overview Objective In this exercise, you will use the DAQ Assistant to build a LabVIEW VI that generates and outputs an analogue waveform. You will then add a second loop that measures the waveform using an analogue input channel.

Goals When you have completed this exercise, you will:  Know how to generate signals in LabVIEW with NI CompactDAQ  Run loops in parallel for multiple analogue operations

Exercise Instructions 1. If you closed LabVIEW after the last exercise, launch it. Open a new VI. 2. Press 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.

Hands-on Introduction to Data Acquisition with LabVIEW

63

6. Bring up the Functions»Express palette again, and browse to the DAQmx Assist VI on the Output subpalette of the Functions palette. Place the VI on the block diagram. 7. In the Create New window, select Analogue Output as the Measurement Type and then select Voltage.

Hands-on Introduction to Data Acquisition with LabVIEW

64

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

9. In the DAQ Assistant configuration window, select Generate Continuously from the Task Timing tab in the lower part of the window. Uncheck Use timing from waveform data, and set the Rate (Hz) to 10,000. Click the OK button.

Hands-on Introduction to Data Acquisition with LabVIEW

65

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.

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.

Hands-on Introduction to Data Acquisition with LabVIEW

66

13. To create a slide control for varying the frequency of the sine wave, press to switch to the LabVIEW front panel. Right-click on the empty gray space to pull up the Controls palette. Select Vertical Pointer Slide from the Numeric Controls subpalette of the Controls palette. Place the vertical pointer slide on the front panel.

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 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).

Hands-on Introduction to Data Acquisition with LabVIEW

67

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 . Your block diagram should resemble the following figure.

16. This VI will now use the frequency knob on the LabVIEW front panel to generate a sine wave at the specified frequency. This sine wave is then generated on analogue output channel 0 of the NI 9263 C Series module by the DAQ Assistant Express VI. 17. Save the VI as Analogue output.vi in the Desktop\CustomerWork folder. 18. Increase the size of the block diagram window to make space for another While Loop to go below the existing Analogue Output code.

Hands-on Introduction to Data Acquisition with LabVIEW

68

19. Place a DAQ Assistant Express VI from the Input subpalette of the Functions»Express palette. Select Analogue 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.

Hands-on Introduction to Data Acquisition with LabVIEW

69

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

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.

Hands-on Introduction to Data Acquisition with LabVIEW

70

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

Hands-on Introduction to Data Acquisition with LabVIEW

71

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

24. Press 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)

Hands-on Introduction to Data Acquisition with LabVIEW

72

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

27. Save the VI as Analogue Input and Output.vi in the Desktop\CustomerWork folder. 28. Run the VI 29. The analogue output loop is generating a sine wave on analogue output channel 0, which is wired directly to channel 0 of the analogue 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.

Hands-on Introduction to Data Acquisition with LabVIEW

73

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

Hands-on Introduction to Data Acquisition with LabVIEW

74

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF