Labview Lab 2 Vern Lindberg April 16, 2012 1 Temperature Measurement Thermistors are sensitive semiconductor devices that can measure temperature over a restricted temperature range. The thermistors we will use are good around the range -50 to 100 C. Nominal resistance at room temperature is 10 kω. In this first step of a two week lab you will design a vi that will read voltage and compute the resistance of the thermistor, and from that compute the temperature using the Steinhart- Hart equation, 1 T = A + B ln R + C(ln R)3 (1) The circuit is almost trivial, a 10 kω resistor in series with a thermistor, powered by 5 V. The 5 V is a nominal value i.e. it not guaranteed to be exactly 5. Although the voltage is not known exactly, the precision resistor, of value R P, can be measured, and the resistance of the thermistor can be found by a simple ratio, R therm = V therm V resist R P (2) Available on the circuit board are a fixed +5V supply and also some banana jacks. At the top left of the board are the analog inputs. In software these are called ai0 etc., but on the circuit board each voltage channel needs two inputs called ACh0+ and ACh0. These are floating inputs, meaning that neither end is connected to ground and that a differential voltage can be measured. Today you will build the circuit from scratch, meaning that you will need to tell the program where the signals originate. The banana jacks are accessed by the breadboard pins called Banana A and Banana B. The thermistor is in a separate box that will be connected to the banana jacks. 1
The hook-up is schematically shown in Figure 1. The arrows in the On Board portion of Figure 1 are hook up wire jumpers, The arrows from the thermistor are banana cables. The precision resistor is nominally 10 kω. Connect the two sides of the resistor to channel ACh0 and the two sides of the thermistor to the ACh1. Figure 1: Voltage Divider using a thermistor. BA and BB are banana jacks. The circled resistor is the thermistor. Use a 10 kω precision resistor. 2 The Read and Calculate Loop The rest is done in software. 2.1 Reading the Voltages (a) Start a new VI with a big While loop in place. (b) Add code so that you can control the rate at which you take data. Start with collecting data every 0.25 seconds. Compute the time in seconds and make an indicator inside the loop to show running time. 2
(c) To collect the data you must access the DAQ board. Add a DAQ assistant from the Express/Input panel, another window will pop up. Choose Acquire Signals, Voltage, and select ai0 and ai1 for the two voltage inputs. The next window lets you specify parameters for the ADC: Call one ResistorVoltageACh0 and the other ThermistorVoltageACh1 (no spaces are allowed in the names). They should both be 0 to 6 V, differential, and 1 sample on demand. (d) Each time through the loop a measurement is made resulting in two numbers, the voltage across the resistor and the voltage across the thermistor. The output of the DAQ is of type DDT (dynamic data type) that has two channels. We need to separate these and get floating point values of each. I have found two ways to do this pick one. (i) Place two From DDT icons, both wired to the DAQ output. From the Configure Menu that pops up, pick Single Scalar, and make the resistor voltage channel 0 and the thermistor voltage channel 1. (Alternately wire constants 0 and 1 to the Channel Input of the From DDTs.) If the From DDT is already in place you can double click on it to get the Configure Menu. (ii) Less elegantly, insert a Split Signals icon from the Express menu and wire to the DAQ output. Place two From DDT icons from the Express menu, one wired to the top of the split signals (ACh0 ) and one to the bottom (ACh1 ). The icons should be Single scalars representing the two voltages. (e) It is a good idea to debug and check as you go. Be sure the DAQ and Elvis are on. Create indicators for the two voltages and run. Add the two voltages that should be the constant 5 V supply. Place a Waveform Chart on the front panel and wire the thermistor voltage to it. Place your finger on the thermistor for a few seconds and stop the program. As the temperature increases, you should see one voltage increasing and one decreasing. Once you know that the VI works, you may delete any of these indictors, 2.2 Computing the resistance and temperature Equation 2 and Equation 1 give the means of calculating the temperature. (a) Compute the resistance. Measure the value of your nominal 10 kω resistor with a multimeter. From the two readings of voltages and this resistance, you can determine the resistance of the thermistor with Equation 2. 3
Use a Mathematics Scripts&Formulas Formula Node. Right click on a boundary and Add inputs and outputs, naming each of them. Inside the formula node write the equation, ending with a semicolon. Your formula might look like RT=Rp*VR/VT; Avoid writing in the value of the precision resistor in the formula, instead create a constant outside with its value. That way it is easy to find and change if the precision resistor is changed. (b) Use another Formula Node and compute temperature using the Steinhart-Hart Equation 1 using A = 1.03245 10 3, B = 2.38582 10 4 and C = 1.58647 10 7, (all in K 1 ), where the resistance is in Ωs. The resulting temperature is in K. (I may be off on these constants a little bit, but am close. ) Also compute the temperature in Celsius and Fahrenheit. HINT: Make constants outside the Formula Node for A, B, and C, in these constants scientific notation for A is written 1.03245E-3. Inside the formula node you use +, -, *, /, and ** for the mathematical operations, and can use ln for the natural log. (c) Place a Waveform Chart on the front panel and place inside the loop to display the celsius temperature. (d) Run the program and make sure that it works as desired. 3 Displaying the results and Saving Data (a) Inside the loop build the array that will eventually be saved in an Excel file. Use a Build Array icon, enlarge it to have 4 inputs, make the first the time, the second the kelvin temperature, the third the celsius temperature, and the fourth the fahrenheit temperature. Connect the output of this array to an indexed tunnel. (b) Since the data are collected in equally spaced intervals, a Waveform Graph is suitable. Bring time to a non-indexed tunnel, kelvin, celsius, and fahrenheit temperatures to indexed tunnels. Place a Waveform Graph outside the loop and add the bundle that is suggested by the context help for the Waveform Graph. Plot fahrenheit (or celsius, your choice) temperature versus time outside the loop. Run the VI and touch the thermistor to change its temperature. (c) Finally write code to save the file. This is an involved process. (i) First you must tell the computer where to store the data. Place a FileI/O File Constants Path Constant outside the loop. In your Documents folder/library 4
create a folder to hold the data files. Right click on the Path Constant and Browse for Path and locate folder you just created. Click Current Folder and the path to that folder is created. (ii) Create a File Name: Deposit a String Control on the front panel, and a string constant.xls on the block diagram. Place a Strings Concatenate Strings on the block diagram and wire the file name and extenstion to the two inputs. (iii) Place a File I/O Build Path and wire the Path Constant to the base path, and the concatenated filename to the name inputs. (iv) From the File I/O menu deposit Open/Create/Replace File, Write Text File, Close File icons. The inputs to the Open... icon are the appended path from the Build Path, and an operation input. Create a constant at the operation input and choose Create from its pull down list. Connect the refnum out to the file input on the Write to Text, and the error out to the error in. Connect the refnum and error lines between the Write to Text and the Close File. Finally, place a Dialog and User Interface Simple Error Handler and connect the error out of the Close File to the error handler (v) Final step! The array data must be converted into a form that can be written to the file. Place a String Array to Spreadsheet String near the tunnel for the array. Connect the array to the array input (duh!). Connect the spreadsheet string to the text input of the Write to Text file. Create a constant at the format string input of the Array to Spreadsheet and make it %.2f, that is a floating point number with 2 digits after the decimal point. Put in a file name, then run your program, changing the temperature of the thermistor, stop it, locate the file in the folder you prepared, and open and it should open in Excel (after a prompt from Microsoft.) Run a second time with the same filename and see the error that results. As written the program Creates a file, and if that file already exists tells us of the error. We will discuss ways to reduce this aggravation in class. Add comments and adjust the layout so that your vi is neat. Print the front panel and block diagrams and place into your labbook. Be sure to save your vi, then save a copy to a new name. 5
In class we will (or have already) discuss a few other nice features that could be added to the saving process, namely Add the hour, minute, second to your file name so it will be unique (e.g. File132508.xls) Add date and time automatically to your file Add a comment to the file, such as Temperature of coffee as it cools Add column headers to your file 4 Subvis Saving data is a regular task, and regular tasks should be sub-vis. Then your main VI should read the voltages, compute thermistor resistance and determine the temperature. A subvi should take care of saving the data. Before doing any coding list the desired inputs to the subvi. In this case they would be (a) path (b) file name (c) format of data, and (d) data (and eventually Comments, and Headers.) Make sure that the labels for your controls are meaningful, since that is the lowest level of documentation. Move these 4 elements on the block diagram to the left, and the rest of the writing portion of the program to the right. Drag around all elements of the writing portion not including the 4 inputs (but the.txt, Concatenate, File opening, writing, closing and error handling and the Array to Spreadsheet should be included), then use Edit pull down menu and Create Sub VI. The selected elements should disappear and a new icon appears. Double click on this new icon to see the front panel and block diagram just for it. Right click on the connector pane (upper right corner icon) and you can edit the icon. Right click on the icon, go to VI Properties, use the category pull down menu to go to documentation, and add a brief description. This will appear in the contextual help. Save the subvi, then save your main vi. 6