labview manual 2009

47
LabVIEW Course Leiden University

Upload: eleazar-von-lietchenstein

Post on 14-Apr-2015

64 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: LabVIEW Manual 2009

LabVIEW Course

Leiden University

Page 2: LabVIEW Manual 2009

2

Index INDEX ........................................................................................................................................................... 2 INTRODUCTION ........................................................................................................................................ 4

LABJOURNAL............................................................................................................................................... 4 SAVING YOUR VIS ...................................................................................................................................... 4 TIPS, TRICKS & SHORTCUT KEYS................................................................................................................ 4 [E]-QUESTIONS ........................................................................................................................................... 4

PRACTICUM 1 ............................................................................................................................................ 5 FRONT PANEL & BLOCK DIAGRAM ............................................................................................................. 5 COMPUTER SETTINGS.................................................................................................................................. 5 AUTOMATIC TOOL SELECTION .................................................................................................................... 6

Hello World ............................................................................................................................................ 6 DATA TYPES: FLOATS, BOOLEANS, ETC. ..................................................................................................... 7 EXECUTION HIGHLIGHTING......................................................................................................................... 8 LOOPS ......................................................................................................................................................... 8 DATA TYPES: ARRAYS ................................................................................................................................ 9 DATA TYPES: STRINGS.............................................................................................................................. 10

IEEE 488: GPIB Communications ....................................................................................................... 11 Synthesizer............................................................................................................................................ 13

SEQUENCE STRUCTURES ........................................................................................................................... 13 WAIT STATEMENTS................................................................................................................................... 13 INDEXING .................................................................................................................................................. 14 A/D CONVERSION ..................................................................................................................................... 15

Loudspeaker ......................................................................................................................................... 15 PC Operated Frequency Sweep............................................................................................................ 15

I/O CARDS................................................................................................................................................. 17 DAQMX SINGLE POINT OUTPUT ............................................................................................................... 17 DAQMX MULTIPLE POINT OUTPUT .......................................................................................................... 18 BASIC PLOTTING: WAVEFORM GRAPH...................................................................................................... 20 DATA TYPES: CLUSTERS ........................................................................................................................... 20 DAQMX CONTINUOUS OUTPUT ................................................................................................................ 20 CASE STRUCTURE ..................................................................................................................................... 21

A LabVIEW Function Generator .......................................................................................................... 22 SINGLE POINT INPUT ................................................................................................................................. 24 MULTIPLE POINT INPUT ............................................................................................................................ 24 CONTINUOUS INPUT .................................................................................................................................. 24 CONTINUOUS INPUT: DETAILS................................................................................................................... 25 AUTOMATED DATA STORAGE ................................................................................................................... 27 DATA TYPES: PATHS ................................................................................................................................. 27

Check the 5V Voltage Source ............................................................................................................... 27 ADC LIMITATIONS.................................................................................................................................... 28 CUSTOM SUB-VIS ..................................................................................................................................... 28

The Temperature Converter ................................................................................................................. 28 USING CUSTOM SUB-VIS .......................................................................................................................... 29 DATA TYPES: WAVEFORMS....................................................................................................................... 29 MEASUREMENT & AUTOMATION EXPLORER............................................................................................. 29 PROPERTY NODE ....................................................................................................................................... 30 RS232 COMMUNICATION .......................................................................................................................... 30

PRACTICUM 2 .......................................................................................................................................... 31 INTRODUCTION.......................................................................................................................................... 31 THEORY .................................................................................................................................................... 31

Page 3: LabVIEW Manual 2009

3

BASIC DIGITAL FEEDBACK MECHANISMS ................................................................................................. 32 Proportional Feedback......................................................................................................................... 33 Integrating Feedback............................................................................................................................ 33 Differential Feedback........................................................................................................................... 34

COMBINED FEEDBACK MECHANISMS......................................................................................................... 34 Proportional & Integrating Feedback.................................................................................................. 34 Proportional, Integrating & Differential Feedback ............................................................................. 35

THE PHYSICS OF NTC RESISTORS ............................................................................................................. 36 THE HEATING DEVICE............................................................................................................................... 37 EXPERIMENT ............................................................................................................................................. 38

Precautions........................................................................................................................................... 38 Hardware.............................................................................................................................................. 38 Thermal Response Time........................................................................................................................ 39 Software................................................................................................................................................ 39

TEMPERATURE CONTROL WITH PI FEEDBACK ........................................................................................... 40 Optimization of the feedback parameters ............................................................................................. 40 References ............................................................................................................................................ 41

PRACTICUM 3 .......................................................................................................................................... 42

Page 4: LabVIEW Manual 2009

4

Introduction LabVIEW is a programming language developed by National Instruments, and designed to facilitate communication between different types of hardware, such as personal computers, function generators, A/D converters, et cetera. It has a graphical way of depicting pieces of code, instead of being text-based.

Labjournal For practicum 1 you are only required to write down the answers to the questions in your labjournal, perhaps adding prints of some block diagrams; you will be asked to do so when necessary. In practicum 2 and 3, you are required to keep a labjournal1, as you would make with laboratory experiments. Note that the course schedule for this year is not yet updated: LV 1,2 and 3 in the schedule together form practicum 1, LV 4 is practicum 2 and LV 5 is practicum 3.

Saving Your VIs Be sure to save your VIs regularly, preferably every time it is required in the course to add new functionality. This will facilitate debugging, and can be handy for future reference. Saving subsequent versions of VIs is also a standard laboratory practice.

There are several saving options when you select ‘File|Save As’ in LabVIEW 8.x. Choosing ’Substitute copy for original’ is most convenient if you just want to save the current VI as version

x.y and continue with programming. If the LabVIEW Help is open, you can see what the different saving options exactly mean.

Tips, Tricks & Shortcut Keys You can find them in the addendum by National Instruments, included in this manual. Learning them by heart immediately is possible, but it is easier to learn them while you learn to use LabVIEW.

[E]-Questions Sometimes an [E]-symbol is added to a question in this manual. This means the question is not mandatory. Skip it if you do not have enough time to complete the necessary questions; you can always do it later.

1 The words ‘report’ and ‘labjournal’ will be used interchangeably.

Page 5: LabVIEW Manual 2009

5

Practicum 1 In this practicum you will be introduced to the basics of LabVIEW. To start, open LabVIEW and create a ‘Blank VI’.

Front Panel & Block Diagram What you should see in front of you are two panels: a white and a grey one. The grey one is the Front Panel, and will contain the interface of your program, with buttons, indicators, and so on. The white one is called the Block Diagram, and will contain the actual code itself, so the for-loops, the multiplications, et cetera. There are several ways to arrange these panels on your desktop: in ‘Window|’, you can select the tiling ‘Left and Right’ or Up and Down’, which creates a non-overlapping tiling of the two panels. You can also keep the panels overlapping, and use Ctrl-E to swap between the two while programming. The programs you make can be run with this button:

Ctrl-R has the same effect; try this. The button next to it can be used to run a program over and over again, but handle this button with care; sometimes it will make LabVIEW crash. Note also that it is bad practice to use this button as some sort of while- or for statement. To stop programs while running use Ctrl-. (Ctrl-‘dot’) or the ‘Stop Button’ depicted in Figure 2. This button is depicted as inactive, but will be active when a program is running.

Computer Settings The LabVIEW interface can be customized to a large extent. However, to keep this manual readable and to facilitate teaching assistant supervision during the course, it is more convenient to use standard settings. These settings can be found in the ‘Tools|Options’ section. Another part of the interface that can be modified (but for convenience should be kept as it is for the duration of the course) is the look of the ‘Functions Palette that you can open with right-click on the block diagram. Its view, which can be changed after clicking on the drawing pin by clicking the button next to the button the magnifying glass, should be set to ‘Category (Standard)’

Figure 1: Run.

Figure 2: Abort Execution.

Figure 3: Tools Palette.

Page 6: LabVIEW Manual 2009

6

Automatic Tool Selection Open now View|Tools Palette. The settings you have just seen make (among other things) sure that while using LabVIEW, the proper tool is selected for your needs automatically. This is done by hovering over objects in your front panel and the block diagram; this will make the pointer change into one of the objects in Figure 3, with the following functionality:

• Wrench and Screwdriver: turn on/off automatic tool selection • Finger: push buttons • Pointer: select, resize • Text Tool: write text or numbers • Bobbin: create wires between objects, create connected controls/indicators • Menu Tool: same as right-click • Hand: pan • Breakpoint: create point where program ‘pauses’ (execution can be resumed) • Probe: show contents of wire during execution • Pipette: assume color • Brush: paint with color

Hello World

Save your VIs before you run them. This can save you hours of work; some students have

learned this the hard way. The first programming task you are going to complete is actually not creating a ‘Hello World’ string output, but it comes close. It will be an exercise to demonstrate the basic functionality of LabVIEW, and will therefore be fairly trivial. Follow the text and, if you get stuck, check the footnotes for tips. Right click on the front panel and click on the drawing pin on the pop-up screen. This will lock this pop-up screen. Now place a ‘Numeric Indicator’ on the front panel and

Figure 4: Create numeric indicator.

Page 7: LabVIEW Manual 2009

7

obtain a picture2 as in Figure 4. Now go to the block diagram via ‘Window’|Show Block Diagram’ or Ctrl-E, and connect a ‘Control’ to the indicator you just made. This can be done with the pop-up menu opened by right-clicking on the indicator3. See Figure 5. This will create an object that allows you to insert any number at that point into the program. Double-click now on this newly created control in the block diagram; this will make you jump to front panel (alternatively, Ctrl-E will get you back to the front panel as well), where you can enter a number in the control. The control accepts many different notations: 1E2, 2e3, 3.4, 5k, 6m and 7M are all allowed. Now use the run button to use your first LabVIEW program.

Data Types: Floats, Booleans, etc. Just as many other programming languages, LabVIEW also supports different types of data types. Examples are integers, Booleans, complex numbers, and double precision floats, as the one you just used. To see how the Booleans look like (remember: this is a graphical programming language, so all its elements have a certain look), we shall now extend the program with an element that can check whether the number you just typed is larger than a pre-specified number. To do this, right-click on the block diagram, and select ‘Programming|Comparison|Greater’ (from now on the ‘Programming|’-division shall be assumed unless otherwise stated). Place this icon on the block diagram, somewhere close to the line between the two orange boxes. You have now placed a sub-VI on your block diagram. Compared to C++, this would roughly be a function that you can call from ‘main’. LabVIEW comes with a large library of sub-VIs with all sorts of functionalities, and they can be accessed via the function palette. In addition, you can make custom sub-VIs; that will be the subject of a later section of this practicum. Connect4 your control to the ‘x’-terminal of the comparison sub-VI. Create a control on the ‘y’-terminal with the steps outlined above. Create5 an indicator for the Boolean that comes out of the ‘Greater?’ sub-VI. Now go to the front panel and check whether your program responds the way you expect it to respond.

Q.1 How does the Boolean indicator change if it changes from False to True (or vice versa)?

2 Click on ‘Numeric’, and select the ‘Numeric indicator’ (hover over the icons to see how they are called). Now place this indicator somewhere on your front panel. 3 Hover over the box and notice how the pointer changes into a bobbin. 4 Click with the bobbin on the orange line in your program, and connect the dotted line to the ‘x’-terminal. 5 Right click on the left terminal and select ‘Create|Indicator’.

