Académique Documents
Professionnel Documents
Culture Documents
Leiden University
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
2
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
3
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.
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.
[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.
4
Practicum 1
In this practicum you will be introduced to the basics of LabVIEW. To start, open LabVIEW and
create a ‘Blank VI’.
Figure 1: Run.
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)’
5
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:
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
6
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.
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’.
7
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.
8
Figure 7: While loop.
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.
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
9
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.
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.
8 Hover over the icon until an up/down pointing arrow appears, then click-and-drag, dragging
since the content of the source is only determined by connecting the sink.
10
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].
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
11
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.
12All the GPIB sub-VIs can also be found via the ‘Instrument I/O|GPIB’ section on the functions
palette.
12
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
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
13
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.
14
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.
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’.
15
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.
14You 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.
16
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.
15 This part of the manual is an adaptation of the original course material ‘Data Acquisition
17
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.
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 f
max/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.
18
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.
The similarity with the 20MHz limit of the Tabor is most likely coincidental; the
21
19
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.
Q.28
Which three types of cluster ‘bundling’ sub-VIs exits? Where can you find them?
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
20
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.
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
21
What do you have to do to the ‘False’ or ‘≠0’-cases in order to make the case structure
work?
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
22
immediately to this rather involved way of solving DAQmx problems before consulting one of
the course assistants.
23
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.
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 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.
24
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?
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
25
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.
26
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?
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.
27
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.
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
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.
28
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.
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.
29
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].
30
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.
DAC I
HEATER
PC
Cu
NTC
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
= P − κ (T − T0 ),
dT
C
dt
Equation 1
31
Figure 28: Temperature dynamics of a simple system.
T (t ) = TEQ + ΔT exp (− t τ )
Equation 2
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.
32
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 :
y p (t ) = K P e(t )
Equation 3
For our specific case the feedback signal is the power P(t), which we apply to our system:
P (t ) = −κK P (T (t ) − TS )
Equation 4
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:
33
t
y I = K I ∫ e(t ')dt ' = K I ∑ e(ti ).
t0 i
Equation 5
The expression for heating power P(t) can then be given in a form of:
t
P (t ) = −κK I ∫ [T (t ') − TS ]dt ' = −κK I ∑ [T (t i ) − TS ].
t0 i
Equation 6
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:
de(t )
yD = K D
dt
Equation 7
Which is equivalent to the following discrete representation of the time-derivative less sensitive
e(ti ) to noise:
Equation 9
34
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:
⎛ t ⎞
y PI = K P ⎜ e(t ) + ( )
1 ⎟.
⎜ Δt I ∫t e t ' dt
⎟
⎝ 0 ⎠
Equation 10
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:
⎛ Δt t
⎞
P (t ) = − K P ⎜⎜ [T (t ) − TS ] + S ∑ T (t ) − T ⎟⎟,
Δt I
S
⎝ t =0 ⎠
Equation 11
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.
PID control is the most advanced algorithm, combining all the tree controls we have considered:
de (t )
t
y PI = K P e(t ) + K I ∫ e(t ')dt + K D .
t0
dt
Equation 12
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.
T P T
TS TS TS
t t
Figure 29: Typical time traces for real P, PI and PID controls. TS is the set-point temperature.
35
R, R, Om T, C R, Om
1600
15 1508,4
1500
1400 20 1223,9
1300
25 1000,0
1200
1100 30 822,5
1000
900
35 680,9
800 40 567,0
700
600
45 474,9
500 50 400,0
400
300 55 338,6
200 60 288,1
100
10 20 30 40 50 60 70 65 246,3
O
T, C
70 211,6
⎛T ⎞ ⎛T T ⎞
RNTC = C exp ⎜ C ⎟ = R0 exp ⎜⎜ C − C ⎟⎟
⎝T ⎠ ⎝ T T0 ⎠
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.
36
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.
R1 = 1 kOm
PC ADC R
V
NTC 5V
37
Experiment
Connection Box
(ADC & DAC)
AI0 AO0 oo to PC
+5V
In
Current
amplifier
Out
ADC +5V DAC
R1
RED
Ground In / Out
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
38
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.
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.
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:
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.
• 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.
39
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?
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:
40
• 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.
41
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.
• 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.
42
43
7
NATIONAL
INSTRUMENTS°
Context Help
When you move the cursor over LabVIEW objects, the Context Help window
displays basic information about each object . Select Help»Show Context
Help to display the Context Help window .
LabVIEW Help
Includes information about LabVIEW programming concepts, step-by-step
instructions for using LabVIEW, and reference information about LabVIEW VIs,
functions, palettes, menus, and tools . Access the LabVIEW Help by selecting
Help»Search the LabVIEW Help .
LabVIEW Examples
LabVIEW searches among hundreds of example VIs you can use and
incorporate into VIs that you create . You can modify an example VI to
fit an application, or you can copy and paste from one or more examples
into a VI that you create . Browse or search the example Vis by selecting
Help»Find Examples .You also can right-click a VI or function on the
block diagram or on a pinned palette and select Examples from the
shortcut menu to display a help topic with links to examples for that
VI or function .
n i .com/Iabviewzone
Keyboard Shortcuts
You also can access this list of keyboard shortcuts in the LabVIEW Help .
Help
Navigating the
VI 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 .
Note The <Ctrl> key in these shortcuts corresponds to the (Mac OS) <Option> or <Command> key or (Linux) <Alt> key .
n i .com/labviewzon e
Text
SubVls
Double-click Selects a single word in a string .
Double-click Displays subVl front panel . Triple-click Selects an entire string .
subVl
Ctrl--> Moves forward in string by one word .
Ctrl-double-click Displays subVl block diagram and front Ctrl-- Moves backward in string by one word .
subVl panel . Home Moves to beginning of current line
in string .
Drag VI icon to Places that VI as a subVl on the End Moves to end of current line in string .
block diagram block diagram . Moves to beginning of entire string .
Ctrl-Home
Shift-drag VI Places that VI as a subVl on the Ctrl-End Moves to end of entire string .
icon to block block diagram with constants Shift-Enter Adds new items when entering items
diagram wired for controls that have in enumerated type controls and
non-default values . constants, ring controls and
Ctrl-right-click Opens front panel of that VI . constants, or Case structures .
block diagram Esc Cancels current edit in a string .
and select VI Ctrl-Enter Ends text entry.
from palette Ctrl Increases the current font size .
Ctrl- Decreases the current font size .
-Ctrl-0 Displays the Font dialog box .
Ctrl-1 t Changes to the Application font .
Execution Ctrl-2 t Changes to the System font .
Ctrl-R Runs the VI . Ctrl-3 t Changes to the Dialog font .
Ctrl- . t Stops the VI . Ctrl-4 t Changes to the current font .
NATIONAL
n i .com/labviewzon e
7 INSTRUMENTS"
Show Context Help Window -Displays the Step into-Opens a node and pauses .
ii Context Help window.
c
Broken Run-Indicates that the VI contains errors .
Click the button to list errors .
Run Continuously-Runs the VI until you abort
n Step Out-Finishes executing the current node
and pauses .
l3pt Application Font Text Settings-Changes the
or pause execution . font settings for the VI .
3
r
~J
Abort Execution -Aborts execution of the
top-level VI . Im Align Objects-Aligns objects along axes .
Highlight Execution -Displays an animation of Resize Objects-Resizes multiple front panel objects
the block diagram when you click the Run button . to the same size .
Retain Wire Values-Saves data values that Reorder -Reorders objects if they overlap, including
pass through wires during VI execution . moving forward and moving backward .
The Tools palette contains the following tools . Refer to the LabVIEW Help for information about other tools
on the Tools palette .
Breakpoint Tool-Sets breakpoints on nodes and wires Probe Tool-Creates probes on wires to display
+I.F,F
to pause execution at that location . intermediate values in a running VI .
National Instruments, NI, ni .com, and LabVIEW are trademarks of National Instruments Corporation . Refer to the
Terms of Use section on ni .one/lega'_ for more information about National Instruments trademarks . Other product
and company names mentioned herein are trademarks or trade names of their respective companies . For patents covering
National Instruments products, refer to the appropriate location . HelprrPatents in your software, the patents . txt file
on your CD, or n : . com/patents . For a listing of the copyrights, conditions, and disclaimers regarding components used in
USI (Xerces C++, ICU, and HDF5), refer to the us_copyrighcs .chm.
© 1997-2005 National Instruments Corporation . All rights reserved . 373353A-01 Aug05