Professional Documents
Culture Documents
Richard Gonzales
Ofc P323, Ofc hrs: I am at PU all day TU & TR in my Ofc or a Lab
Email: RichardGonzales@aol.com
1
Reference Texts:
Labview 8 Student Edition, Robert Bishop, Prentice Hall, 2007
LabVIEW for Everyone, Travis & Kring, Prentice Hall, 2008
Introduction to Data Acquisition with LabVIEW, King, McGraw Hill, 2009
Labview Graphical Programming, Johnson & Jennings, McGraw Hill, 2006
The LabVIEW Style Book, Blumb, McGraw Hill, 2007
Course Grading:
This is a relatively new experimental course, and the course grading and
content may need to be modified as the course is developed. The current
thinking is shown below. You will be kept informed of any changes
implemented.
2
LabVIEW
Laboratory Virtual Instrument Engineering Workbench
Another and better name
Graphical Programming Language G (not text based)
It is a general purpose language like C, MATLAB, and others
It has Instrumentation and Display Capability
It is used for Simulation
It is used for Data Acquisition
It is used in Control Applications
Front Panel,
Block Diagram
CTRL T toggle
Icon/Connector
• Controls = Inputs
• Indicators = Outputs
5
Data Flow Programming.
A node can executed only when all the input data arrives at its
input terminals. The node supplies data to all of its output
terminals when it finishes executing.
Load Arith-2.vi
Highlight execution and step through to demonstrate the data
Flow.
6
Students Create some vi’s
7
Students Create some vi’s cont
3. Create Arith-2.vi
Add a Boolean light to Arith.vi
The light should go on if A > to 3, and is otherwise off
8
By convention, where possible, the data flow programming
diagrams are constructed so that the flow is left to right.
This results in the best readability.
Note: Nodes also generally have their inputs on the left and outputs on the right.
9
Random number generation
Rand #.vi
open and discuss
Case.vi
open and discuss
Students Create some vi’s cont
1. Create Arith+Case.vi
Add a True False Case to Arith-2.vi such that if A is not = 0 then
calculation is as before, but if A = 0 then OUT 1 = a random number
between -5 and +6.8 (Span=11.8), and OUT 2 is unchanged.
Short list LabVIEW Shortcuts and some Notes
Ctrl Hold down after selecting object and drag away to make a copy of
object Hold down while making a box in whitespace to make
more room
Shift Hold down while using arrow keys to move an object faster
Hold down and right click mouse button to bring up Tools Palette
Right-Click On any input or output to make controls/constants or
indicators. On any control and go to Replace to change to
another type, and go to Properties to modify a specific item
13
Short list LabVIEW Shortcuts and some Notes – cont
Instrument Drivers
Drivers available at ni.com/idnet
Install the instrument driver VI Library into LabVIEW 8.0\instr.lib
directory. Access drivers from
Any vi can be made into a SubVI just like any routine (program) can be
Made into a subroutine.
Method 1
Arith.vi
Open and discuss
Method 2
Open Arith+Case.vi
Set 2. Inputs: A=6 a constant l, B=X a control, and C=Z the output
from Set 1.
Outputs: Out1=XX an indicator and Out2 not used
Make this VI into a SubVI Disc.vi with an appropriate icon and icon
connect Inputs (controls) are a, b, and c,. The output (indicator) is y.
a
b Disc y
c
2. Write a SubVI that calculated the roots of a quadratic equation using
the SubVI disc.vi from Exercise 1. The digital inputs to the VI should
be the quadratic equation coefficients, and the outputs the roots of the
quadratic equation. Note that the VI should be capable of dealing with
both real and complex roots of the quadratic equation. Make this VI
into a SubVI quad eq.vi with inputs a, b, and c, and outputs r1, i1, r2,
and i2.
a r1
i1
b quad eq
r2
c i2 19
quad.vi - logic
Calculate Disc
R1=(-b+sqrt(Disc))/(2*a)
YES I1=0
Positive?
R2 =(-b-sqrt(Disc))/(2*a)
I2=0
NO
R1=-b/(2*a)
I1=+sqrt(-Disc)/(2*a)
R2=-b/(2*a)
I2=-sqrt(-Disc))/(2*a)
Assignment due next period. Hand in: Exercise 2
Exercise 2 on a 3 ½ floppy disk Open and discuss
22
Trouble shooting
Use quad eq.vi with its SubVI disc.vi to show some trouble
shooting techniques
1. Show how to set default values on A, B, C (Say 1,2,3 or
other)
2. Highlight Execution – run and look at data flow
3. Step thru the program
3. Show use of the Probe
4. Use the Stop to execute up to a point and then step thru.
23
Case Structures For more than just T, F case
demo Cases-3.vi
Connect a numeric control to the boolean input, and instead of
True False it becomes 0,1 then add as many cases as you
want
Add other cases. There are 3 total in the Demo see be,low
24
While Loops
Open & Demo
WhileLoop.vi
26
Demo ShiftReg3.vi
Add feedback registers
I
i-1
i-2
etc
27
Demo x^i.vi
The SubVI should output the value of e^x and the number of
terms in the series.
29
Exercise 3 cont.
Test your SubVI e^x.vi with Test e^x.vi - demo it.
30
Important! - Programming Success
• A Step at a Time Build programs and
subprogram in small steps testing each step
thoroughly before adding the next step. Don’t go
for broke with a big program!!
• Divide and Conquer. Use Modular
Programming techniques with SubVIs and
Subprograms
32
Introduction to Graphing
Waveform Chart:
Open & Demo Charts.vi
Strip chart
Scope Chart
Sweep Chart
Stop
34
Waveform Graphs Build below a step at a time
Graphs-1.vi
Build array - note array sizes expanded with zeros to make both the same
35
Graphs with time. Graphs-2.vi
36
XY Graph XY Graph.vi. Inputs are X arrays & Y arrays
37
Exercise 6
Generate 100 random numbers in the range from +1 to -2, one number
every 0.1 seconds. Also generate 100 values of 1.8sin10t, one value
ot t every 0.1 seconds, ie, 0, .1, .2, .3 …
c) Display both the random numbers and the 1.8sin10t numbers on a
single Waveform Chart as they are being generated, and experiment
with the different display options and features. The objective is to learn
all about Waveform Chart properties and features
d) Generate the above numbers and collect them in arrays. Display the
arrays on a Waveform Graph verses the array index. Also display the
arrays on a Waveform Graph verses time. Experiment with the
different display options and features. The objective is to learn all
about Waveform Graph properties and features
e) Display the array for the random numbers on the X axis, and the sin
wave array on the y axis of an XY Graph. Experiment with the different
display options and features. The objective is to learn all about
XYGraph properties and features
38
Formula Node Formula Node-1.vi
If else example
Note lower case if and else
39
Formula Node while loop example Formula Node-2.vi
40
Formula Node For Loop example Formula Node-3.vi
;
41
Some Formula Node Syntax Formula Node-4.vi
floating-point-type:float, float32, float64
integer-type: Int, int8, int16, int32, uInt8, uInt16, uInt32
assignment-operators: = += –= *= /= >>= <<= &= ^= |= %= **=
binary-operators: + – * / ^ != == > < >= <= && || & | % **
42
Formula Node
Do loop
1 1 1 1 1 1 1 0 0 0 0 0 0
Formula Node-5.vi 4 2 2 2 0 0 1 1 1
4 1 1 1
Bubble sort 2 2 4 0 0 2 2 2 2 2 2 2 2
0 0 0 4 4 4 4 4 4 4 4 4 4
43
Exercise 7
Write a SubVI Roots.vi using a Formula Node to calculate the roots of
a quadratic equation Ax^2+Bx+C.
A R1
B Roots I1
C R2
I2
This, of course, should yield the same result of the earlier SubVI
quad.vi.
44
Arrays
Build Array, Array Size
Array-1.vi
Index Array
Array-2.vi
45
Replace Array Subset: Array-3.vi
Array in determines size of the Array Result
46
Initialize Array, Array-5.vi
Exercise 8 Create a good example for one of the other array and
email it to me at RichardGonzales@aol.com. I will then email all of
the examples back to everyone.
47
Polymorphism – dealing with arithmetic operations on arrays of different
dimensions
Polymorphism.vi
48
Indexing (again) with For and While Loops – Demo Indexing Loops.vi
Clusters: Creating Clusters for either indicators or controls
The order (not the position) placed in the Cluster shell determined the
order in the cluster.
Demo Clusters.vi
50
Local Variable
A local variable can be
created for any control or
indicator.
51
Exercise 10 Write a bubble sort sub vi: Sort-B.vi. that does the same sort as
Formula Node-5.vi, but does not use the formula node and C code. LabVIEW
For loops, While loops and other structures should be used. You may find that
the use of a Local Variable will prove useful in order to set a DONE condition, and
then to read, and to act on that condition.
1 1 1 1 1 1 1 0 0 0 0 0 0
4 4 2 2 2 0 0 1 1 1 1 1 1
2 2 4 0 0 2 2 2 2 2 2 2 2
0 0 0 4 4 4 4 4 4 4 4 4 4
52
Exercise 10 cont Write a bubble sort sub vi: XY Sort-B.vi. that will sort [X], [Y]
data pairs so that they are ordered pairs for increasing values of X. Test your
SubVI with the [X], [Y] data pairs below:
[X] = 3.9 [Y] = -4.9 Sorted [X] = -3.1 Sorted [Y] = -1.9
12.6 6
6.3 4 2.1
0 6.7 -1.2 6.7
-3.1 -1.9 0 3.1
10.1 -1.5 1.2 -4.9
5,0 -8.1 3.9 -8.1
7.5 1.9 5,0 4
2.1 6.3 1.9
-1.2 3.1 7.5 -1.5
10.1 6
1.2 12.6
[X] Sorted [X]
XY
[Y] Sort-B Sorted [Y]
53
Trapezoidal Integration lecture etc. on black board
y
A2 yi+1
Ai x yi
A0 A1
Ai
xi xi+1
54
Exercise 11 Write a SubVI (Trap I.vi) that will integrate a curve y(x)
using trapezoidal integration. y(x) is described by [x], [y] data
points, two arrays. The integral array [z] is the output of the SubVI,
and is an array of values for the integral.
[x]
Trap I [z]
[y]
Write a test routine Exercise 11.vi to test the SubVI by integrating the
curve described by the following data points.
55
Exercise 11.vi, testing the Trap I SubVI
56
Interpolation Lecture summary
Ya Yi+1
Y Ya
Yi
X0
X
XL Xi Xa Xi+1
Xa
Xa is in the range X0 to XL
Ya = Yi+1 – Yi)/(Xi+1-Xi)) (Xa-Xi) + Yi
Point slope formula Y = mX + B
[X] = X0, X1, X2, x3, …XL
[Y] = Y0, Y1, Y2 ……… YL
57
Interpolation Lecture summary Xa, Ya
Out of range Xa<X0 or Xa>XL
XL, YL
X0, Y0 Xa>XL
Ya = (YL - YL-1)/(XL - XL-1)*(Xa-XL) + YL
Xa, Ya
Xa<X0
Ya = (Y0+1 - Y0)/(X0+1 – X0)*(Xa-X0) + Y0
58
Exercise 12
Write a SubVI Interp.vi that does linear interpolation for array data points [X], [Y]. That
is, for an input Xa the output Ya will be calculated, Outside of data range interpolation
should take place, and the out of range magnitude M calculated and printed. The vi
should also output the value of the index i, where Xi<=Xa<Xi+1. Note if Xa<=X0 the
value of i should be 0, and if Xa>=XL the value of i is L-1
[X] Ya
[Y] Interp i
m
Xa
DemoTextInterp.vi
59
DemoTextInterp.vi
Exercise 12 cont. Write a SubVI InterpM.vi that does linear interpolation for a array of
data [X], [Y] points, and for an array of input values [Xa]. That is, interpolation for the
elements of an input array [Xa] an interpolated output array [Ya] will be calculated.
Also an array [i], and an out of range magnitude array [m.] will be calculated.
X] [Ya]
Write a vi, Exercise 12.vi, to test InterpM.vi and Interp.vi using the [x], [y] data of
Exercise 11, and the following test values for [xa].
[Xa] = [-5, -3.1 -2.03, -1.49, 6.3, 9.8, 11.5, 17.62, 19.7, 21.5, and 23.4].
Test other data array inputs.
61
Exercise 12 – Demo TestInterp&InterpM.vi,
Select 1.vi
A 3 bit binary array selector
Select 2.vi another selector
Select 2.vi
64
Integration from xa to xb, lecture etc on blackboard, Calculate the Integral of a curve
from xa to xb using original data where possible.
y
A2
xa Ai Ai+1
A0 A1
x
xb
65
Exercise 13
Write a SubVI NewD.vi with inputs [x], [y], xa, and xb. The outputs of the SubVI are
modified arrays [xn], and [yn], which are new set of data point arrays from the low
limit xa to the high limit xb. The original data points are to be used except at the end
points xa and xb. Thus, interpolation will be necessary and your sub vi Interp.vi will
be needed. Also consider error checking for invalid input values etc.
[x]
[xn] = [xa, xi, xi+1, …., xb]
[y] NewD
xa [yn]
error
xb
Write a vi TestNewD.vi that calculates an array [z] which is equal to the integral
of a curve defined by arrays [xn] and [yn] above. TestNewD.vi logically will thus
include the SubVIs Trap I.vi, NewD.vi, and Interp.vi. The integral is to be from a
low limit of xa to a high limit of xb. The output results [z], vs the [xn] should be
graphed over the range from xa to xb. Use the data of Exercise 11, and test
your vi for xa = -4.9, xb = 11.5, and xa = 3.1, xb = 10.5. Also test for other alues
for xa &, xb. Check the results to make sure the vi is working properly.
66
TestNewD.vi. Run it also for for various values of xa, and xb
67
Integration from Xa to Xb using new points equally spaced, Calculate the Integral of
a curve from Xa to Xb using new points equally spaced by inc.
y
A2
xa
A0
x
xb
[x]
[Xn]
[y]
xa NewD2 [Yn]
xb error
inc
Write a vi Exercise 14.vi that calculates an array [z] which is equal to the integral
of a curve defined by arrays [x] and [y]. Exercise 13.vi logically will include the
SubVIs Trap I.vi, NewD.vi, and Interp.vi and possibly InterpM.vi. The integral is
to be from a low limit of xa to a high limit of xb. The output results [z], vs the [xn]
should be graphed over the range from xa to xb. Use the data of Exercise 11,
and test your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb =
10.5, and inc=1 and also test it for other values for xa &, xb. Check the results to
make sure the vi is working properly. 69
Demo SubVI, xa inc xb.vi:
given [x] xa, inc, & xb, create [xa, xa+inc, xa+2*inc………xb ]
TestNewD2.vi: Testing NewD2.vi
71
Curve Fitting,
Blackboard lecture first on polynomial curve fitting then:
Demo CurveFit-1.vi, and CurveFit-2.vi & use experiment with different polynomial
Orders.
72
Curve fit with lots of points: Demo CurveFit-3.vi, with different orders
from demo folder
73
Blackboard Lecture on polynomial Integration
74
Exercise 15, Polynomial Integration
Write a SubVI to evaluate the integral of a polynomial c0 + c1*x =+ c2x^2 + …
Start by writing the SubVI PolyInt 1 Point.vi with input data [c (poly coef)], and x to
do the evaluation of the integrated polynomial c0*x/1 + c1*x^2/2 + c2* x^3/3 +
c3*x^4/4 + … ……… The output of the SubVI z is the integrted polynomial
evaluated at one value of x (1 point).
Then write PolyInt.vi with array data inputs [c (poly coef)], xa, inc, and xb. The
output of the SubVI is the integral array, [z]. [z] is the integral from xa to xb
evaluated at each [x2] array point, where [x2]=[xa, xa+inc, xa+2*inc, xa + 3*inc,…. …
xb]. This routine will logically use the SubVI PolyInt 1 Point.vi.
Write a vi Exercise 15.vi to test PolyInt.vi, PolyInt 1 Point.vi and calculate the array
[z], which is equal to the integral at the data points [x2] of a curve defined by arrays
[x] and [y]. Plot the results and fully test the vi’s. Use the data of Exercise 11, and test
your vi for xa = -4.9, xb = 11.5, and inc =1, and for xa = 3.1 and xb = 10.5, and inc=1
and also test it for other values for xa &, xb. Experiment with different polynomial75 fit
order. Check the results to make sure the vi is working properly.
Exercise 15, Polynomial Integration test results
Demonstrate this vi
76
Submit your Exercises on 3.5 floppy disk
• Submit all completed exercises. Save complete folders with all SubVIs needed
for each exercise in the folder, eg, Exercise 1 Folder, etc.
78
Exercise 16,
Write a SubVI Poly LSE Fit.vi to determine the polynomial coefficients for a least
square error fit of data points [x], [y] using the regression technique. This SubVI
should be basically the same as the LabVIEW LSE routine
Write a vi, Exercise 16.vi, to test Poly LSE Fit.vi. Use the [x], [y] data of Exercise 11,
and compare your results with the LabVIEW LSE routine, and Check the to make
sure the vi is working properly.
79
Exercise 16.vi
Course Project, Paper, and Presentation
81
Schedule
Project Selection Due November 4 with a brief written abstract of what you plan to do.
Final Project Abstract and all Exercises are Due November 20 on your 3.5 disk
Final Abstract Format
Title:_____________
Name:____________
Brief description less than 100 words
December 2 Ning Xu
Xiao Guo
December 4 Xiaohan Xu
Man Xu
82
Euhlers Technique, Differential Equations
83
DE Euh 1.vi, demo this
84
Blackboard lecture and hand outs on Euhler’s technique for an nth order differential
equations.
Exercise 17,
Write a SubVI Euh M.vi that uses Euhler’s method to solve a set of 1st order
differential equations. Note, also a SubVI F(X,Y) Euh M.vi will be needed for the
function describing the differential equation
X0
[X] X
DX F(X,Y) [F(X,[Y])]
Xl Euh M Euh M
[Y] Y
[Y]0
Write a VI, TestEuh M.vi, to test Euh,M.vi, and F(X,Y) Euh M.vi for the differential
equation Y’’’ + 5Y’’ + 8Y’+6Y= 3. Check the to make sure the VI is working properly.
85
Exercise 17.vi, demo this.
86
Exercise 18
The Rocket
air drag
K(y)*dy/dt*|dy/dt|lbs
This is a hypothetical
LabVIEW Design Exercise.
A weather and pollution data
gathering rocket containing
delicate instrumentation and mass of rocket with a
full load of fuel at
photographic equipment is t=0 is 9.56 slugs
y(t)
being developed. The (weight = 307.8 lbs)
87
As fuel is burned a thrust force is created which is
proportional to the rate of fuel consumption. Laboratory
data from dynamometer tests shows the rate of fuel
consumption Vs time. Data points are provided showing
consumption in lbs per second Vs time for the 9 second
solid fuel burn cycle in the file -DWDT.VI.
88
Note that for t > 9 seconds m’ = 0, T = 0.
or
Y0’= F0 = Y1
Y1’= F1 = (T - 32.2m – K(Y0)Y1|Y1| - m’Y1)/m
Analyze and investigate the rocket flight using LabVIEW.
Your solution should include the following:
m Rocket
Time Data Mass Slugs
Fuel Rate Data m’ rate of change Rocket mass
mm’T
slugs/sec
Time
T Rocket EngineThrust
y K(y) K(y)
Interpolation and trapezoidal integration are appropriate for the fuel data
to calculate m, m’ and T. For the air friction function K(y), a polynomial
curve fit is preferred because of the nature of the data given. 91
Logical extensions to this design problem are:
1. Jettison the fuel section of the rocket after the fuel is used up. This would
reduce the mass and effect the final altitude, and/or amount of fuel required.
Say that the fuel shell that can be discarded is 1 slug, and it could be
jettisoned 1 second after the fuel is used up.
3. The effects (max velocity, acceleration, height etc,) resulting from different
solid fuel burning rate schedules with the same initial amount fuel.
92
File I/O and Strings Demo these
93
File I/O 3.vi:
File Path, Headers, Write to a Text File,
Write to a Excel File, and Write to a a
binary File
Data Acquisition DAQ
Demo this
94
File I/O 4.vi:
Read 1d String Data from a Text File
and convert to Numerical 1d Data
Array. Data Acquisition DAQ - Demo
this
95
File I/O 5.vi:
Read Data from a Binary File and convert to Numerical 2d
Array Data. Data Acquisition DAQ - Demo this
96
Exercise 19
Study File IO 1.vi, File IO 2.vi, File IO 3.vi, File IO 4.vi, and File IO 5.vi …. for a
full understanding.
Write a SubVI String to Numbers.vi that will convert multiple lines of an ascii
string of numbers to a numerical array. The vi should handle String data
representing by both 1 and 2 dimensional data. The data string format is tab
separated for each row, and rows are separated by a carriage return. Fully test
the SubVI with Exercise 19.vi – Sample below.
Array 1d
String
String
to
Numbers Array 2d
97
DAQ1.vi Demo
Data acquisition, analog in using DAQ Assistant, 1 Sample, 8 Channels, on Demand,
10 ms loop time = acquire rate, Channel 2 Selected for acquired samples and
graphing
98
DAQ2.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate), Channel 2 Selected for acquired samples and graphing
99
DAQ3.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate) , Time & channel results saved in an EXCEL spread
sheet and graphed.
100
DAQ4.vi Demo
Data acquisition, analog in using DAQ Assistant, Continuous Samples, 8 Channels,
at 10HZ (10 ms sample rate) , time added to data, results saved every .1 sec as it is
acquired in a text file.
101
DAQ5.vi Demo Data acquisition
Digital Input
Digital Output
Analog Out - DAC
102
Data Buffer Window.vi Demo
Array In has new Add Array appended to it array resized, and oldest data is discarded
yielding Array OUT – a moving window
1 2 3 4 5 6 7 8 9 10
103
DAQ6.vi Demo Master – Slave
Analog in DAQ
104
DAQ Signals.vi Demo A DAQ Signal simulator for 5 channels with sin, square wave,
and random signals of variable frequency, amplitude and offset
Time
Input
FFT.vi Demo Fast Fourier Transform
Demo vis in Mouse Examples Folder
107
108
109
110
111