Figure 5: Create Control.

Page 8: LabVIEW Manual 2009

8

This might be the first place where you encounter a bug in your program. If your program cannot be run, the ‘Run’-button will have changed. If this is the case, you can click on this button

to see where the bug(s) is (are) located.

Execution Highlighting Once you have a program that works properly, you can look at the following functionality which makes LabVIEW very convenient at times. Go to the block diagram and click the following button (Figure 6):

Now run the program and observe what happens. This ‘Execution highlighting’ can be quite handy to debug your program. It slows down the program, and allows you to observe the values on all the wires, controls, indicators, et cetera, in your program. If you do not want to slow down your program, but nevertheless want to see what data is on a certain wire, right-click on the wire and use the ‘Probe’, while running the program.

Q.2 Give the difference(s) between the icons that represent inputs and outputs. Do this for the block diagram only, and watch for the differences that are independent of the datatype represented by the in- or output.

Loops To repeat certain operations, LabVIEW can execute while- and for loops. Their function is virtually identical to those bearing similar names in C++. To illustrate their behavior, go to the functions palette6, select ‘Structures|While Loop’, and place7 it on your block diagram.

Q.3 The program is not executable now. What is the problem according to the message you get from the “broken” run button?

If you need to drag a very large while-loop around you program, your program is probably taking up too much space. Make your program more compact by click-and-dragging the icons on the block diagram more closely to each other. This will make your program easier to read,

which will become especially useful when your programs contain more and more elements. Compare this with using indentions in C++ for instance: strictly speaking the code will work

without it, but it will be easier to read.

6 This palette is only available when the block diagram is the active window on your desktop. 7 Click-and-drag this loop around the program you have already made.

Figure 6: Execution Highlighting.

Page 9: LabVIEW Manual 2009

9

Now connect the ‘Loop condition’ to the green line carrying the Boolean. Use ‘Execution highlighting’ while you do a few test runs with your program, to see what this Loop condition is meant for and how you can change it. Then use the LabVIEW Help, available via Ctrl-H, F1 or the menu to check whether you ideas about it are correct. A for loop is a loop that is executed only a predetermined amount of times. With the counter from the while loop (the blue box with an ‘i’ inscribed) and the comparison elements in your while loop, you can however build the same functionality in your own program. Modify your program in such a way that you get the following block diagram (Figure 7).

Q.4 If ‘y’ is N (with ‘N’ an integer), what then is the value of ‘Numeric’ after execution of the loop? Explain this.

Sometimes it is necessary to carry over information from one loop iteration to the next. The value of the counter is an example; this memory is already implemented in the blue box with the ‘i’ inscribed. But think of a situation in which you would like to compare, say, the measured temperature (yes, with LabVIEW one can ultimately measure physical observables like temperature) in the current iteration with that from the previous. For these situations one can create an additional memory element called the ‘Shift Register’. To make this memory element, simply right-click on the side of the while-loop and select ‘Add Shift Register’. You should see the two elements visible in Figure 8: Shift register. At iteration N one can wire any data type into the right element on the edge of the while loop, which will then become available in the subsequent iteration N+1 from the left side of the loop.

Data Types: Arrays An array is just an ordered collection of items. In this section you shall make a one dimensional array of integers that can be used for plotting, calculations, et cetera, with the while-loop we just created. Now if one wants to stack numbers, what one has to do in words is the following:

• Get the existing stack from the memory, if there is any • Add one number to the stack • Put the appended stack back into the memory

To add a number to the stack, or in general, to ‘build an array’, you need a sub-VI that builds an array. Luckily, there is just such a VI in LabVIEW’s standard library. On the block diagram, place

Figure 7: While loop.

Figure 8: Shift register

Page 10: LabVIEW Manual 2009

10

the ‘Array|Build Array’-icon in your while loop. By default, this VI has one input and one output. Wire the while loop counter to the input. In order to complete the building process, you need the existing stack, and another input for this stack. This existing stack comes from the shift register (the left box on the edge of the while loop is a data source). To build the array by adding the existing stack to the element from the counter, add this extra input by expanding the sub-VI8. Alternatively, you can right-click on the icon and select ‘Add Input’. Now wire the output of the ‘Build Array’ sub-VI to the shift register sink (the box on the right side of the loop) and you will see that it changes color. Once the shift register sink is connected, the source for the subsequent iterations can be connected to the remaining open input from the build array sub-VI.9 Unfortunately, you have no access now to the contents of the array. In order to see the contents of the array, right-click on the ‘Shift register’ outside the while loop, and create an indicator. Now go to the front panel and find the array. What you should see is depicted in Figure 9. You recognize the grey box: that is the indicator that shows what value is inside. But the array has more than one element, and to visualize the, you can perform the same expansion trick as with the ‘Build Array’ VI. The white box with the number in it is the coordinate of the first element of this row. If you have two or more white boxes, you actually have a two (or higher) dimensional array.

Note the change in thickness of the wire that carries the array; all different data types have a different wire.

Q.5 Set ‘y’ to 0 and run the program a few times. What array do you see in the output? Q.6 What happens to the array when you reverse the inputs on the ‘build array’-elements?

The issue you encountered in answering question Q.5 in using the memory of the shift-register is that it has to be erased at the beginning of the program, and now this step is not yet implemented. To erase this memory before each execution of the program: right-click on the left connector of the shift-register and create a constant. This constant is actually an empty array, which will overwrite/delete everything that was in the memory reserved for the shift register from a previous execution of the program.

Data Types: Strings Apart from handling numbers and Booleans, LabVIEW can handle text strings. One particular use of them is in automated data storage. In such an application, one would for example like to create logically named data files in a particular directory. One way to program this is to use the ‘Number to Decimal String’ sub-VI in combination with ‘Concatenate Strings’. To find them, go to the block diagram, open the functions palette with a right-click and click on the drawing pin. Then you can locate them in the ‘String’ section. Use the while loop from the previous exercises, or make a new program to construct a piece of code that automatically creates numbered filenames, including the drive and directory, as in: ‘P:\data\measurement123.dat’. In one of the previous exercises you created an indicator to monitor the contents of an array (see above). This indicator was positioned outside the while loop, and only showed the content of the array after completion of the while loop.

8 Hover over the icon until an up/down pointing arrow appears, then click-and-drag, dragging downward. This will create extra inputs. 9 When you connect the source of the shift register before the sink, a broken wire will appear, since the content of the source is only determined by connecting the sink.

Figure 9: Array indicator.

Page 11: LabVIEW Manual 2009

11

Q.7 What happens when you connect an indicator to the output of the ‘Number to Decimal String’ sub-VI, and place the indicator inside the while loop? Describe what happens when you run the program (if necessary with execution highlighting). Q.8 Save the VI you made and include a copy of its block diagram in your report. Q.9 Usually file managing programs, such as Windows Explorer, order files on name by looking at the first digit they encounter in the filename, starting from the left. Therefore, in order to get a properly ordered list, you usually have to add zeroes to the number in the data filename. Extend you program to add a predefined number of zeroes to the number in the filename [E].

IEEE 488: GPIB Communications

Since you are now familiar with most of the basics of LabVIEW, you can now put LabVIEW to use where it is actually efficient to use: I/O. You will now see that LabVIEW can be used for communication with external devices and instruments. Apart from PCs, you will find special purpose electronic hardware in almost all experimental physics setups. These devices have knobs mostly, but being able to control these devices electronically can come in handy sometimes. Additionally, in some situations these special purpose devices actually gather your data (think of voltage or temperature readers), and transferring this data to your PC via a cable is more convenient than via a solid-state memory module, such as a CD or an SD card (which is actually present in the oscilloscope you are going to use). To connect external devices to a PC, there are several standard ports available on a PC (USB, Parallel/Serial Ports, FireWire). Some manufacturers choose to use their own communication protocol to communicate with the device via on of these ports, and write (proprietary) software for this, which they then supply with the device. However, more and more manufacturers choose to use standardized communication protocols to serve as the information channel between their device and a PC. Well-known examples of these standardized protocols are for example USB, Ethernet, WiFi and FireWire10. These worldwide standards are defined by the Institute of Electrical and Electronics Engineers (IEEE) organization. LabVIEW comes into this story as being a programming language that has a software library that allows you to implement and use many of the IEEE-protocols rather easily. The title of this section already shows which communication protocol you are going to use now: the IEEE 488 protocol, or GPIB. It is a rather old and slow protocol, but it is still quite common. The GPIB port is not available on PCs by default, so one has to a GPIB extension module for a PC (usually a PCI or PCI-e card, but there are also USB-to-GPIB converters) to use this protocol. Anyway this port is available on the PC you are working with. Check whether the Tabor Function generator is connected to your PC via the GPIB cable. If not, do so now. Open a blank VI and go to block diagram. Now you need sub-VIs with which you can communicate via the GPIB protocol. To find VIs in the library, LabVIEW also has search functionality. Go to the search of the functions palette11. In the search field, type ‘gpib’ (the search is not case sensitive). LabVIEW will find a list of GPIB commands for you. The one you need now is ‘GPIB Write’. Select it, and place it one the block diagram. Connect all the terminals with controls and indicators.

Be careful not to use the search all the time to find all the VIs you need. Using the search can be slower then simply memorizing where you can find VIs on the function palette. Moreover, in this

10 ‘Firewire’ refers to the port as well as to the communication protocol itself. 11 The magnifying glass.

Figure 10: GPIB cable.

Page 12: LabVIEW Manual 2009

12

functions palette of the block diagram the VIs with similar or related functionality are grouped together, and sometimes simply by browsing you find quite useful VIs there you did not know

existed. With the GPIB protocol you can hook up more than one machine on a single connector, so one needs to include a reference to the specific device you are sending a command to. This is the function of the ‘Address’; the address of the Tabor is set in the Tabor itself and equals 15 in this practicum. To communicate with the Tabor, you need to know which commands it understands (remember: the GPIB protocol only tells machines how to talk to each other, but not what to say). These commands can be found in the manual of the Tabor, on Table 4-5. This table is an additional sheet of paper often stapled into the official booklet. Note that once you have used the GPIB to set a function, the Tabor cannot be operated via its panel anymore. Press the ‘LCL’ button to activate the panel again.

Q.10 What are the commands to set the frequency, amplitude and type of waveform? Q.11 Find out how to change the address of the Tabor. You should be able to find this information in the manual. What is the exact procedure [E]?

Do not press ‘Enter’ after typing a command such as ‘FRQ500’ in the ‘String Control’ on your front panel. An ‘Enter’ is also a string constant, and will stay in the string control box, making

all subsequent commands invalid. One of the first things to check when you encounter a malfunction of your VI while it is running is the content of the string control. To run your VI just

click run or press Ctrl-R.

It is also possible to acquire information from the Tabor, for example the waveform amplitude. To get this information, you have to send a so-called query command. These commands can be found in the same table mentioned before. After you have sent this command, you can read what the Tabor is ‘saying’ by using the ‘GPIB Read’ sub-VI12. Note that you have to send a query command before you can read something on the GPIB bus. Moreover, after reading, the message will be deleted from the bus.

