18
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01 Datalogging in LabVIEW HANS-PETTER HALVORSEN, 2011.01.04

Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

Embed Size (px)

Citation preview

Page 1: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

Telemark University College

Department of Electrical Engineering, Information Technology and Cybernetics

Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01

Datalogging in LabVIEW

HANS-PETTER HALVORSEN, 2011.01.04

Page 2: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

ii

PREFACE

In this lab you will learn basic Data Acquisition (DAQ) and how to use a DAQ unit in LabVIEW. We will use the

USB-6008 DAQ device from National Instruments. NI USB-6008 is a simple and low-cost USV based

multifunction I/O device from National Instruments. The device is well suited for training and education

purpose.

The purpose of data acquisition is to measure an electrical or physical phenomenon such as voltage, current,

temperature, pressure, or sound. PC-based data acquisition uses a combination of hardware, software, and a

computer to take measurements.

The principle of Data Acquisition:

USB-6008 DAQ device from National Instruments:

Page 3: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

iii

TABLE OF CONTENTS

Preface ..................................................................................................................................................................... ii

Table of Contents .................................................................................................................................................... iii

1 Introduction to Data Acquisition ....................................................................................................................4

2 Datalogging .....................................................................................................................................................8

3 Additional Tasks............................................................................................................................................15

Page 4: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

4

1 INTRODUCTION TO DATA ACQUISITION

In this task we will learn basic Data Acquisition in LabVIEW. We will use the USB-6008 DAQ device.

Background information for this task is described in detailed in the Tutorial “Data Acquisition in

LabVIEW”. The Tutorial consists of pdf documents, videos, example code, additional resources and links.

http://home.hit.no/~hansha/?tutorial=daq

The purpose of data acquisition is to measure an electrical or physical phenomenon such as voltage, current,

temperature, pressure, or sound. PC-based data acquisition uses a combination of modular hardware,

application software, and a computer to take measurements. While each data acquisition system is defined by

its application requirements, every system shares a common goal of acquiring, analyzing, and presenting

information. Data acquisition systems incorporate signals, sensors, actuators, signal conditioning, data

acquisition devices, and application software.

So summing up, Data Acquisition is the process of:

Acquiring signals from real-world phenomena

Digitizing the signals

Analyzing, presenting and saving the data

Page 5: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

5 Introduction to Data Acquisition

Lab Work: Datalogging in LabVIEW

The DAQ system has the following parts involved, see Figure:

The parts are:

Physical input/output signals

DAQ device/hardware

Driver software

Your software application (Application software)

The NI-DAQmx Driver software is the layer of software for easily communicating with the hardware. It forms

the middle layer between the application software and the hardware. Driver software also prevents a

programmer from having to do register-level programming or complicated commands in order to access the

hardware functions.

The DAQmx palette in LabVIEW:

The DAQ Assistant, included with NI-DAQmx, is a graphical, interactive guide for configuring, testing, and

acquiring measurement data. With a single click, you can even generate code based on your configuration,

making it easier and faster to develop complex operations. Because DAQ Assistant is completely menu-driven,

Page 6: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

6 Introduction to Data Acquisition

Lab Work: Datalogging in LabVIEW

you will make fewer programming errors and drastically decrease the time from setting up your DAQ system to

taking your first measurement.

NI USB-6008 is a simple and low-cost multifunction I/O device from National Instruments.

The device has the following specifications:

8 analog inputs (12-bit, 10 kS/s)

2 analog outputs (12-bit, 150 S/s)

12 digital I/O

USB connection, No extra power-supply neeeded

Compatible with LabVIEW, LabWindows/CVI, and Measurement Studio for Visual Studio .NET

NI-DAQmx driver software

The NI USB-6008 is well suited for education purposes due to its small size and easy USB connection.

Measurement & Automation Explorer (MAX) provides access to your National Instruments devices and

systems.

With MAX, you can:

Configure your National Instruments hardware and software

Create and edit channels, tasks, interfaces, scales, and virtual instruments

Execute system diagnostics

View devices and instruments connected to your system

Update your National Instruments software

In addition to the standard tools, MAX can expose item-specific tools you can use to configure, diagnose, or

test your system, depending on which NI products you install. As you navigate through MAX, the contents of

the application menu and toolbar change to reflect these new tools.

Page 7: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

7 Introduction to Data Acquisition

Lab Work: Datalogging in LabVIEW

Page 8: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

8

2 DATALOGGING

In this task we will connect our DAQ device to a “real” process (small-scale model).

Below we see the Lab Equipment available for this assignment:

Level Tank Air Heater

