data acquisition with labview - temperature

70
Data Acquisition with LabVIEW: Temperature K. Craig 1 Data Acquisition with LabVIEW Physical & Mathematical Modeling Engineering Measurement Engineering Analysis & Computing Engineering Discovery P h y s i c s M a th e m a t ic s Social Science Hands-On Minds-On Technical Communications Teamwork Professionalism Engineering System Investigation Process Engineering System Design Process Mechanical Engineering Electrical & Computer Engineering Civil & Environmental Engineering Biomedical Engineering Selection of Engineering Materials Processes to Make Products

Upload: mashraf397037

Post on 30-Oct-2014

111 views

Category:

Documents


7 download

TRANSCRIPT

Data Acquisition with LabVIEW: Temperature K. Craig 1

Data Acquisition with LabVIEW

Physical &

Mathematical

Modeling

Engineering

Measurement

Engineering

Analysis &

Computing

Engineering

Discovery

Physics

Mathem

atics

So

cia

l S

cie

nce

Hands-On Minds-On

Technical

Communications

Teamwork Professionalism

Engineering System Investigation Process

Engineering System Design Process

Mechanical

Engineering

Electrical &

Computer

Engineering

Civil &

Environmental

Engineering

Biomedical

Engineering

Se

lectio

n o

f E

ng

ine

erin

g M

ate

ria

ls Pro

ce

sse

s to

Ma

ke

Pro

du

cts

Data Acquisition with LabVIEW: Temperature K. Craig 2

Temperature Measurement In LabVIEW

• The steps we will follow are:

– Configure the DAQ device in the Measurement & Automation

Explorer (MAX).

– Open LabVIEW.

– Create the DAQ Assistant on the block diagram window.

– Configure the measurement.

– Create the conversion equation from volts to ºC on the block

diagram window.

– Create the chart indicator on the front panel window.

– Wire the DAQ Assistant, conversion equation, and chart

indicator.

– Save and run the program.

Data Acquisition with LabVIEW: Temperature K. Craig 3

Temperature Measurement Program

out

out

V 0.5 (0.01)T( C)

V 0.5T( C)

0.01

volts ºC

Data Acquisition with LabVIEW: Temperature K. Craig 4

Temperature Sensor

connected

not

connected

USB DAQ

ground

5 V

signal

Data Acquisition with LabVIEW: Temperature K. Craig 5

• Temperature Transducer

– Analog Devices TMP36 Low Voltage, Precision, Centigrade

Temperature Sensor

– Applications: HVAC, automotive, electronics

– Features:

• Temperature span: -40ºC to +125ºC

• Accuracy ± 2ºC

• Linearity ± 0.5ºC

• Temperature coefficient of 10 mV/ºC with 5V supply

• Output voltage is 750 mV at 25ºC using a single 5V supply

• Output Voltage (volts) for T (ºC):

• Single-supply operation

• High-level, low-impedance output

outV 0.5 (0.01)T

5 voltsAnalog

Input 0

Bottom View

Data Acquisition with LabVIEW: Temperature K. Craig 6

• DAQ Device

– NI USB 6008

– Analog Input Resolution

• 12 bits differential

• 11 bits single-ended

– Maximum Analog Input Sample Rate (single channel)

• 10,000 samples / second

– Analog Input: ± 10V (single-ended)

– Analog Output: 0 to 5V, 12-bit resolution

Green LED

Data Acquisition with LabVIEW: Temperature K. Craig 7

• Digitizing Resolution

– The NI USB 6008 converts the analog voltage signal to

digital values for the computer.

– A low-resolution converter creates a step-type graph while a

higher-resolution converter creates a more continuous graph.

– The difference can be seen in the graph below.

A digital variable is discrete in amplitude (quantized) and discrete in time (sampled).

Data Acquisition with LabVIEW: Temperature K. Craig 8

• Digitizing Resolution Error

– Digitizing Resolution Error is the difference between the

measured and actual voltage when using an analog-to-digital

converter (ADC).

– Digitizing Resolution Error = (Input voltage range) / (2N)

where N = the ADC resolution.

– The digitizing resolution error is shown in the table below for

the different input voltage ranges for 12-bit resolution.

12-Bit Resolution

Data Acquisition with LabVIEW: Temperature K. Craig 9

Digital Terminal AssignmentsAnalog Terminal Assignments

NI USB 6008

Data Acquisition with LabVIEW: Temperature K. Craig 10

Signal DescriptionsNI USB 6008

Data Acquisition with LabVIEW: Temperature K. Craig 11

Grounded Measurement Floating Measurement

Data Acquisition with LabVIEW: Temperature K. Craig 12

• Selecting a DAQ Device

– Determine the physical properties that need to be measured

now and in the future.