Q.12 With what command can you query the frequency or the amplitude? Do not use these commands yet, some more LabVIEW functionality is necessary to make this work properly.

Q.13 What text is displayed on the Tabor when you send an undefined command? What message is displayed when you specify a valid parameter (say the frequency) but out of range? Send the following string: STP1000; SWT10; FRQ1 – hook up a scope to the Tabor (see below) and describe what this particular command does.

Observing a changing amplitude or frequency on the display of the Tabor is one thing, but it would be nice if you can actually check the signal on the output BNC connector from the Tabor. To visualize this signal, normally one uses an oscilloscope. Connect the output of the Tabor to the oscilloscope (with a BNC cable) and check the signal that it produces, by sending different commands to it. The command strings are case sensitive, by the way. Note that the Tabor can produce signals with frequencies up to 20MHz. Try to create different waveforms with the Tabor via your PC, such as a linear and logarithmic sweep, a DC output, et cetera.

12 All the GPIB sub-VIs can also be found via the ‘Instrument I/O|GPIB’ section on the functions palette.

Page 13: LabVIEW Manual 2009

13

The oscilloscope has an auto-set button that you can use after you turned it on. This makes it easier to visualize your waveform for the first time. Try to learn how to use it without the

autoset button though – it does not always show you what you want to see.

Synthesizer

We can use the Tabor in combination with Labview and a loudspeaker to construct a synthesizer, be it a very modest one. To get there, there are a few Labview things to learn.

Sequence Structures

In using the GPIB commands, you have probably already noticed that the order in which you execute commands is sometimes essential. Usually LabVIEW executes code from left to right, but two separate pieces of code on the same block diagram might be executed virtually simultaneously, resulting in undesired or unpredictable behavior. To solve this issue, one can use a ‘Sequence Structure’ that forces a sequential execution of pieces of code. This structure comes in two types, their difference being only their appearance. In Figure 11 you see the ‘Flat Sequence Structure’, the other sequence structure is the ‘Stacked Sequence Structure’. The sequence structure can be useful to make an automated GPIB-query program that first sends the desired query command, and then reads the message on the GPIB bus immediately afterwards.

Q.14 Build such a VI and include its block diagram in your labjournal. If you encounter strange behavior, try reading the next section (not the next question) first. Q.15 If you use a stacked sequence, you cannot simply pass data from one frame to a subsequent frame by e.g. dragging a wire. What function is available on these stacked sequences to circumvent this?

Wait Statements

When you send a very long string over the GPIB bus, it might take a while before the whole string is received by the Tabor. This is due to the fact that the GPIB bus is slow (9600 Baud usually, where Baud means number of symbols per seconds). However, once LabVIEW has completed executing the ‘Write GPIB’-subVI itself, it will continue with the rest of the program, regardless of the fact that the GPIB controller may still be sending data. To compensate for the fact that LabVIEW is not always aware of when your hardware has finished the operations you ordered it to execute, you can use wait-statements manually, preferably in the

Figure 11: Flat sequence structure.

Figure 12: Two different 'wait' statements

Page 14: LabVIEW Manual 2009

14

sequence structure you just learned. There are two different wait statements: ‘Wait (ms)’ and ‘Wait Until Next ms Multiple’; Figure 12 shows how they look. The first one is used if you want your program to wait a certain amount of time at a specific location in the execution order of your program. Typically you place this sub-VI in a sequence, in order to enforce the proper moment of execution. The operation of the second timer is more complicated. In order to understand its behavior, you have to know that Labview has an internal clock, counting the number of milliseconds passed since some arbitrary starting point. The value of this clock is an integer (32 bit) and will count zero when it has reached 232. When you execute the ‘Wait Until Next ms Multiple’-sub-VI, with, say, 100 millisecond as input, the program will wait until this internal millisecond clock has reached a value that is an integer multiple of 100. Therefore, the first time you run this sub-VI, you never know how far you are from this number, and the first waiting time after calling this VI is therefore arbitrary, but bounded from above by the number you specified. This VI is however quite handy if you use it in a while loop for instance; it will make sure your while loop is executed at regular intervals. This can be useful for e.g. synchronization purposes.

Indexing The synthesizer you are going to make initially will be able to play a predefined number of tones with certain duration. By now you should roughly be able to see how this can be put together with a for-loop, the GPIB library, sequences and wait statements. There is however a feature of loops that can be quite helpful in this and other applications. This feature is called automatic indexing. Figure 13 shows an example; one can create similar functionality in while-loops. In this figure the basic functionality is that the for-loop automatically runs through all the elements in the array, making them individually (in the indicator in this case) available. The number of iterations in this code is equal to the length of the array.

Q.16 What happens when you connect two arrays of different length via indexing to a single for loop?

A simpler version of an array building technique discussed earlier is shown in Figure 14. Here, the indexing technique is used to create arrays automatically. This method is not as flexible as the one using the ‘build array’ sub-VI, since one cannot, for example, change the order of elements in the array. Another drawback is that the array that is being built up is not accessible inside the loop, so one cannot for example show its contents in a graph while the loop is being executed. Note that indexing is usually automatically applied on data lines crossing a loop boundary. If you do not want this to happen, it can be manually turned of via the menu that pops up after a right click on the square with the brackets inscribed.

Figure 13: Indexing in loops.

Figure 14: Build array with indexing.

Page 15: LabVIEW Manual 2009

15

A/D Conversion You will encounter the abbreviations ‘DAC’ and ‘ADC’ quite often in this manual. The abbreviations stand for Digital to Analog Converter and Analog to Digital Converter. They refer in most cases to the microchip that converts digital to analog signals, or vice versa. These microchips are of course essential for performing electronic measurements.

Q.17 To see that these converters are indeed microchips, look up the datasheet13 of one particular example of an A/D converter, the AD7248. Include a print of a small part of the datasheet in your labjournal.

Loudspeaker

The loudspeaker you will be using to produce sound is a 6Ω loudspeaker (in principle the impedance of the coil in the loudspeaker is frequency dependent), with a maximum power consumption of 10W. These numbers set a limit on the voltages you can use to modify the amplitudes of the sounds produced. Usually though the loudspeaker starts to behave non-ideally far below these upper limits. In any case, if you want to test your synthesizer (or any other piece of equipment!), start gently, with small amplitudes. The calculation you shall do below, will tell you what ‘gently’ actually means in this case.

Q.18 Derive what the maximum voltage is you can apply to the speaker, and what current then flows through the coils inside the speaker at that maximum. Once you know the upper limit of what the hardware can bear without breaking down, what would be a ‘gentle’ initial test voltage?

The Tabor can only produce a 50mA current, so it will not be able to drive the speaker directly (or only very softly). To amplify a current without modifying the voltage, you can use a ‘buffer amplifier’. This device simply consists of an electronic amplifier with an amplification factor of 1. It is only meant to beef up the amount of current you can supply, without changing the voltage. The amplifier itself is a so-called ‘active’ circuit element, requiring a power supply, so the power it funnels into the circuit can be larger than it gets from the circuit (for passive elements such as resistors or capacitors this is not true of course),. The circuit in this case is the 50mA current source. The buffer amplifier is a relatively large box with one bipolar input and one bipolar output; you will find it on your workbench.

Q.19 Now build a synthesizer with which you can play a certain amount of tones sequentially, whose frequency, amplitude and length can be modified via the front panel. Include the front panel and block diagram in your report. Don’t forget to save the VIs you build for your own reference; you might be able to use pieces of code to make now later on in the practicum.

PC Operated Frequency Sweep

With the string operators used in the previous section and a for-loop you can make a VI that will make the Tabor produce a frequency sweep of which you can set the start frequency and the stop frequency in LabVIEW. This functionality you have already seen in Q.13.

Q.20 Make this program. Make sure that the frequency steps are smaller than unity for a smoother updating of the waveform. Check the sweep with the oscilloscope, and the loudspeaker. Include the block diagram of this VI in your labjournal [E].

13 Datasheets are sometimes also called specsheets, where ‘spec’ comes from ‘specification’.

Page 16: LabVIEW Manual 2009

16

Q.21 Make a sweep with a sine wave that starts at 100 Hz, and stops at 0.001 Hz. Change the setting of the scope from ‘DC’ to ‘AC’. What do you observe[E]?

This effect is caused by the response of the internal high pass filter14 you switch on when to put the scope to AC. This setting is useful if you want to observe low amplitude Alternating Currents (AC) on a signal that also has a large Direct Current (DC) component.

Setting the wrong AC/DC input setting by mistake on the scope happens easily and often causes

confusion. Check this setting first in case you experience problems with the scope.

14 You should have seen high and low-pass filters in the first year practicum. You will learn more about them in the course called SVR. It might be useful to remember the sweep-function; you can use it to measure the transfer function of filters.

Page 17: LabVIEW Manual 2009

17

I/O Cards 15The functionalities built into the Tabor and the oscilloscope, namely digital to analog signal conversion and vice versa, respectively, can also be achieved by other hardware. This hardware is specifically designed to fit into your PC16, so-called input/output (I/O) board. Depending on the type, other functionality is usually also available on these boards: digital clocks (5V square wave generators), digital ports that can either sense or output digital signals, for example for TTL circuits. These cards17 can be bought at different manufacturers, but not all work equally well with LabVIEW. The card installed on your PC is the PCI-6014 from National Instruments.

Q.22 Download the datasheet from ni.com and write down what type of I/O functionality (inputs/outputs/speed etc.) is available on this card.

So why use an oscilloscope if you can use a more flexible I/O board? Why use a function generator if the same output can be achieved with a cheaper PCI card? There are advantages and disadvantages in both solutions: familiarity with the programming language is for example a strong boundary condition for using LabVIEW-based solutions. Flexibility in use usually also means hard to set up: you will see that programming a very basic function generator in LabVIEW takes quite some time and skill, while the Tabor works when you turn it on. Another consideration is hardware demands: to measure picoamperes or gigahertz signals, dedicated hardware is usually required; I/O boards that do that are simply not available. Let’s also not forget that all PCs run on complicated operating systems which are far more likely to stop functioning properly than a custom programmed microchip in e.g. a function generator. Yet another consideration is that a function generator might keep working for >20 years; hoping for full software and hardware compatibility guarantees for the duration of 20 years is a utopian dream. Typically, when your application is either very demanding or very simple, or when a quick solution is needed, dedicated hardware is the preferred piece of equipment. For a versatile basis of doing moderately intricate experiments, involving different pieces of hardware or which have to be tailored to specific demands that are too expensive or simply inexistent commercially, Labview can be an indispensable tool.

DAQmx Single Point Output An easy way to get used to the basics of I/O is to learn how to create a potential difference18 between an analog output port and the ground of the I/O card. The ingredients can be deducted

15 This part of the manual is an adaptation of the original course material ‘Data Acquisition Fundamentals’ by Sarah Finney, Arizona State University. 16 Although nowadays also USB-I/O ‘cards’ are available. 17 The words ‘card’ and ‘board’ are synonyms here and will be used interchangeably. 18 ‘to write a voltage’ in the text below refers to the same operation.

Figure 15: Single point write.

Page 18: LabVIEW Manual 2009

18

