Data Acquisition With LabVIEW - Temperature
Data Acquisition With LabVIEW - Temperature
Technical Communications
Ma
th e
s ic
Hands-On
Engineering Discovery
Minds-On
Engineering Measurement
Social Science
Teamwork
Mechanical Engineering
Professionalism
Civil & Environmental Engineering
Vout T( C)
volts
K. Craig
Temperature Sensor
USB DAQ
5V signal
ground
Temperature Transducer Analog Devices TMP36 Low Voltage, Precision, Centigrade Temperature Sensor Applications: HVAC, automotive, electronics Features:
Temperature span: -40C to +125C Accuracy 2C Linearity 0.5C Temperature coefficient of 10 mV/C with 5V supply Output voltage is 750 mV at 25C using a single 5V supply Output Voltage (volts) for T (C): V 0.5 (0.01)T out Single-supply operation High-level, low-impedance output 5 volts
Analog Input 0
K. Craig
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.
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
K. Craig
NI USB 6008
Analog Terminal Assignments Digital Terminal Assignments
K. Craig
NI USB 6008
Signal Descriptions
K. Craig
10
Grounded Measurement
Floating Measurement
K. Craig
11
K. Craig
12
K. Craig
13
K. Craig
14
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.
K. Craig
15
K. Craig
16
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.
K. Craig
17
Block Diagram
LabVIEW
K. Craig
18
K. Craig
19
DAQ Assistant
K. Craig
20
K. Craig
21
Selecting the Signal See Following Screen Shots 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 100C) Minimum voltage 0.5 (corresponds to 0C) Number of samples: 20 Sample Rate: 2 Hz Create Conversion Equation Right click on the block diagram. Functions >> Programming >> Numeric Vout 0.5 T( C) 0.01 Data Acquisition with LabVIEW: Temperature K. Craig 22
K. Craig
23
K. Craig
24
K. Craig
25
K. Craig
26
K. Craig
27
Set the number (N) of samples in the DAQ assistant to 20 and the sampling rate to 2 Hz as shown.
K. Craig
28
K. Craig
29
Numeric
K. Craig
30
T( C)
K. Craig
31
K. Craig
32
K. Craig
33
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
K. Craig
34
K. Craig
35
K. Craig
36
K. Craig
37
K. Craig
38
K. Craig
41
K. Craig
42
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
K. Craig
43
K. Craig
44
K. Craig
45
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 46
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
T( C)
T( F)
End the program.
Data Acquisition with LabVIEW: Temperature
32
K. Craig
47
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 48
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.
K. Craig
49
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.
K. Craig
50
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 51
K. Craig
52
K. Craig
53
K. Craig
54
K. Craig
55
Selector Label
Tunnel
Case Structure
Selector Terminal
K. Craig
56
K. Craig
57
K. Craig
58
Dynamic
Integer
Boolean
K. Craig
59
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.
K. Craig
60
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 61
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.
K. Craig
62
To implement repetition in the program, insert a While Loop: Functions >> Programming >> Structures >> While Loop.
K. Craig
63
While Loop
K. Craig
64
Right click the While-Loop Conditional Terminal and create a control to stop the loop.
K. Craig
65
K. Craig
66
K. Craig
67
Explicit Execution Timing The While Loop will run as fast as it can and essentially take all of the computers resources from other important activities. Most times, we dont need that level of resources or speed. We will slow the While Loops 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 69
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.
Data Acquisition with LabVIEW: Temperature K. Craig 70