– Select transducers.

– Determine if any signal conditioning is required

– Determine the allowable analog-to-digital conversion error.

– Determine the sample rate required to accurately capture the

physical properties

– Choose the DAQ device that will meet the requirements

Data Acquisition with LabVIEW: Temperature K. Craig 13

Data Acquisition with LabVIEW: Temperature K. Craig 14

• Initializing the DAQ

– The first step to using the DAQ is to instruct the operating system to

communicate with it.

– To do this use the Measurement and Automation Explorer (MAX)

– MAX can be opened from LabVIEW by selecting Tools >> Measurement

& Automation Explorer

Data Acquisition with LabVIEW: Temperature K. Craig 15

• We will be using the NI USB 6008 to make temperature

measurements.

– Plug in the USB 6008 to the computer USB port.

– Open up the Measurement & Automation Explorer (MAX).

– Once MAX has opened, expand the Devices and Interfaces

folder.

– After this, expand the Ni-DAQmx devices folder.

– Note under the NI-DAQmx Devices the NI USB-6008:

“Dev 1”

– See the screen shot on the next slide.

Data Acquisition with LabVIEW: Temperature K. Craig 16

Data Acquisition with LabVIEW: Temperature K. Craig 17

• Opening the DAQ Assistant

– Open a blank VI in LabVIEW and expose the Block

Diagram.

– Right click anywhere on the block diagram.

– Add the DAQ assistant by opening the functions palette and

selecting measurements I/O.

– Next open DAQmx, then click on DAQ Assistant.

– Drag the DAQ Assistant to the block diagram.

– The DAQ Assistant is a graphical interface for configuring

measurement tasks, channels, and scales.

– See screen shots on the next slides.

Data Acquisition with LabVIEW: Temperature K. Craig 18

Block Diagram

Front Panel

LabVIEW

Blank Virtual Instrument (VI)

Data Acquisition with LabVIEW: Temperature K. Craig 19

Blank VI Block Diagram Window

Data Acquisition with LabVIEW: Temperature K. Craig 20

DAQ Assistant

Data Acquisition with LabVIEW: Temperature K. Craig 21

Data Acquisition with LabVIEW: Temperature K. Craig 22

• Selecting the Signal

– The DAQ assistant opens a new window.

– Expand Acquire Signal, then expand Analog Input.

– Click on the Voltage icon.

• Selecting the Sensor Channel

– The temperature sensor is connected to channel 0, so select

ai0 from the DAQ Assistant.

• Sensor Setup

– Maximum voltage 1.5 (corresponds to 100ºC)

– Minimum voltage 0.5 (corresponds to 0ºC)

– Number of samples: 20 Sample Rate: 2 Hz

• Create Conversion Equation

– Right click on the block diagram. Functions >>

Programming >> NumericoutV 0.5

T( C)0.01

See Following

Screen Shots

Data Acquisition with LabVIEW: Temperature K. Craig 23

Data Acquisition with LabVIEW: Temperature K. Craig 24

Data Acquisition with LabVIEW: Temperature K. Craig 25

Data Acquisition with LabVIEW: Temperature K. Craig 26

Data Acquisition with LabVIEW: Temperature K. Craig 27

Data Acquisition with LabVIEW: Temperature K. Craig 28

Set the

number (N)

of samples

in the DAQ

assistant to

20 and the

sampling

rate to 2 Hz

as shown.

Data Acquisition with LabVIEW: Temperature K. Craig 29

Data Acquisition with LabVIEW: Temperature K. Craig 30

Numeric

Data Acquisition with LabVIEW: Temperature K. Craig 31

Right Click Here

Choose: Create >> Graph Indicator

outV 0.5T( C)

0.01

Data Acquisition with LabVIEW: Temperature K. Craig 32

Data Acquisition with LabVIEW: Temperature K. Craig 33

Data Acquisition with LabVIEW: Temperature K. Craig 34

Make Changes to Graph

Change Title

X scale: remove auto-scale and change scale

Y scale: remove auto-scale and change scale

Change Plot Type

Data Acquisition with LabVIEW: Temperature K. Craig 35

Data Acquisition with LabVIEW: Temperature K. Craig 36

Data Acquisition with LabVIEW: Temperature K. Craig 37

Data Acquisition with LabVIEW: Temperature K. Craig 38

• Code Developed by the DAQ Assistant

– The DAQ Assistant automatically develops some code when

it is configured.

– View the code by right clicking on the DAQ assistant and

choosing Open Front Panel.

– Click convert on the window that appears.

Data Acquisition with LabVIEW: Temperature K. Craig 39

DAQ Software Design and Flow Control

• We introduced the fundamentals of software design and flow

control and integrated software and hardware for a simple data

acquisition application in the previous exercise.