from the contents of the previous sentence: you will have to tell the computer which port you want to address, and how large the potential difference should be. This can be achieved by building the code depicted in Figure 15. The sub-VIs depicted there can be found in ‘Measurement I/O|DAQmx’. The ‘physical channel’ constant refers to Dev1, which is the 6014 card you have. The ‘1’ in this constant is equivalent to the address in the GPIB protocol; you could have more than one I/O card installed. ‘ao0’ refers to the AO0 BNC connector on the connector box. The settings in the purple boxes on your block diagram are not depicted – think about what you need for analog output (AO) and a single channel, single point output. Modify the content of the purple boxes by clicking on the inscribed triangle. Make sure you do not select the ‘Waveform’ option. This small program should be able to write a voltage to the AO0 BNC connector on the connector box. You can check whether this works with the scope.

DAQmx Multiple Point Output The program from Figure 15 can write the voltage to an output port only once. What if you want to output, say, a (discretized) sine wave? From what you have learned so far, you might expect the following solution to work:

If the ‘Sine Wave’ array contains a discretized sine wave, in fact this solution will work! This solution is however severely limited: remember that the clock in LabVIEW has only millisecond accuracy. That means that, theoretically, the for-loop cannot be accurately synchronized at a rate faster than 1000x per second. That means that the voltage on AO0 cannot be updated faster than 1000x per second19. This limits the frequency of your sine wave to 500Hz20; nothing compared to the 20MHz of the Tabor.

Q.23 Check the statement above by building the code from Figure 16, and using zero (0) for the ‘millisecond multiple’. Using a sine wave is not required; just make of a small array that contains voltage steps you can visualize on the scope. What is the maximum output rate of this code?

19 In practice the execution of the DAQmx sub-VIs takes a few milliseconds at least (depending on the computer hardware), which makes the code even slower. 20 The largest frequency component you can generate is fmax/2, where fmax is the output (or input!) writing (reading) frequency. This is the Nyquist theorem. You will learn more about this in the SVR course.

Figure 16: Finite multiple single points output

Page 19: LabVIEW Manual 2009

19

There is however a hardware clock present on the 6014 board that actually goes up to 20MHz21 (you might have seen that in the datasheet). This clock, along with some other hardware can be addressed with LabVIEW. Example code is depicted in Figure 17. To build this code, you have to select the ‘1Chan NSamp’-option from the purple box below the ‘DAQmx Write’ sub-VI. Again select the ‘DBL’-option. In addition to this modification, to specify the rate at which the content of the array is written to the output port (in Figure 16 this is done with the metronome sub-VI), you can use a DAQmx sub-VI that can configure the output rate. The ‘Staircase’-array should be a one dimensional array containing 10 numbers: 1,2,3,4,5,4,3,2,1,0. The ‘auto start’ setting in this figure (find it yourself!) has to be set to true.

Q.24 What do you observe on the scope when you run this VI?

Since the total duration of the waveform on the scope is 1ms, you might need to adjust the time base of the scope, and configure the trigger level properly. Remember what the trigger is? The

trigger sets the point where the scope starts plotting the voltage – you have to set at least the level and whether the scope needs to start when the voltage has a positive of negative slope at

that voltage. Q.25 Now decrease the ‘rate’ to 10. You should in theory observe the same waveform, but its completion should now take 1 second (adapt the time base of the scope accordingly). Do you still observe the same waveform? If not, what do you observe?

After completing the code, LabVIEW stops the scheduled task immediately, resetting all the hardware. In the code depicted in Figure 17, this happens irrespective of whether the hardware actually completed writing the full array to the analog output. In the DAQmx subsection of the function palette, in fact in the subsection where you found the other DAQmx sub-VIs, there is another sub-VI that solves this problem.

Q.26 What is the name of this sub-VI? Find it, include it in your code (where?), and check whether it actually works.

Have you already used the possibility to include comment in your code? The yellow boxes in

Figure 17 are just that. Double click on an empty piece of block diagram to make one.

21 The similarity with the 20MHz limit of the Tabor is most likely coincidental; the microelectronics used in both pieces of hardware is not fully disclosed.

Figure 17: Finite N points output.

Page 20: LabVIEW Manual 2009

20

Basic Plotting: Waveform Graph Visualizing the staircase waveform on the scope is a useful tool to check the behavior of your VI, but it would be convenient if you can plot simple graphs directly, inside LabVIEW. This option is indeed available: place a ‘Waveform Graph’ on the front panel and hook up the staircase array to it. Running the program will not show a staircase however. Right click on the control box at the top right corner of the graph display (with ‘Plot 0’ inscribed) to find a menu where you can change the appearance of the plot.

Q.27 Change the settings of the ‘Waveform Graph’ in such a way that you see both the actual datapoints, and a ‘real’ staircase. Print this graph and include it in your report.

Important remark on using the printer: In order to save the toner in the cartridge, make your graphs small. A convenient way of

copying and printing graphs from your VI front panel is using “Print Screen”. Paste the saved picture from a buffer into MSWord document window by pressing ‘Ctrl-V’. Adjust the picture

(crop, size) by using Word ‘Picture’ tools. You can put several pictures on a single page. Print the page via the printer on the 4th floor (studprn3).

Data Types: Clusters In order to transfer more than a single data type on a single wire, you can use the ‘Cluster’ data type. Apart from being optically neat, it can also be convenient to create special purpose ‘custom’ data types. One example of that is the ‘Error Cluster’ of which a connection can be found on most advanced sub-VIs you have used. Connecting these properly throughout your program is not required but can be really helpful when debugging your program. The error cluster contains a Boolean that is true whenever an error occurred, an integer as an error code, and a string constant for some basic error explanations. More extensive explanation of error numbers is available via ‘Help|Explain Error’ in the program menu. Usually that help also indicates where the error occurred.

Q.28 Which three types of cluster ‘bundling’ sub-VIs exits? Where can you find them?

DAQmx Continuous Output The output types encountered above are limited to the extent that one is limited to low output rates, or to the use of increasingly larger arrays to write data for longer periods at high rates. As an example: if you want to output a sine wave of changing amplitude at 20kHz for a few days, you would need around 108 data points in your array. To avoid working with these impractically large numbers, there is a way to write data to the analog output in a ‘streaming’ way. The technique employed is similar to the one used in Youtube video streams. Instead of directly streaming data from the server to your monitor, a virtual buffer is created, which is continuously filled with new videodata from the Youtube server. After a short delay, these data are also continuously written to the monitor. This method of data streaming can make the data stream to your monitor insensitive to small fluctuations of data influx from the server into the buffer, and that is precisely what is necessary: the video should run smoothly on your screen irrespective of (small) network interruptions. In the LabVIEW context one would say that LabVIEW cannot directly supply a DAC element at say 1MHz with data, but it can write bursts of data (say 1000 points) every millisecond or so quickly to a virtual buffer. If then the hardware on the card makes sure this buffer data in transferred at a constant rate of 1Mhz to the DAC (and from there to the output port), the effective, averaged influx and efflux of data to and from the buffer is 1 million data points per second: the buffer will never be empty, and it will also never be full! In Figure 18 you can see code that might give you the desired continuous output of an array. The little sub-VI with the word ‘status’ inscribed is a cluster unbundle VI that you have seen before, if

Page 21: LabVIEW Manual 2009

21

you answered Q.28. In fact building this VI will not give a ‘broken’ Run button. Running it however will result in an error and will stop the loop after one iteration.

Q.29 What is the problem? Find it out with the error cluster. In which iteration of the loop does it occur? How can you solve it? Q.30 If you use the staircase array described above as output array, and if you configure the trigger on the scope properly, you can find out what the slewrate of the DAC is. Is this in accordance with maximum output rate you found in the datasheet [E]?

Two useful notes on using LabVIEW: Ctrl-B erases all broken wires on your block diagram. In the ‘Edit’ menu you can find the option ‘Make all current values default’ – that setting saves the current settings for all input and output variables of the current VI, so you don’t have to insert

them again the next time you start LabVIEW.

You can also solve the problem you found in the code from Figure 18 also in a different way that reveals slightly more about the functioning of the DAQmx software-hardware interaction. In the DAQmx subsection of the function palette, there is a subVI called ‘DAQmx Start Task’, and obviously when the ‘auto start’ option on the DAQmx write sub-VI is turned off, this is the VI to use instead. The only minor difficulty is that you have to call this sub-VI only in the first iteration of the while loop. This can be done with LabVIEW functionality introduced in the next section.

Case Structure The switch-case statement in C++ has an equivalent in LabVIEW: the case statement. This functionality can be found in the subsection of the functions palette where the for- and while loop are located. By default it selects the case to apply on the basis of the value of the Boolean you wire into the box with the question mark inscribed, but you can modify the structure to work with integer ranges too. Examples ‘a’ and ‘b’ in Figure 19 therefore have the same functionality. Coincidentally in this figure you can immediately see how to implement the ‘DAQmx Start Task’ sub-VI.

Q.31

Figure 18: Continuous N points output.

Page 22: LabVIEW Manual 2009

22

What do you have to do to the ‘False’ or ‘≠0’-cases in order to make the case structure work?

A LabVIEW Function Generator

You should now be able to build your own LabVIEW function generator, with a similar or even more extensive functionality than the Tabor has.

Q.32 Make such a function generator, and print it’s block diagram. It should be able to give sine, triangle and square waves. Make sure the amplitude and phase can be modified easily from the front panel. Can you now ‘audualise’ a square- or triangle wave (be careful not to destroy the speaker with too large amplitudes)?

Note: there are sub-VIs that can generate arrays filled with sine, triangle and/or square wave signals. Find them by using the search. And again: save the VIs you make for future reference.

Q.33 You can customize and beautify the front panel to a large extent. Try to build a user-friendly interface for your function generator [E].

Please be aware of the fact that the rate at which you fill the buffer with data that are to be written should be, on average, equal to the rate at which these data are transferred to the DAC and written to the output port. If you are too slow writing samples, the card will start to write old samples to the DAC. If you are too fast, the card will not be able to generate the ‘waveforms’ you want it to generate. Note that you will be able to see that this happens by monitoring the error cluster. LabVIEW determines the size of the buffer automagically with the ‘samples per channel’ control on the ‘DAQmx Timing’ sub-VI. If you encounter problems with the buffer, you might want to do

that yourself; this is possible by using the ‘Buffer Property Node’. Do not however revert

Figure 19: Case structures.

Page 23: LabVIEW Manual 2009

23

immediately to this rather involved way of solving DAQmx problems before consulting one of the course assistants.

Page 24: LabVIEW Manual 2009

24

Single Point Input In the previous sections you have seen how to build your own function generator, the Tabor functionality so to speak. The functionality of the oscilloscope, in other words the input functionality, can also be implemented with by the 6014; it is an I/O card after all. Fortunately the software structure of data acquisition is very similar to that of data writing. It will not surprise you then that Figure 20 represents code that enables you to read a single voltage value on input port AI0. One important setting is the maximum input voltage the hardware can read; make sure you set it to +/- 5 or 10V. This input limitation can be set on the ‘DAQmx Create Virtual Channel’ sub-VI.

Multiple Point Input Knowing how finite N point writing works immediately tells you how to generalize the code above to finite N point data acquisition.