In this Lab we can select one of these models. Which one you use is not relevant for the purpose of this lab

work.

Documents of how to use the Level Tank/Air Heater and the USB-6008 DAQ device is available from

http://home.hit.no/~hansha.

Level Tank: http://home.hit.no/~hansha/?equipment=leveltank

Air Heater: http://home.hit.no/~hansha/?equipment=airheater

USB-6008: http://home.hit.no/~hansha/?equipment=usb6008

Task 1: Test DAQ Device on Real Process

Select one of the processes above and connect you DAQ device to the system.

→ Log data (Temperature for the Air Heater system or Level for the Water Tank) for different input signals (u).

→ Show the results in a Chart.

You may want to use the “Waveform Chart” located in the Graph palette:

Page 9: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

9 Datalogging

Lab Work: Datalogging in LabVIEW

Here is a LabVIEW example:

Scaling:

Make sure to scale the output signal from the system (Voltage signal) to Temperature (Air Heater) or Level

(Water Tank).

Air Heater output: 1-5V → 20-50 o

C.

Water Tank output: 0-5V → 0-20cm.

The following linear relationship applies:

Page 10: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

10 Datalogging

Lab Work: Datalogging in LabVIEW

You have to find a (slope) and b (intercept). The following formulas may be used:

This gives:

where

→ It is good practice to implement the scaling using a SubVI.

[End of Task]

Task 2: Manual Control

→ Try to act like a controller: Let’s say you want the setpoint to be 15cm (Level Tank)/35 degrees C (Air

Heater) and then try to manually adjust the control signal (u) so the Temperature stays on the setpoint.

You need to extend the program from a previous task so that the control signal u is sent to the DAQ unit.

Use the “DAQmx Write.vi”:

Page 11: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

11 Datalogging

Lab Work: Datalogging in LabVIEW

[End of Task]

Task 3: Write to Measurement File

Extend your program so the logged data can be saved to a Measurement File.

You can use the Write to Measurement File function on the File I/O palette in LabVIEW for writing data to text

files (use the LVM data file format, not the TDMS file format which give binary files).

Recommended settings for the “Write To Measurement File”:

Page 12: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

12 Datalogging

Lab Work: Datalogging in LabVIEW

Example of LabVIEW Program:

Open the *.lvm file in, e.g., Notepad in order to see the results.

[End of Task]

Page 13: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

13 Datalogging

Lab Work: Datalogging in LabVIEW

Task 4: Read from Measurement File:

Create another program that open the measurement file and shows the data in an array and a Graph.

Use the “Read From Measurement File” in LabVIEW.

Recommended settings for the “Read From Measurement File”:

Example of LabVIEW program:

Page 14: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

14 Datalogging

Lab Work: Datalogging in LabVIEW

You should also open the file in Excel and plot the data in Excel.

[End of Task]

Task 5: Import Data to Excel

In this task we will open the measurement file created in a previous task in MS Excel.

→ Open the measurement file in Excel

→ Calculate the average (mean) of the logged data (use the built-in mean function in Excel)

→ Create a plot of the logged data

[End of Task]

Page 15: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

15

3 ADDITIONAL TASKS

Task 6: Datalogging and Virtual Instruments

Create a “Virtual Instrument” with the following components:

1. Toolbar

2. Owned Label

3. Numeric Control

4. Free Label

5. Numeric Control Terminal

6. Knob Terminal

7. Numeric Constant

8. Multiply Function

9. Icon

10. Knob Control

11. Plot Legend

12. XY Graph

13. Wire Data Path

14. XY Graph Terminal

15. Bundle Function

16. SubVI

17. For Loop Structure

Below we see the front panel and the block diagram for the virtual instrument.

Page 16: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

16 Additional Tasks

Lab Work: Datalogging in LabVIEW

→ The SubVI (number 16) shall read the temperature from the Air Heater using the USB-6008 DAQ (Data

Acquisition) device.

Page 17: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

17 Additional Tasks

Lab Work: Datalogging in LabVIEW

Page 18: Lab Work: Datalogging in LabVIEWhome.hit.no/~hansha/training/daq/documents/Datalogging in LabVIEW.… · The device is well suited for training and education ... Lab Work: Datalogging

Telemark University College

Faculty of Technology

Kjølnes Ring 56

N-3914 Porsgrunn, Norway

www.hit.no

Hans-Petter Halvorsen, M.Sc.

Telemark University College

Department of Electrical Engineering, Information Technology and Cybernetics

Phone: +47 3557 5158

E-mail: [email protected]

Blog: http://home.hit.no/~hansha/

Room: B-237a