• We now expand these fundamental concepts by developing an

example that continuously measures temperature. Additional

capabilities include:

– Selection with a Case Structure

– Repetition with a While Loop

– Timing

• The user will be able to choose how long to acquire data, the

interval between samples, and the units.

Data Acquisition with LabVIEW: Temperature K. Craig 40

Continuous Temperature Measurement

• We will modify the current program:

– Add a Case Structure to the block diagram.

– Add a control for acquisition time.

– Add a control for the sample interval.

– Code the False Case to convert voltage to ºF and the True Case to

convert voltage to ºC.

– Add a Boolean Control for choice of units.

– Add a While Loop and Stop control.

– Add time conversion code.

– Add a greater than or equal to function.

– Add a wait function.

– Wire the nodes.

– Save a run the program.

Data Acquisition with LabVIEW: Temperature K. Craig 41

Data Acquisition with LabVIEW: Temperature K. Craig 42

Data Acquisition with LabVIEW: Temperature K. Craig 43

• Implementing User Preferences

– A key element in software design is to understand the

needs of whoever is going to use the program.

– Here we want the user to be able to change the sample rate,

the number of samples, and the temperature units easily

with a GUI (graphical user interface) when making a series

of measurements.

– To control the sample rate and number of samples, use the

terminals on the DAQ Assistant. Move the cursor to the

first and second terminals on the left side of the DAQ

Assistant. Right click and select Create >> Control

Data Acquisition with LabVIEW: Temperature K. Craig 44

Data Acquisition with LabVIEW: Temperature K. Craig 45

Data Acquisition with LabVIEW: Temperature K. Craig 46

• Algorithms, Pseudo Code, and Flowcharts

– Sophisticated applications require planning and design. A

good design will make the software and hardware easier to

build initially and easier to modify and maintain in the

future.

– Here we begin the design by developing an algorithm – a

procedure or method for solving a problem or producing a

desired result with a computer. The procedure or method

contains the actions the computer should execute and the

order in which they are executed. The procedure requires

us to decompose the problem into small tasks and to define

the relationships between the tasks.

– When designing an algorithm that requires user input, we

must think of the possible ways the user could interact and

design our code to deal with them.

Data Acquisition with LabVIEW: Temperature K. Craig 47

– Here the steps in our algorithm written in English, the

pseudo code, might be:

• Open the program.

• Run the program.

• Read sampling parameters and units from the user inputs.

• Acquire a measurement from the temperature transducer signal.

• If ºC units are selected

– Convert the units and display temperature in ºC

• Else use ºF units

– Convert the units and display temperature in ºF

• End the program.

outV 0.5 9T( F) 32

0.01 5

outV 0.5T( C)

0.01

Data Acquisition with LabVIEW: Temperature K. Craig 48

• Flowcharts are often used to

represent programs

graphically.

• Different symbols represent

different operations:

– Ovals represent program

start and termination.

– Diamonds represent

selections.

– Parallelograms represent

input and output.

– Rectangles represent all

processes.

Data Acquisition with LabVIEW: Temperature K. Craig 49

• Selection with a Case Structure

– Next we will give the user the choice of units using the

LabVIEW Case Structure to control the flow of the

program.

– If the user selects ºC, one case will implement the ºC

conversion formula, or another case will execute the ºF

formula.

– Create space on the block diagram for the Case Structure.

– Insert the Case Structure: Functions >> Programming >>

Structures >> Case Structure

– After we place the Case Structure on the block diagram, the

Run Button arrow is broken to remind us there are

additional steps to programming the Case Structure.

Data Acquisition with LabVIEW: Temperature K. Craig 50

– The green ? on the left side of the Case Structure is the

Case Structure selector terminal. In the default condition, it

accepts a Boolean (True or False) data type control or

constant as input. The value wired to the selector terminal

determines which one of the Case Structure subdiagrams

executes, allowing us to implement the decision from the

flowchart. If the input is true, the program executes the

code inside the True case.

– Move the green ? Lower on the Case Structure border.

Move the cursor over the selector terminal and right-click.

Use the menu to create a control. Label it F or C? (F) to

inform the user that this control changes the units and F is

the default.

Data Acquisition with LabVIEW: Temperature K. Craig 51

– The True Case is displayed when we first add the Case

Structure to the block diagram. The True Case implements

the voltage to ºC formula, and the data flows out of the

structure to the chart. When wires cross the border of a

structure such as the Case Structure, they create a tunnel for

the data to flow into or out of the structure.

– We need to switch to the case that implements the ºF

conversion, code the formula, and wire to the tunnel.

– Switch from the True Case to the False Case by clicking on

one of the arrows in the Case Structure selector label.

– Complete the coding.

– The Boolean control default is False.