Q.34 Build this N-point data acquisition LabVIEW code, based on Figure 20. With this code you acquire a single buffer of size A at rate B. If the rate is low, the default timeout (10 seconds) setting on the ‘DAQmx Read’ sub-VI might be too small. Implement a solution to this problem. Include a print of your VI in your labjournal.

Continuous Input As is the case for writing data to an output, you cannot use the multiple point acquisition code for both long and fast data acquisition. You could insert the whole single- or multiple point acquisition code in a for- or while loop. Schematically that would create reading schemes as in Figure 21 a) and b). You can ‘see’ that these reading modes are slow and impose only limitedly strict timing on the acquisition. The constants N and tr in this figure can be set by the user.

Figure 20: Single point read.

Figure 21: Reading modes: a) single point acquisition, b) single buffer read, c) continuous read. N is the number of samples, ti is the time between two executions of the code, tr is the rate at which data is acquired.

Page 25: LabVIEW Manual 2009

25

Q.35 With which inputs on which sub-VIs can one control the two variables N and τr?

ti Depends on other factors you do not have explicit control over. Examples are the background processes running on the computer, and, in case you execute the single point acquisition or the single buffer read in a while loop, on the other things you execute in the while loop. Figure 22 is by far superior to the solutions mentioned above. Be aware however that it is not always necessary to implement continuous reading. If reading speeds are of the order of 100 Hz or slower, a while loop with single of finite N-point input will suffice and is far easier to implement, certainly in combination with the possibility to create your own sub-VI that will be introduced below.

Q.36 Build the code shown in Figure 22. What happens when you disconnect the ‘number of samples per channel’ on the ‘DAQmx Read’ sub-VI? Explain this by using the help, or even the advanced help. Q.37 You can also measure the voltage on two ports simultaneously: simply enter Dev1/ai0, Dev1/ai1 in the channel constant and modifying the ‘DAQmx Read’ sub-VI setting to ‘NChan NSamp’ will do the trick. What type of output from the read sub-VI does this generate?

Continuous Input: Details The continuous input code for you most likely contains some mysterious settings. One of them is probably the ‘input terminal configuration’. This nontrivial setting has to do with the fact that you usually (this depends on computer settings which sometimes get messed up) by default measure the potential difference between the input port and the ground of the I/O card, the Referenced Single Ended (RSE) setting. Now in some applications the ground of the I/O card (the reference) and the ground of the source of the voltage (e.g. a force sensor or light meter) you measure are only connected via some convoluted and remote ground loop. This loop will pick up the 50Hz electromagnetic field that permeates all modern living areas since it originates from power lines (in the US this would be 60Hz). You will see that as a 50 Hz ripple on your signal. Try to use a NRSE or differential measurement instead (they are identical for single input acquisition). If your measurement circuit is not properly connected, you can also end up measuring the potential difference across loose connectors, basically a ‘capacitor’ of fluctuating capacity and charge content: any sort of noise (spikes, drift) can be expected in that case.

In short: if you encounter 50Hz noise or intermittent noise with no obvious source, check the grounding wires and settings. Consult an assistant if you cannot solve the problem yourself, but

Figure 22: Continuous input.

Page 26: LabVIEW Manual 2009

26

sometimes grounding problems seem to defy logic; don’t be surprised if finding the source of the noise takes some time.

The other perhaps surprising thing is the location of the ‘DAQmx Start Task sub-VI’. In the DAQmx writing protocol, this sub-VI was optional in the first place (now it is required), but is was also executed after the ‘DAQmx Write sub-VI’. To explain the logic behind this change of order, take a look at Figure 23. If you follow the order in which the ‘write’-protocol is executed, you start at the top of the left stack at the LabVIEW code, where the value for output voltage is determined. After that has happened, this voltage value is transferred to the buffer by the ‘DAQmx Write’ sub-VI. After that, the digital value can be transferred to the DAC, where it is converted to an analog signal. The transfer to the DAC is initiated, roughly speaking, by the ‘DAQmx Start Task’ sub-VI. Then the reason for the reversal of the order of the ‘Start’ and ‘Read’ sub-VIs is obvious: since the ‘Start’ sub-VI operates between the ADC in this case and the buffer, this sub-VI has to be executed first, otherwise there is no data to be read from the buffer, which is what ‘DAQmx Read’ will try to do.

If every while loop iteration in the code from Figure 22 takes too much time to complete, you might be reading data from the buffer slower than the buffer is being filled up. This can result in data loss, and is undesirable. You can however observe that this happens (at high sample rates, say 100k, and a small ‘samples per channel setting’, e.g. 1) by creating an error indicator connected to the ‘DAQmx’ read sub-VI. Figure 19 even shows how to make sure the program stops working in case such an error (or any other error) occurs.

Q.38 Which error number occurs when you read too slowly? Which solutions are suggested?

You found out earlier in this practicum that the I/O card you are working with actually has 16 channels, and it might just happen that you want to read two independent signals simultaneously via the channels. This is possible with the VI you just made, and can be done by ‘Analog|Multiple Channels|Multiple Samples’ from the drop-down menu on the DAQmx read sub-VI. Currently this will not be necessary, but for Practicum 3 you might want to do just that.

Figure 23: LabVIEW I/O structure.

Page 27: LabVIEW Manual 2009

27

Automated Data Storage LabVIEW also enables you to store the numbers you measure in your experiment in a text file by using the sub-VI ‘File I/O|Write To Spreadsheet File’. This technique is usually an indispensible tool (whether you use LabVIEW or some other language), since permanent storage of measurement results allows for post processing and (re)interpretation of results. Storing (large amounts) of measurements results efficiently in such a way that they are still recoverable after a certain amount of time is an art (and also involves a proper use of your labjournal), and having some proficiency in it can make a real difference. Anyway, you can find this VI in the functions palette under the icon with the floppy (if you still know what that is). Note that this sub-VI requires a data type called ‘Path’ to know where to create the data file itself. This data type is introduced below. You can create a control for this input for now.

Q.39 If you write a one dimensional array with numbers to a file, will the ‘Write To Spreadsheet File’ sub-VI by default write this to a file as one long column with numbers, or as a long row? How can you modify this?

Data Types: Paths You have just seen the data type ‘Path’ being introduced. Earlier in this practicum you made a VI in which you concatenated different (sub) strings into one long string containing a full path. This string can be converted into a path with a standard sub-VI depicted in Figure 24. After this conversion it can be wired to the spreadsheet write (and read) sub-VIs.

Automation in data storage is, apart from being convenient, also useful to append references information consistently to data files. You can for example automatically append measurement

parameters (a date, temperature, et cetera) or a unique reference number to the name of the data file.

Q.40 Include the string to path conversion in the string-path creation program you made earlier. Print this in your report.

Check the 5V Voltage Source

The I/O card you have also features a 5V voltage source. With the continuous input program you have (check the input limits!), you can monitor whether this voltage actually is equal to 5V or whether it fluctuates a bit over time.

Figure 24: String/Array/Path conversions.

Page 28: LabVIEW Manual 2009

28

Q.41 Measure the 5V voltage source for at least 10 seconds at a sampling rate of 10kHz. Store the measurement data in a single, long column on your hard drive, and plot this data with Origin or Excel. Include this plot, with proper labels on the axis, in your report, together with a print of the block diagram of your program.

The default number of significant digits LabVIEW uses in writing numbers to a text file is three.

For Q.41 this might not be sufficient.

ADC Limitations The analog to digital converter on the I/O card has a limited resolution. You have probably seen in the datasheet that the card has a 16 bit ADC, but what does that mean? Check the ‘DAQmx Create Channel’ sub-VI in, say, Figure 22. That sub-VI has inputs for the minimum and maximum value that can measured on the configured input ports22. The total analog measurement range is then divided into 216-1 discrete bins. A voltage to be measured is then rounded off to the nearest bin delimiter; that will then be the digital value of the analog signal. That determines23 the resolution.

Q.42 Visualize the bit-levels by performing a continuous measurement, with the input and the ground shorted. Plotting the data on a ‘Waveform Graph’ that is acquired thus reveals the bit levels, and the Gaussian noise around zero. Print this plot, and include it in your report.

Custom Sub-VIs As with other programming languages, it can be useful to build your program from small ‘sub-programs’. This will make the eventual code neater, easier to debug, you can use the functionality from the sub-programs multiple times without copying the actual code, and you might even be able to re-use the sub-programs in other/future applications as well. If you are for example required to make a program that includes measuring, say, a temperature every 10 seconds, you might want to build the DAQmx structure into a single sub-program, or rather ‘sub-VI’ as it should be called of course.

The Temperature Converter

Open a new, blank, VI to make a sub-VI you can use later on in Practicum 2. This VI should be able to convert any temperature in Fahrenheit, Celsius or Kelvin to all these three different temperature standards. So it should be able to return the Celsius and Kelvin equivalents of 90F, but also the Celsius and Fahrenheit equivalents of 923K.

Q.43 Build this functionality. Note that this sub-VI should be able to accept any temperature standard as input, and regardless of the input also convert it into the remaining two. Include the block diagram of this program in your report.

The default values appearing in the controls and indicators when you open a program can be modified: fill in the desired default settings into the controls, go to ‘Edit|Make current values

default, and save your (sub-)VI.

22 It can change these limits by dynamically amplifying the ‘real’ input signal after which the amplification factor is divided out again. 23 Naturally if you set the limits to 1nV, the ADC won’t be able to measure a pV; there is a natural noise floor for this ADC (you can find that in the datasheet too). In typical LabVIEW applications though, you will not encounter this hardware limitation.

Page 29: LabVIEW Manual 2009

29

The program you have made should have at least two (temperature and type), but possibly three inputs and at least two outputs, possibly three. This program can now be made into a sub-VI. To do so, you have to define what the in- and outputs are of this sub-VI. This can be done on the front panel: right-click on the icon in the upper-right corner of the front panel-window, and select ‘Show Connector’. You will probably see something like Figure 25.

Now all these little squares and rectangles can become in- and outputs, but now there are too many of them. In order to get a connection scheme with the desired amount of in- and outputs, again right-click on this connector-scheme, and go to ‘Patterns’ and select the appropriate connection scheme. The convention with these connectors is that you connect24 the inputs to the left, and the outputs to the right, since LabVIEW operates code from left to right.

Using Custom Sub-VIs To use the custom sub-VI you just made, open a blank VI with Ctrl-N and choose ‘Select a VI’ from the functions palette. Now open the VI you just made. It will appear as an icon with an in- and output on the block diagram. Create controls and indicators for your custom sub-VI, and test it.

Data Types: Waveforms A data type you will have encountered already but most certainly will encounter in the near future is the ‘Waveform’. A ‘Waveform’ is actually a cluster in which a signal (e.g. measurement data) in an array is accompanied by timing information25. This timing information consists of the time step between two elements of the array, in other words, the inverse sample rate. It also includes the precise starting moment (with day, month and year) of the signal in the array. The ‘Waveform’ data type is important enough to have its own subsection on the functions palette.

Measurement & Automation Explorer On the desktop of your PC you should be able to find the icon depicted in Figure 26. This program allows you to check the available hardware on your PC, and run some diagnostic tests on it. Run this explorer, and expand the ‘My Sytem|Devices and Interfaces|NI-DAQmx devices’ section. Here you should click on the NI PCI-6014: “Dev1”. Open the ‘Test Panels’ and select the ‘Analog Input’ tab.

