327 - Lab 9 4/10/16
Physics 327, Spring 2009
Lab 9: LABVIEW and GPIB
LabVIEW (National Instruments, Inc.)
LabView (LV) is a software package which allows the programming of instrument control and data acquisition by a computer. The programming is done by creating “virtual instruments” in software using graphical manipulations, e.g., instruments are connected by virtual “wiring” on the monitor screen. VI’s, virtual instruments, may be combined to form a larger VI, in a way similar to the way conventional subroutines are combined to make larger programs or larger subroutines.
A VI is made up of two parts: the “front panel” and the “block diagram”. The front panel is where you can interact with the VI. In the front panel, you may enter values in controlling parameters (inputs to the VI), read indicators (outputs from the VI) and look at graphs of measured quantities. The block diagram may be thought of as the program code which specifies the steps in the VI. The programming is done by “wiring” between the terminals of various icons. If wiring is incorrect in some way, LV tells you so. (You can remove all the bad wires by a key stroke!). The writing or reading of a disk file can be specified in the block diagram.
General Purpose Interface Bus (GPIB), also called IEEE-488, is a communication protocol used between computers and instruments. A GPIB hardware board (made by National Instruments) has been installed on the PC. The GPIB boards may be programmed into LabVIEW VI’s. A Hewlett-Packard digital multimeter (model HP34401A, referred to simply as HP) will be controlled via instructions through GPIB board; the Stanford Research Systems spectrum analyzer, used last term in 326, can also be controlled.
Verify that the GPIB connectors are securely fastened, then turn on the pc and the HP.
1. Launch LabView by clicking Start/Physics and Math/National Instruments LabView6. You will first inspect some existing VI’s, then create your own.
2. Open the virtual instrument (VI) Frequency Response.vi. Choose “open vi”, go to C: Program Files/ National Instruments/ Labview 6SE/ examples/ apps/ freqresp/ Frequency Response.vi. The window that opens up is the “Front Panel” of the VI. Open the Wiring Diagram (Block Diagram, the “innards” of the VI) by clicking Window/Show Diagram. “Tools” and “Controls” pop up menus are used with Front Panel. “Tools” and “Functions” pop up menus are used with Block Diagram. You will work with these pop up menus as you go along the experiment. [If you want to follow an on-line tutorial of basic operations, you may do so by opening the tutorial folder.]
2.1. This VI measures the frequency response of the gain of an unknown “black box”. A function generator supplies a sinusoidal input to the black box. A digital multimeter measures the output voltage
2.2. Run the VI by clicking on the arrow in the upper left corner of the Front Panel window, and play with the available controls in the Front Panel. . What kind of filter does the black box contain?
2.3. Open and examine the Block Diagram. Turn on “context help” in the Help menu to see descriptions of elements in the diagram. A double left click shows the front panel of an element – this is sometimes helpful. Note that there is no explicit element for the black box – its function is hidden in the details of the “Simulate UUT” element.
2.4. Close the VI. Do not save any changes.
3. From File menu, choose Open to open and go to examples/measure/maxmpl.lib. Open Frequency Analysis of a Filter Design.vi.
3.1 Run the VI. You can stop the VI by clicking the stop sign button. The values in the front panel can be changed. While the vi is running, change the parameters that specify the filter. Specifically, try band pass, low pass, high pass, and band stop filters. Try to find parameters such that the frequency response is within the given “mask” throughout the entire frequency range. Print out the front panel once you have succeeded.
3.2 Open the wiring diagram (Window/Show Diagram). This is the “source code” for this VI. The program contains for loops and a logical case structure. The lines are “wires” which connects various parts of the program. Note that there are boxes called “Uniform White Noise Waveform.vi”, “IIR Filter for 1 Chan.vi”, “Frequency Response Function.vi”, and “Limit Testing for Cluster.vi”. These are sub-VI’s (analogous to subroutines in conventional language), corresponding to a function generator and a multimeter, respectively. If you double click in one of the boxes, the front panel for the sub-VI shows up. Try it (while the main VI is running!). Look at the block diagram. At this point do not worry about how the programs are made up.
3.3. From File menu, close the VI’s. Do not save any changes.
4. We will now learn to control the HP with the pc via GPIB communication. In the process you will write a new VI. Each instrument connected to the resident GPIB board is assigned an address (a string constant). The address of the HP is displayed immediately after its power is turned on. Note the address. If the address happens to be 21 (which is used by the PC), it must be changed.
4.1. The process of sending information or data to an instrument is called “writing” data to the instrument. Writing is used for example to change the sensitivity of the HP. Retrieving data from the instrument to the PC is called “reading”. Functions are already provided by LV for writing and reading.
4.2. Open a new VI and go to its Block Diagram. Change the tool to arrow cursor. In the Functions pop up menu, move cursor to “Instruments I/O” icon box. Select the “GPIB” icon and then “GPIB Write” (which shows an arrow going from pc to instrument indicating that data flows from pc to instrument). Place the icon into the Block Diagram.
4.3. From Help menu, choose Show Context Help. A pop up window appears. Then go back to the Block Diagram and place the cursor on the GPIB Write icon. The pop up help window now shows the wire connections that can be made. The “address string” and “data” terminals must be connected for the GPIB Write to operate. (Other terminals will be dealt with later.) The next step shows one way of doing this.
4.4. In the Functions pop up menu, select “String”, then “String Constant”. Copy the “String Constant” icon to the left side of the “GPIB Write”. Change the tool to finger cursor, click inside the “String Constant” box and type in the address of the HP. With the wiring tool, connect the string constant box to the “address string” input of the GPIB Write icon. If the wire is successfully made, it shows a solid magenta color line. If not, a dotted line (broken wire) appears. That’s easy to fix. Just delete it and try it again.
Go back to the Functions menu and get another “String Constant”. Wire it to the “data” terminal of the GPIB Write. The text written into the “data” terminal will be transmitted (“written”) to the HP.
4.5. Write “conf:res” (don’t type the quotes) into the “data” string constant. Then click the run button. Verify that the HP changes to resistance measurement mode. At this point, read the HP manual to see how the configurations can be changed. Then configure the HP for dc voltage measurement. Verify the change of configuration on the HP display panel. Try other configurations.
4.6. Next we will learn how to read data from HP. You first have to ask (or write to) the HP to get the data ready. Then you will read what the HP puts on the data lines. To measure resistance, enter the following text into the “data” of the “GPIB write”:
The first line configures the HP for resistance measurement. The second line chooses the trigger mode for immediate measurement. The third line requests the HP to put the resistance reading on the GPIB bus. See pp. 119 and 155 of HP manual for details.
From the Functions menu get a “GPIB Read” icon (which shows an arrow going from instrument to pc indicating that data flows from instrument to PC) and place the icon to the right of the “GPIB Write” icon. The Help pop-up window again identifies the wire connections. Connect the string constant box containing the address string to the “address” input of the GPIB Read icon.
You must connect an integer number (20 will do) to the “byte count” input. (This sets the number of bytes of data to be read from the instrument.) To do this, choose “Numeric” from the Function menu and select a Numeric Constant.
To display what is read from the instrument, go to the Front Panel. From the Control menu, select “string”, then “string indicator”. Move the “string indicator” icon into the Front Panel. Type in a label for it such as “Data Read from HP”. Now go to the Diagram. A box with the label you just made should be visible in the Diagram. Move the box and the label to the right side of the “GPIB Read” icon. Change the pointer to wiring tool and connect the indicator to the “data string” of the Read icon. Finally connect the “error out” terminal of the Write icon to the “error in” of the Read icon. This guarantees that the write process (sending commands to HP) occurs before the read.
Now connect a thermistor to the resistance terminals of the HP and click Run. The Front Panel indicator should show the resistance value.
5. You will now repeat the measurement N times using a For Loop. From the Functions menu, select “Structures”, then “For Loop”. Move the For Loop into the Block Diagram. (N is called count terminal and I the iteration terminal. The variable I counts from 1 to N.) With the arrow pointer, increase the frame size of the For Loop icon.
Now move your entire previous program into the For Loop. First select all your icons and wires (click the mouse in the upper left, drag to the bottom right to make a rectangle around your icons, then release mouse button), then move the selected items with the mouse.
Go to the Front Panel. From the “Controls” menu, point to “Numeric” and choose “Digital Indicator”. Place the digital indicator in the Front Panel and type “Iteration Number” into the label box. Return to the Diagram. The indicator box should be visible in the Diagram. Move it inside the For Loop if it is not already. Connect a wire from the iteration terminal to the indicator. From the Functions menu, go to “Numeric” and choose “Numeric Constant”. Move the “numeric constant” icon to the block diagram. Type in some number around 10. Wire it to the “Count terminal” N. Go back to the Functions menu, go to “Time and Dialog” and choose “Wait Till Next ms Multiple”. Place it within the For Loop frame. From Functions menu get a “numeric constant” as done before. Place it on the left side of the “Wait Till ...”. Type the number of ms to wait between iterations (make it several 100 ms).
Go back to Front Panel and click run. The indicator should change at the time interval set. Increase or decrease the time interval in the block diagram to verify its effect.
6. You will now learn how to create an array of numbers and to store the array as a Matlab or spreadsheet file. From Functions men, open “Array” and choose “Build Array.” Locate it outside and to the right of the For Loop. When you first create the array, it has only one row (indicated by a short bar) of elements. Additional rows can be added by pulling on a corner of the icon with the cursor. Increase the size of the array such that it contains two rows. Connect a wire from the iteration number I of the For Loop to the first (upper) row element of the array icon.
Now convert the string output of the GPIB read command to a number, using the command “Fract/Exp string to number”, in Function/String/String to Number Conversion. Display this number on the Front Panel using a digital indicator, and connect it to the second (bottom) row of the array icon.
In order to write your data (iteration number and resistance, bundled in an array) to a spreadsheet file, go to the Functions menu. From “File I/O” choose “Write to Spreadsheet File” and move it to the right of the “build array” icon. Connect the output array of the “build array” to the “2D data” input terminal of the “Write to Spreadsheet File” icon. You have to specify the file name for the spreadsheet and where to store it. Go back to “File I/O” and choose “Path Constant” and place it above the “Write to Speadsheet File” icon. Write into the file path into the Path Constant: C:\documents and settings\undergrad\my documents\filename.txt (Matlab) or filename.xls (spreadsheet), where you replace “filename” with your own unique filename for the spreadsheet. Wire the path name to the “file path” input terminal of the “Write to Spreadsheet” icon. Also connect a logical true (found in “Function/Boolean”) to the “transpose?” input in order to save columns instead of rows.
Now go back to Front Panel and run the program. If all is well, a file should have been saved in the folder you specified. Open the file with Matlab, Windows, or Excel to see that it contains two columns, consisting of the iteration # and the resistance (in Ohms), respectively.
7. Using your For Loop structure, make a VI which takes a total of N (to be specified via a control on the Front Panel) measurements of resistance. The time to wait between measurements should also be specified on the Front Panel. Save the VI. Print out the VI (panel and diagram). Include it in your report.
8. Let the thermistor equilibrate to room temperature. Use your VI to measure how the resistance changes as function of time after you begin to hold the thermistor in you hand. Store this as a data file.
8.1 Use the VI to measure how the resistance returns to its room temperature value after you release it. Save this as another data file.
8.2 Plot the data files you obtained for resistance versus time using Matlab, Excel or other plotting software. Convert the R vs. time data into temperature vs. time by using the thermistor formula and a crude calibration between room temperature and body temperature. The plot should include the steady states before and after the warming and cooling.
9. Modify your VI such that the resistance is displayed on a graph in the Front Panel. Hint: look at one of the VI’s you inspected earlier. Save your VI for later modification and use.
C. AD590 Temperature Sensor
The AD590 Temperature Sensor is a semi-conductor device which passes a current that is proportional to temperature in degrees K; the proportionality is 1 A per K, see the data sheets available on the web site. Thus at a temperature of 300K, the current is 300 A. The current is independent of bias voltage in the range 4 to 30 V. Since current carries the temperature information, the sensor is particularly useful in remote situations.
You will embed the AD590 in an op-amp circuit, read the circuit’s output voltage with the HP and use your VI to plot temperature vs time; you will turn on a warning light in the front panel of your VI when the temperature is too high.
1. Op-amp Circuit: Connect the AD590 between +12V and the negative input to the LM741 or equivalent. Ground the positive input. Use a 10K resistor for negative feedback from the LM741 output to the negative input. Don’t forget the power connections to the LM741. There is no need for offset adjustment in this application. What is the output voltage at a termperature of 300K? In your report, explain this circuit.
2. Connect the output voltage of the LM741 to the HP. Modify your VI from step B9 to read DC voltage from the HP, see step B4.5 earlier.
3. Modify your VI so that the data displayed in at least one indicator and the graph on the front panel is temperature in degrees K. This can be done with the “Multiply” element and “Numeric Constant”. Try your VI.
4. Modify your VI so that a “Square LED” on the front panel lights up if the temperature goes over 300K while the VI is running. This indicator is in the “Classic Controls/Boolean” menu. The comparison of current data to 300K can be made with the “Greater Than” element (“Comparison” menu) and “Numeric Constant”.
5. Print your VI with a graph showing a warmup and cooldown of the AD590.
D. Lab Report
When reporting a VI that you have created, give a brief description of its function and method, as well as the printout of the front panel and block diagram.
Your lab report should include:
1. A brief description of the LabVIEW application program. Do not exceed one page, but include brief discussions of its differences, advantages and disadvantages compared to the conventional code-based programming languages.
2. Printout of the Front Panel of the Frequency Analysis of a Filter Design.vi, after finding parameters that solve the design problem.
3. The printouts of the Front Panel and Block Diagram, and description, of the VI you made to measure the resistance of thermistor as function of time. The icons and wires should be neatly arranged for easy inspection.
4. The formula to convert thermistor resistance to temperature using your crude calibration.
5. The temperature vs. time graphs for both warming and cooling processes
6. Discuss how well the time dependence of the temperature can be approximated by an exponential.
7. The printout of the Front Panel and Block Diagram, and description, of the VI you made to display the resistance of the thermistor as a function to time in a graph in the front panel. The graph should show an actual trace of a measurement.
8. The printout and description of the VI for the AD590 temperature sensor in Step C.
9. An explanation of the op-amp circuit with the AD590.