Simulation in LabVIEW
Simulation in LabVIEW
0.1 Introduction
LabVIEW is a graphical programming language in principle capable of the same utility that
programming in C or C++ can provide. Some capabilities of C++ are more difficult to
obtain, but for the purposes of control systems–the focus of this short tutorial–LabVIEW is
an exceptionally convenient programming language. This is for two primary reasons:
1. LabVIEW enables programming that mirrors that graphical analysis tools (such as
block diagrams) that we use to analyze control systems;
We will see both of these become evident over the course of this tutorial.
0.1.3 Organization
This tutorial will be organized according to the needs of an introductory controls course. The
goal is not to systematically introduce students to all of LabVIEW’s capabilities. It is the
author’s view that this is simply an untenable goal leading to certain failure and confusion
on the part of the students. Instead, we will focus on using simple examples, as they become
useful, to illustrate new tools being used within LabVIEW. As the tutorial proceeds, it is
assumed that less and less explicit instruction will be required, so some hints may simply
lead the reader to look at a particular tool on his own and merely indicate that it is indeed
a useful tool.
F = (212 − 32)/100C + 32
and
C = 100/(212 − 32)F − 32.
as expressions. In standard text languages, this might look something like:
4
main()
{
float DegreeF=76;
float DegreeC=celsius(DegreeF);
printf("The Temperature is %f F and %f C\n", DegreeF, DegreeC);
}
The blocks that will be required for this circuit are in the Programming // Numeric
Pallette and should be placed within the Block Diagram. To place the user interface com-
ponents, you may place a numeric constant, right click and change it to either Indicator or
Control. You may also place a numeric indicator or control in the front panel. Build this
circuit and test it.
in Fig. 2), clicking on the upper left “simulation loop” icon, and dragging it into the back
panel. It may then be stretched to any desired size. The result will look something like the
loop seen in Fig. 3. All the things that need to execute at every time step in a simulation or
hardware experiment should be placed within the simulation loop. Everything else can be
kept outside of it.
1. integration algorithm used (e.g., Euler (fixed time step), Runge-Kutta, and variable
time step algorithms);
6
2. Determines the step size both for fixed time step integration algorithms and for running
hardware experiments;
4. timing parameters (involving the clock, an external clock, how fast to access said clock,
etcetera).
All these options can be configured by right-clicking on the simulation loop and selecting
Configure Simulation Parameters. The dialog box is shown in Fig.4
The palettes contain the other operations you may wish to use. These include:
1. Generating a signal. For instance, one can create a step-input from the Signal Genera-
tion pallette. After placing the step-function in the Simulation Loop, double click on it.
This will bring up the configuration window. Within the configuration window is a list
of parameters. Clicking on any of the parameters will open “Parameter Information,”
which allows you to modify the selected parameter(i.e. final value of step-input = 10).
3. Linear effects, such as time delay are found in the Linear Systems palette. (Note that
within LabVIEW, a time delay is know as “transport delay.”)
4. Nonlinear effects such as saturation are found in the Nonlinear Systems palette.
5. Graphics: Plots can be generated using Graph Utilities. In general, you will want to
use a sim-time wave form, but you may wish to use an XY graph if you want trace
functionality.
2. step plots the step response of a transfer function or state space system;
Figure 8: MathScript defining a state space system, converting it to a transfer function, and
using it in the simulation module
10
The cursor is created in the front panel (see Fig. 12) by right clicking on the graph and
selecting Properties. Then select cursor, choose to add a cursor, and a cursor will show up
on the graph. Note that the cursor can only select actual data points–it will not interpolate.
0.7. LABVIEW SAVING AND READING 11
Therefore, you may wish to select a maximum step size in your integration algorithm that
makes it move smoothly from point to point. (E.g., reduce the maximum step size.)
2. The default amount of data a Waveform Chart in the Simulation Module displays is
1024. If your time steps are too small in a simulation or experiment, you may not get
all your data. Hence, if this happens you should change the “Chart History Length”
to a larger number (by right clicking on the graph).
3. Lastly, the time axis sometimes gets set to Day/Year format. If this happens, go into
“Properties” and under “Format and Precision” set Type to SI notation.
not be written to the file. Also note that LabVIEW allows you to plot multiple plots on the
same graph, as shown.
Now, reading data is similarly straight forward. Assuming that you have saved the data
as above (in a spreadsheet format), you can use the “Read From Spreadsheet” utility. The
data will be in an array format already, but you must use the “Index Array” to select the
data. Figure 14 shows the use of the “Index Array” block to select the first (“0”th) and
second (“1”st) signals from the data. These can then either be used or bundled together and
plotted.
0.7. LABVIEW SAVING AND READING 13
Figure 13: (top) A VI that saves data from an FPGA, (bottom) an enlargment of the section
of code that saves data
The collector can be found under Simulation // Utilities, while the Write To Spreadsheet
VI can be found under Programming // File I/O. Modify your code from Figure 8 to save
the waveform. Then import this waveform using the code from Figure 14
14