24 Hover over a connector, and click on it with the bobbin. The connector will become black, and the pointer will remain a bobbin. Click with this bobbin on the control or indicator in your front panel you want to connect the terminal to, and you will see that the rectangle assumes the color of this control. 25 It can also include information in ‘Attributes’, but that is beyond the scope of this manual.

Figure 25: Default connection pattern.

Figure 26: Measurement & automation explorer.

Page 30: LabVIEW Manual 2009

30

Q.44 Can you explain which reading modes are available under ‘Mode’ [E]?

Property Node The looks and settings of objects on the front panel can be customized, even during the running of the program. To do this one needs to create a ’Property Node’ for the object one would like to customize. This can be done in the block diagram by right-clicking on the icon representing the object to be customized. You can select the property to be changed in ‘Create|Property Node’. Note that this affects mostly the “looks” of your program, and is seldom necessary to change functionality.

RS232 Communication Suppose now that you want to measure a signal that contains relevant frequency components of up to 10 MHz. The I/O card you have cannot measure these frequency components, since its maximum sample rate is 200 kHz. The solution in this case can consist of using the Tektronix oscilloscope. This scope (as most of its more modern relatives) features an extension module via which it can communicate with a PC. Although nowadays USB connections become more and more standard, the RS232 connection you find on the back of the scope can still be found on many devices. The connector (the 9-pin sub-D connector) is still available on much equipment, and most PC motherboards feature this communication port as well.

Q.45 Try to figure out how to communicate with the scope over the RS232 port. Hook it directly to the Tabor and try to measure a sine wave with a frequency of 1 MHz automatically [E].

Page 31: LabVIEW Manual 2009

31

Practicum 2

Introduction The goal of this experiment is to build a LabVIEW-driven temperature control system, which regulates the temperature of a small block of copper. The electronic parts of the system are sketched in Figure 27, where the small block of copper is incorporated in the heater in the lower right-hand corner. The complete system uses a temperature sensitive NTC resistor as a temperature sensor, a simple heating resistor as a heater and a combination of ADC & DAC & PC for the electronic feedback.

Theory Figure 28 presents a very simple model for the thermal management in the system (copper block). Energy can be fed into the system with a heating resistor that generates a heating power P [W]. Energy leaks out of the system through thermal contact between the system and the environment (thermal bath). Two parameters determine the temperature dynamics of this system: (i) the system’s heat capacity C [J/K], which quantifies the thermal energy increase per Kelvin, and (ii) the thermal conductivity κ [W/K] between the system and its environment, which quantifies the energy leak between system and bath per Kelvin temperature difference. With these parameters in mind it is relatively easy to write down the time evolution of the system’s temperature as

where T0 is the temperature of the environment (thermal bath).

I

PC

DAC

NTCCu

HEATER

( ),0TTPdtdTC −−= κ

Equation 1

Figure 27: Experimental setup: DAC - Digital-to-Analog Converter, I - Buffer Amplifier, ADC - Analog-to-Digital Converter, Cu - Copper Block, NTC - Negative Temperature Coefficient Resistor (temprature sensor).

Page 32: LabVIEW Manual 2009

32

At constant heating power P the solution of this differential equation is found as

where TEQ = T0 + P/κ is the equilibrium temperature (at t -› ∞) and ΔT = T0 − TEQ, τ = C/κ is the thermal time constant. The temperature dynamics of this system is quite simple: the equilibrium temperature TEQ of the system is P/κ higher than that of the environment (T0) and the relaxation of the system to any new equilibrium temperature is exponential with a time constant τ.

Q.46 Verify that Equation 2 solves Equation 1 and the expressions for TEQ and τ are correct and have proper dimensions.

In practice the system might of course deviate from this simple system in several ways. The temperature might not be completely uniform over the system and there will probably be some time delay between the application of a heating pulse at one end of the system, and the temperature rise observed with a sensor at the other end. The thermal contact between the system and its environment might be more complicated then sketched in the model, which assumes that the bath remains at a fixed temperature and must therefore be infinitely large. As a practical example of the latter complication we note that the large white plastic box which supports the copper system, might also heat up. In principle, one can model the temperature of this white plastic box in a similar way, introducing a second heat capacity and thermal conductivity (now between plastic block and larger environment). This type of modelling, however, goes way beyond present needs. The point here is to develop a feedback/control circuit that, regardless of subtleties, keeps the temperature constant.

Basic Digital Feedback Mechanisms Feedback is a process whereby some proportion of the output signal of a system is passed (fed back) to the input. Often this is done intentionally, in order to control the dynamic behavior of the system. The importance of the feedback in our daily life can be illustrated by a vital example — a man driving a car to some destination. Without a feedback system, provided by the man’s eyes and his

( )τtTTtT EQ −Δ+= exp)(Equation 2

Figure 28: Temperature dynamics of a simple system.

Page 33: LabVIEW Manual 2009

33

brain, the result would be disastrous: it’s almost impossible to predict uncontrollable external influences like pedestrians, other cars, traffic lights etc. before the trip in order to overpass them. The eyes as a comparator and the brain as a processor provide an indispensable feedback assisting a successful arrival. Feedback can called positive or negative; this depends on the sign of the response to the feedback. Positive feedback increases the quantity measured in the feedback loop. The basic idea of any electronic feedback system is the following. Suppose you want to control a temperature T(t) and keep it at some fixed set-point TS. The first step is to compare these temperatures and calculate the error signal e(t) = T(t)−TS. The second step is to choose an algorithm, the details of which are given below, that uses this time-dependent error temperature e(t) to calculate the amount or feedback y(t) needed for quick reduction of the error voltage to zero. The third and the last step is to apply this feedback under the usual assumption that the system responds linearly to this control via dT(t)/dt = −y(t).

Q.47 What type of the feedback will you use in the experiment — positive or negative?

Systems which include feedback are prone to hunting, which is oscillation of output resulting from improperly tuned inputs. If the input changes faster than the system can respond to it, the negative feedback signal begins to act as positive feedback, causing the output to oscillate. To avoid such problems, a wide range of feedback algorithms has been developed:

Proportional Feedback

P-control Proportional feedback handles the present state of the system. The feedback signal y(t) is linearly proportional to the error signal at every moment, with a dimensionless coefficient KP :

For our specific case the feedback signal is the power P(t), which we apply to our system:

Here κ is the thermal conductivity, necessary to get the units correct. The main advantage of proportional or P-control feedback is its simplicity. The main disadvantage is that this type of feedback can never reduce the error signal to exactly zero.

Q.48 Why not? Hint: solve Equation 1 assuming, that the heating power P changes linearly with temperature (Equation 4). You can then reduce the acquired equation to the already known one (Equation 1) via redefinition of some constants.

One can of course make the residual error signal smaller by increasing the proportionality constant KP, but if you increase it too much the control system will become unstable and start to oscillate. The main reason for this behavior is the presence of unavoidable time delays between the temperature measurement and the heating response at that same position.

Integrating Feedback

I-control This feedback handles the past of the system and the feedback signal depends not only on the instantaneous error, but also on the past error values. The error is integrated (or averaged/summed) over a period of time, and then multiplied by a constant KI:

( ) ( )teKty Pp =

Equation 3

( ) ( )( )SP TtTKtP −−= κEquation 4

Page 34: LabVIEW Manual 2009

34

The expression for heating power P(t) can then be given in a form of:

The main advantage of integrating feedback is that it has a memory of past perturbations and in principle controls the system convergence to zero error signal.

Q.49 Why? Hint: Equation 1 with the heating power of a form Equation 6 can be reduced to a second order differential equation for which it can be shown that its solution (T(t) − TS) approaches zero when t −› ∞).

This memory is at the same time a disadvantage, as it reduces the control speed; the low-frequency fluctuations are much better controlled than the high-frequency ones.

Differential Feedback

D-control

This type of feedback handles the future, the first derivative of the error (its rate of change) is calculated with respect to time, and multiplied by a constant KD. The differential term yD(t) increases the feedback strength of high-frequency fluctuations and it makes the control more susceptible to noise:

Which is equivalent to the following discrete representation of the time-derivative less sensitive

( )ite to noise:

Combined feedback mechanisms Proportional & Integrating Feedback

PI-control This is a very popular control algorithm, which uses the combination of P- and I-controls:

( ) ( ).''0

∑∫ ==i

iI

t

tII teKdtteKy

Equation 5

( ) ( )[ ] ( )[ ].''0

∑∫ −−=−−=i

SiI

t

tSI TtTKdtTtTKtP κκ

Equation 6

( )dt

tdeKy DD =

Equation 7

( ) ( ) ( )[ ] ( ) ( ) ( ) ( )[ ] 633 3211 −−−− −−+=−= iiiiDiiDiD teteteteKteteKtyEquation 8

( ) ( ) '.'0

dtteKteKyt

tIPPI ∫+=

Equation 9

Page 35: LabVIEW Manual 2009

35

It combines the response speed of proportional feedback while its error signal does decay to is zero. There is another (more physical) parameter to quantify the relative strength of the integrating feedback (KI) as compared to the proportional feedback (KP). This parameter is called the “effective integration time” ∆tI = (KP/KI) and it equals the time it takes the integrating control to build up to the same strength as the proportional control (at fixed error signal). In terms of this parameter the PI feedback is:

It’s important to note that the “strength of the integrating feedback” is not only proportional to KI, but is also inversely proportional to the sampling time ΔtS. More sample points per unit time will increase the integrating feedback yI(t). Being applied to our system the expression for PI feedback power is then:

where the thermal conductivity κ is incorporated into KP . You will use Equation 11 as a basis for our feedback scheme. However feel free to make your VI more advanced and use PID-control, which will be discussed below. Proportional, Integrating & Differential Feedback

PID-control PID control is the most advanced algorithm, combining all the tree controls we have considered:

Figure 29 shows the typical time traces of three controlled systems and summarizes their differences. For P control the equilibrium does not correspond to the set-point. In theory, the evolution towards this equilibrium should be a simple exponential decay. In practice some overshoot can occur due to time delays between sensor read-out and actuator response. PI control is better in the sense that the equilibrium does correspond to the set-point. Theoretically, this equilibrium is reached after a damped (or possibly overdamped) harmonic oscillation. PID controls can potentially be faster, albeit somewhat more noisy.

( ) ( ) .'1

0⎟⎟⎠

⎞⎜⎜⎝

Δ+= ∫ dtte

tteKy

t

tIPPI

Equation 10

TTS

t

TTS

t

PTS

Figure 29: Typical time traces for real P, PI and PID controls. TS is the set-point temperature.

( ) ( ) ( ) .'0

dttdeKdtteKteKy D

t

tIPPI ++= ∫

Equation 12

( ) ( )[ ] ( ) ,0

⎟⎟⎠

⎞⎜⎜⎝

⎛−

ΔΔ

+−−= ∑=

t

tS

I

SSP TtT

tt

TtTKtP

Equation 11

Page 36: LabVIEW Manual 2009

36