– Compare the block diagram to the flowchart.

Data Acquisition with LabVIEW: Temperature K. Craig 52

Data Acquisition with LabVIEW: Temperature K. Craig 53

Broken RUN Button

Data Acquisition with LabVIEW: Temperature K. Craig 54

Data Acquisition with LabVIEW: Temperature K. Craig 55

Data Acquisition with LabVIEW: Temperature K. Craig 56

Case Structure

Selector Label

Selector Terminal

Tunnel

Data Acquisition with LabVIEW: Temperature K. Craig 57

Data Acquisition with LabVIEW: Temperature K. Craig 58

Data Acquisition with LabVIEW: Temperature K. Craig 59

Note Data Types

Double-precision floating pointBoolean

Dynamic

Integer

Data Acquisition with LabVIEW: Temperature K. Craig 60

• Repetition with a While Loop

– So far we have used sequence and selection. We need one

more form of control to build powerful, complex programs

– repetition. There are several repetition structures in

LabVIEW, including a While Loop and a For Loop. Here

we will use the While Loop.

– The While Loop will allow the user to display a series of

values continuously without pushing the Run button each

time or without using the Continuous Run button.

Data Acquisition with LabVIEW: Temperature K. Craig 61

– The addition of the While

Loop changes the pseudo

code to the following:

• Open the program.

• Run the program.

• Read sampling parameters and

units from the user inputs.

• Acquire a measurement from

the temperature transducer

signal.

• If ºC units are selected, convert

the units and display

temperature in ºC

• Else use ºF units and convert the

units and display temperature in

ºF

• If Stop is true, end the program.

Else return to step 3.

Data Acquisition with LabVIEW: Temperature K. Craig 62

– The While Loop repeats the code it encloses until the

While-Loop Conditional Terminal receives a Boolean value

of True.

– Note that the data from the previous loop iteration remains

on the graph until it is replaced by the data from the next

iteration.

– We can change the sampling parameters while the program

is running and LabVIEW will read them before acquiring

data in each while-loop iteration.

Data Acquisition with LabVIEW: Temperature K. Craig 63

To implement repetition in the program, insert a While Loop:

Functions >> Programming >> Structures >> While Loop.

Data Acquisition with LabVIEW: Temperature K. Craig 64

While Loop

Data Acquisition with LabVIEW: Temperature K. Craig 65

Right click the While-Loop Conditional Terminal

and create a control to stop the loop.

Data Acquisition with LabVIEW: Temperature K. Craig 66

Data Acquisition with LabVIEW: Temperature K. Craig 67

While Loop

Conditional TerminalIteration Terminal

Data Acquisition with LabVIEW: Temperature K. Craig 68

• Display Data As It Is Acquired

– Rather than waiting for 20 samples to be acquired, converted, and

displayed, we can observe the value of each data point as acquired

and converted.

– Open the DAQ Assistant and change it to acquire one sample on

demand.

– Delete the controls for sample rate and number of samples, as you

do not need them anymore.

– In order to display previous data, we will change the Graph to a

Chart. Right-click on the Graph. Select Replace >> Modern >>

Graph >> Waveform Chart.

– A graph will erase and replot each time the While Loop iterates,

but a Chart will retain the data from previous iterations.

– To clear the Chart for subsequent runs, right-click on the Chart,

choose Data Operations >> Clear Chart.

– Save the Program: Temperature Measurement One Sample on

Demand

Data Acquisition with LabVIEW: Temperature K. Craig 69

• Explicit Execution Timing

– The While Loop will run as fast as it can and essentially

take all of the computer’s resources from other important

activities. Most times, we don’t need that level of

resources or speed.

– We will slow the While Loop’s iteration frequency by

adding the Time Delay VI (On the Block Diagram:

Functions >> Programming >> Timing >> Time Delay)

– Place the Time Delay VI on the block diagram window, a

dialog box appears prompting the user to set the amount of

time delay. Set it to 0.25 s.

– This type of timing is called explicit execution timing. It

controls how quickly a program executes on the computer

processor. It executes the code in the loop and then

“sleeps” until the wait time has elapsed.

Data Acquisition with LabVIEW: Temperature K. Craig 70

– Alternatively, we can use a Timed While Loop that

executes an iteration of the loop at the period specified. It

provides multirate timing capabilities, precise timing,

feedback on loop execution, timing characteristics that

change dynamically, or several levels of execution priority.

• Software Control Timing

– We may want to acquire data for a specified time duration.

We can implement code that will automatically stop our

program after a specified amount of time.

– Software timing is not exact. It is not deterministic. The

operating system has priority over our program. It can

interrupt processing at any time. Therefore, when exact

timing is critical, use hardware timing in the DAQ

Assistant or use a real-time operating system.