The Physics of NTC Resistors How can you measure a temperature electronically? The temperature sensor you will be using is a so-called NTC resistor, where NTC stands for Negative Temperature Coefficient and refers to the fact that the resistance of such a device depends on its temperature, the relation having a negative coefficient; the resistance drops as the temperature increases. This decrease is quite rapid (the resistance decreases typically by as much as 4% per degree Centigrade), making these sensors ideal for accurate temperature measurements. An NTC resistor is nothing more than a piece of semiconductor material with a bandgap that is small enough to allow for thermal excitation of some of the electron from the valence band to the conduction band, or (equivalently) for the thermal excitation of electron-hole pairs. When the temperature rises, the number of thermally excited electron-hole pairs will increase and the resistance goes down, thus explaining the name NTC. The conductivity of a semiconductor (proportional to the number of electrons in the conduction band) follows an exponential law: γ= γ0 exp(−ΔW/2kBT), where ΔW is the band-gap energy, kB = 1.38×10−23 J/K is the Boltzman constant, and T is the temperature (in Kelvins), respectively. The resistance therefore follows an inverse dependence and you can write RNTC as in Equation 13:

where TC is related to the band-gap energy ΔW and R0 is the resistance at some reference temperature T0. Our NTC resistors are specified for TC = (3528 ± 18)K and R0 = 1.0k at T0 = 25oC.

T, C R, Om

15 1508,4

20 1223,9

25 1000,0

30 822,5

35 680,9

40 567,0

45 474,9

50 400,0

55 338,6

60 288,1

65 246,310 20 30 40 50 60 70100

200

300

400

500

600

700

800

900

1000

1100

1200

1300

1400

1500

1600

R, Om

T, OC 70 211,6

R,

Figure 30: NTC resistance versus temperature.

⎟⎟⎠

⎞⎜⎜⎝

⎛−=⎟

⎠⎞

⎜⎝⎛=

00 expexp

TT

TTR

TTCR CCC

NTC

Equation 13

Page 37: LabVIEW Manual 2009

37

Based on these values you can calculate a reference table for NTC resistance versus temperature, and plot the exponentially decaying function. These two are shown in Figure 30. In the experiment, the NTC resistance RNTC (and the associated temperature T) can be determined from the voltage over the NTC resistor, measured by a PC trough an ADC converter. The NTC resistor is plugged into the circuit, consisting of a fixed resistor R1 = 1kΩ and a 5V power supply from an I/O card.

Q.50 Derive the expressions for the voltage UNTC on the NTC resistor versus its temperature T and vice versa, i.e. T(UNTC). Hint: use the expression Equation 13 for NTC resistance versus its temperature R(T), consider the Ohm’s law for circuit on Figure 31 and find the voltage drop UNTC on the NTC resistor. Write the derived formulas in your Lab Journal. These conversion formulas will be necessary while building up the VI in LabVIEW.

The Heating Device As heating device we use a simple high-power resistor (RH ≈ 22Ω at room temperature) that is driven directly from DAC via the buffer amplifier (up to 1A in the voltage range of ±10 V). Such a buffer amplifier is needed because the DAC, just like the Tabor you have seen before, cannot supply more than 5 mA of output current. The dissipated power is equal to PH = (UDAC)2/RH. At the maximum DAC output of 10 V about 4.55 W is dissipated. The quadratic relation between the dissipated power PH and the regulating voltage UDAC has, of course, consequences for the regulating feedback loop that you want to construct.

R1 = 1 kOm

NTCRV

5VPC ADC

Figure 31: NTC resistor connection.

Page 38: LabVIEW Manual 2009

38

Experiment

Precautions

It is important to make sure that the system (Heater + Cu block + NTC resistor) is not overheated and thus damaged. Overheating can occur when, for example, a nonzero voltage is sent to the heater and the code (your VI) crashes — the heater keeps going then. Check that the Cu block doesn’t get too hot and include the overheating protection into your VI. The maximum temperature for the system is 550C. If you are not sure of what you are doing, hook up the output of the DAC to a scope to monitor the voltage directly. Calculate the maximum voltage on the the NTC then for a double safety measure.

Hardware

The experimental setup (Figure 32) consists of the following elements: • Connection Box, comprising DAC output, ADC input and +5V power source. • Current (buffer) amplifier with banana-type “In-Out” sockets. • Heater + Cu block + NTC resistor and fixed 1k resistor R1 (see Figure 31), assembled in a

single box. • PC, plugged to Connection Box, with LabVIEW installed.

Connect the output of the DAC (AO0 — Analog Output 0) to the input of the buffer amplifier keeping in mind the polarity — the banana plug ground should be connected to the black socket. Set the DAC AO0 voltage to 0 volts — you don’t want to start heating immediately. The output of

Connection Box(ADC & DAC)

to PC

In / OutGround

Out

InCurrent

amplifier

Heater

ADC +5V DAC

R1

CuNTC

+5VoooAI0 AO0

RED

BLACK

Figure 32: a) Connection scheme; b) BNC-to-banana adaptor connection: ground should be plugged into a black socket.

Page 39: LabVIEW Manual 2009

39

the buffer amplifier is connected to the heater input. Connect the NTC resistor output to the AI0 (Analog Input 0) on the Connection Box. Finally, connect the +5V output from the Connection Box to the NTC resistor circuit (BNC input on the box).

Compare your connections carefully with those depicted on the Figure 32, don’t mix up the +5V input with NTC resistor output — the NTC can easily be burned. Show your setup to an assistant

before plugging +5V to the circuit.

Thermal Response Time

Before building your VI you have to know what sort of timescales you expect in the temperature dynamics: this timescale determines what type of DAQmx measurement system (continuous, single point, et cetera) you can or must use. What you have to estimate is the sampling time ∆tS. Make a reasonable guess for the sampling time based on how quickly you expect the system to heat up under maximum heating26. You can actually check the thermal time response of the system. For this purpose you have to monitor the temperature over an extended period of time (say 20-25 minutes), and you have to be able to plot the change in temperature afterwards. You must monitor the temperature excursion under three consecutive conditions.

• Monitor room temperature T0: heater OFF (~1 minute). • Measure speed of heating up: heater ON at constant voltage (set it to heat at 5V) (~10

minutes). Wait until the temperature stops noticeably increasing, i.e. until T ~ TEQ. • Measure speed of cooling down: heater OFF again (system cools down) (~10 minutes).

The system should settle at a constant value below the maximum temperature; if not set the

heating voltage lower to say 4V.

Software

Now write a VI that monitors the voltage UNTC (t) and corresponding temperature T(t) over the NTC. You can use an ‘Expression Node’ to implement your conversion formula between the voltage and temperature. Put four digital controls on the front panel to set up the:

• sampling rate (1/∆tS). • set-point (required) temperature TS. • strength KP of the proportional feedback term. • the effective integration time ΔtI.

In order to preserve the “Heater + Cu + NTC” assembly from overheating (and possible breakage) while the VI doesn’t run, add a special control to your VI, which stops your VI via button on the front panel, preliminarily setting the heating DAC voltage to zero. Derive the instantaneous error temperature e(ti) = [T(ti)−TS], by subtracting TS from the measured NTC. With these ingredients you are ready to write the PI control that calculates the required heating power P(t) with this error temperature, in combination with the feedback parameters KP and ΔtI. A few points tips and points of concern:

• Realize the program with single point input first – you can always make it better later. • Since feedback is of course not necessary for the thermal response time measurements,

first make a program that allows you to check the thermal response time. Only then add

26 You should estimate this by calculating how fast the copper element would heat up if it did not loose heat to the environment; look up the heat capacity of copper and estimate the total volume of the copper element. An order-of-magnitude estimate will suffice here.

Page 40: LabVIEW Manual 2009

40

the feedback – breaking up the development of your code in this way makes building it easier.

• The calculation of the heating power involves quite some constants. It is convenient to do this calculation in a ‘Formula Node’.

• If you try to write more then the maximum output voltage to an output port, the DAQmx sub-VIs will return an error. Include this restriction in your VI.

• Note that negative voltages will also heat up your system! Active cooling is impossible in this system27

• You might want to monitor the heating voltage, temperature and other variables directly, and while you are measuring, in a graph. If so, make sure you call a ‘Waveform Graph’ you use to plot data from inside the while loop.

• It might be convenient to start using the automatic data storage capabilities in LabVIEW; you will need to analyze measured data after the actual acquisition has taken place.

Does the system heat up and cool down exponentially with time? If so, what is thermal response time of your system? Using the acquired time traces of the system dynamics (temperature) and measured values of T0 and TEQ to determine the system thermal time constants for heating-up (τ+) and cooling-down (τ−). You can do that by determining when the difference temperature (∆T) increases/drops by factor e (Equation 2), or, when you have access to the data via Origin, by fitting. Knowing these two time constants, do they compare well to the time constant you estimated before?

Temperature control with PI feedback By now you have a PI control system that can control the temperature of the copper element. It is now time to optimize the values of the two free parameters in the theory. Optimization of the feedback parameters Optimization of the feedback parameters of a PI control requires some skill. A standard trick to find the limitations of system & control is to search for the feedback constant KP = KO at which the temperature of the system just starts an undamped oscillation under proportional feedback only (KI = 0 or ∆tI = ∞). As a rule of thumb, the optimum parameters for stable PI control are now roughly KP ≈ KO/2 for the proportional term. ΔtI Can be determined from the oscillation period of the unstable system you just found at KO. Include several temperature measurements over several oscillation cycles, recorded at different Kp, and indicate which Kp is the best. Optimize the control system, with the protocol described above. Include time traces in your labjournal of the temperature excursion for a few different KP. Determine the optimum value for PI control KO from these data and mention what criteria you used to select this value. Check how well the optimized feedback scheme controls the temperature and protects it from external influences like air currents (e.g. blowing). Perturb the system, record a time trace and include it in the labjournal. If you still have time left, dress up the temperature control in any way you find suited. Choose one, some or all from the following list:

• Include differential feedback to make it a PID instead of a PI control. In principle, this could speed up the control, but also makes it noisier.

• Include averaging: measure much faster than the thermal response time and average the measured temperatures to obtain a more accurate signal.

27 Unless you get a Peltier cooler!

Page 41: LabVIEW Manual 2009

41

• You might have measured the actual value of the 5V line used in the NTC circuit: the 5V drifts and is actually not 5V. This affects the temperature reading. You can correct for this when you measure the 5V signal too.

• The most elegant, final extension is to let the algorithm optimize its own feedback constants. Such an “intelligent control” works by probing the system’s dynamics during the heating and cooling trajectories and uses the obtained information to optimize the feedback parameters KP and ΔtI (and possibly even KD).

Hats off if you can finish three out of four items from the list above!

References

• I.M. Horowitz, Synthesis of feedback systems, Academic Press Inc., 1963 • Wikipedia (the free encyclopedia), http://en.wikipedia.org/wiki/Feedback • LabVIEW PID Control Toolkit for Windows, ni.com.

Page 42: LabVIEW Manual 2009

42

Practicum 3 In this practicum you are supposed to write and implement LabVIEW code in an ‘experiment’ you design yourself. Your experiment should meet the following boundary conditions:

• You can use the hardware that is available in the practicum room. If you have an idea for an experiment that requires more hardware, feel free to ask for it.

• You should at least use three afternoon sessions. More is optional, but can increase your mark.

• You should have used the LabVIEW capabilities to communicate with external hardware (e.g.: GPIB, DAQ, et cetera).

• Naturally you will keep a labjournal. We have at least the following hardware available. Again: if you think you need something else, just ask for it.

• Light sources: LEDs/lasers • Stepper motor • Microphones • Photodetectors • Line scanners • USB camera • Speakers • Optics: mirrors/lenses • Force sensors

Examples of ‘experiments’ you can do are:

• Set up a communication channel between two PCs with a light source and a photodetector.

• Measure, analyse, and modify sound spectra. • Make use of a USB/Firewire camera to do some simple experiments. • Play ‘Pong’ on the scope via analog I/O.

You are encouraged to come up with ideas for experiments yourself.

Page 43: LabVIEW Manual 2009

43

Page 44: LabVIEW Manual 2009

7NATIONAL

INSTRUMENTS°

LabVIEW'" Quick Reference Card

LabVIEW Documentation Resources

Context HelpWhen you move the cursor over LabVIEW objects, the Context Help windowdisplays basic information about each object . Select Help»Show ContextHelp to display the Context Help window .

LabVIEW HelpIncludes information about LabVIEW programming concepts, step-by-stepinstructions for using LabVIEW, and reference information about LabVIEW VIs,functions, palettes, menus, and tools . Access the LabVIEW Help by selectingHelp»Search the LabVIEW Help .

LabVIEW Examples

LabVIEW searches among hundreds of example VIs you can use andincorporate into VIs that you create . You can modify an example VI tofit an application, or you can copy and paste from one or more examplesinto a VI that you create . Browse or search the example Vis by selectingHelp»Find Examples.You also can right-click a VI or function on theblock diagram or on a pinned palette and select Examples from theshortcut menu to display a help topic with links to examples for thatVI or function .

LabVIEW Web Resources

Includes a list of links to online National Instruments resources . SelectHelp»Web Resources to access the LabVIEW resources at ni .com.Resources available to you include the following :

Products and Services•

Upgrades- Training courses•

Seminars and user groups

Solutions•

Industry solutions•

Customer solutions

ni .com/Iabviewzone

SupportLabVIEW support

- Product documentation

NI Developer Zone- Discussion forums- Example VIs

Page 45: LabVIEW Manual 2009

Keyboard Shortcuts

I After initiating a search by typing in the VI Hierarchy window

Note The <Ctrl> key in these shortcuts corresponds to the (Mac OS) <Option> or <Command> key or (Linux) <Alt> key .

n i .com/labviewzone

You also can access this list of keyboard shortcuts in the LabVIEW Help .

Objects and MovementShift-click

Selects multiple objects ; adds object to current selection .T1~- (arrow keys)

Moves selected objects one pixel at a time .Shift-T1->*-

Moves selected objects several pixels at a time .Shift-click (drag)

Moves selected objects in one axis .

Ctrl-click (drag)

Duplicates selected object .Ctrl-Shift-click (drag)

Duplicates selected object and moves it in one axis .

Shift-resize

Resizes selected object while maintaining aspect ratio .Ctrl-resize

Resizes selected object while maintaining center point .

Ctrl-drag a rectangle

Inserts more working space on the front panel or block diagram .

Ctrl-A

Selects all items on the front panel or block diagram .Ctrl-Shift-A

Performs last alignment operation on objects .Ctrl-D

Performs last distribution operation on objects .

Double-click open space

Places a free label on the front panel or block diagram if automatic tool selection is enabled .

Ctrl-mouse wheel

Scrolls through subdiagrams of a Case, Event, or Stacked Sequence structure .

Navigating Front Panels Debuggingand Block Diagrams Ctrl-r.

Steps into node .Ctrl-E Displays block diagram or front panel . Ctrl--+

Steps over node .Ctrl-# Enables or disables grid alignment . Ctrl-T

Steps out of node .On French keyboards, press the<Ctrl-"> keys . (Mac OS) Press the<Command-*> keys .

Ctrl-/ Maximizes and restores window . File OperationsCtrl-T Tiles front panel and block diagram Ctrl-N Creates a new VI .

windows . Ctrl-O Opens an existing VI .Ctrl-F Finds objects or text . Ctrl-W Closes the VI .Ctrl-G Searches Vis for next instance of object Ctrl-S Saves the VI .

or text. Ctrl-P Prints the window .Ctrl-Shift-G Searches Vis for previous instance of Ctrl-Q Quits LabVIEW .

object or text .Ctrl-Shift-F Displays the Search Results window .Ctrl-Tab Cycles through LabVIEW windows .Ctrl-Shift-Tab Cycles the opposite direction through Basic Editing

LabVIEW windows . Ctrl-Z Undoes last action .Ctrl-Shift-N Displays the Navigation window. Ctrl-Shift-Z Redoes last action .Ctrl-l Displays the VI Properties dialog box . Ctrl-X Cuts an object .

Ctrl-C Copies an object .Ctrl-L Displays the Error list window .Ctrl-V Pastes an object .

Ctrl-Y Displays the History window .

HelpNavigating theVI Hierarchy Window Ctrl-H Displays the Context Help window.

Ctrl-Shift-L Locks the Context Help window .Ctrl-D Redraws the window . Ctrl-? or F1 Displays the LabVIEW Help.Ctrl-A Shows all Vls in the window .Ctrl-click VI Displays the subVls and other nodes that

make up the VI you select in the window .Enter t Finds the next node that matches the

search string .Shift-Enter I Finds the previous node that matches the

search string .

Page 46: LabVIEW Manual 2009

Tools and Palettes

t If automatic tool selection is disabled

SubVlsDouble-click

Displays subVl front panel .subVl

Ctrl-double-click Displays subVl block diagram and frontsubVl

panel .

Drag VI icon to

Places that VI as a subVl on theblock diagram

block diagram .

Shift-drag VI

Places that VI as a subVl on theicon to block

block diagram with constantsdiagram

wired for controls that havenon-default values .

Ctrl-right-click

Opens front panel of that VI .block diagramand select VIfrom palette

ExecutionCtrl-R

Runs the VI .Ctrl- . t

Stops the VI .Ctrl-M

Changes to run or edit mode .Ctrl-Run button Recompiles the current VI .Ctrl-Shift-Run

Recompiles all Vls in memory .button

CtrI-, t

Moves key focus inside an array orcluster.

Ctrl-T t

Moves key focus outside an arrayor cluster.

Tab t

Navigates the controls or indicatorsaccording to tabbing order.

Shift-Tab t

Navigates backward through thecontrols or indicators .

t While the VI is running

Wiring

TextDouble-clickTriple-clickCtrl-->Ctrl--Home

EndCtrl-HomeCtrl-EndShift-Enter

EscCtrl-EnterCtrlCtrl--Ctrl-0Ctrl-1 tCtrl-2 tCtrl-3 tCtrl-4 t

ni.com/labviewzone

t In the Font dialog box

Selects a single word in a string .Selects an entire string .Moves forward in string by one word .Moves backward in string by one word .Moves to beginning of current line

in string .Moves to end of current line in string .Moves to beginning of entire string .Moves to end of entire string .Adds new items when entering items

in enumerated type controls andconstants, ring controls andconstants, or Case structures .

Cancels current edit in a string .Ends text entry.Increases the current font size .Decreases the current font size .Displays the Font dialog box .Changes to the Application font .Changes to the System font .Changes to the Dialog font .Changes to the current font .

7 NATIONALINSTRUMENTS"

Ctrl Switches to next most useful tool . Ctrl-B Removes all broken wires .Shift Switches to Positioning tool . Esc, right-click, Cancels a wire you started .Ctrl-Shift over Switches to Scrolling tool . or click terminalopen space Single-click wire Selects one segment .

Spacebar l Toggles between two most common Double-click wire Selects a branch .tools . Triple-click wire Selects entire wire .

Shift-Tab t Enables automatic tool selection . A While wiring, disables automatic wireTab t Cycles through four most common tools if routing temporarily.

you disabled automatic tool selection by Double-click Tacks down wire without connecting it.clicking the Automatic Tool Selection (while wiring)button . Otherwise, enables automatic spacebar Toggles automatic wiring whiletool selection . moving objects .

T 1-~ E- Navigates temporary Controls and Shift-click Undoes last point where you set a wire .Functions palettes . Ctrl-click input on Switches the two input wires .

Enter Navigates into a temporary palette .Esc Navigates out of a temporary palette .

function with

Shift-right-click Displays a temporary version of the Tools two inputs

palette at the location of the cursor. spacebar Switches the direction of a wirebetween horizontal and vertical .

Page 47: LabVIEW Manual 2009

Editing, Execution, and Debugging Tools

The VI toolbar contains the following tools . Refer to the LabVIEW Help for information about other toolson toolbars .

Show Context Help Window -Displays theContext Help window.ii

TV I Run-Runs the VI .

Broken Run-Indicates that the VI contains errors .Click the button to list errors .

c

Run Continuously-Runs the VI until you abortor pause execution .

r3

Abort Execution -Aborts execution of the~J

top-level VI .

Pause-Pauses or resumes execution .

Highlight Execution -Displays an animation ofthe block diagram when you click the Run button .

Retain Wire Values-Saves data values thatpass through wires during VI execution .

Signed integers(0)

Unsigned integers(0)

Floating-point(0 .0)

Complexfloating-point(0 .0 + i0 .0)

i

ISM

I U87I U's

Fum

16-bit

32-bit

64-bit

8-bit

16-bit

32-bit

64-bit

Boolean(FALSE)

String

Referencenumber

Enumeratedtype

Cluster

nIm

17TF

Iabc

to

(Ii

Single

}~ Double

Extended

Single

Array

Double

Extended

Step into-Opens a node and pauses .

Step Over-Executes a node and pauses at thenext node .

Step Out-Finishes executing the current nodeand pauses .

Text Settings-Changes thefont settings for the VI .

Align Objects-Aligns objects along axes .

Distribute Objects-Spaces objects evenly.

Resize Objects-Resizes multiple front panel objectsto the same size .

Reorder -Reorders objects if they overlap, includingmoving forward and moving backward .

l3pt Application Font

The Tools palette contains the following tools . Refer to the LabVIEW Help for information about other toolson the Tools palette .

Breakpoint Tool-Sets breakpoints on nodes and wires

Probe Tool-Creates probes on wires to display+I.F,Fto pause execution at that location .

intermediate values in a running VI .

Data Type Terminals

(empty string)

Path(<Not A Path,)

Note Default values appear in parentheses ( ) .

National Instruments, NI, ni .com, and LabVIEW are trademarks of National Instruments Corporation . Refer to theTerms of Use section on ni .one/lega'_ for more information about National Instruments trademarks . Other productand company names mentioned herein are trademarks or trade names of their respective companies . For patents coveringNational Instruments products, refer to the appropriate location . HelprrPatents in your software, the patents . txt fileon your CD, or n : . com/patents . For a listing of the copyrights, conditions, and disclaimers regarding components used inUSI (Xerces C++, ICU, and HDF5), refer to the us_copyrighcs .chm.

© 1997-2005 National Instruments Corporation . All rights reserved . 373353A-01 Aug05

Waveform E

Digital lrwaveform

Digital JgM

110 name I I . e

Variant l

Numeric Dynamic FIMMixed data

Picture J1D

2D Time stamp I-27(12 :00 a.m .,1/1/1904,

UniversalTime)