Giáo Trình Labview
Giáo Trình Labview
CONTENTS ...............................................................................................................2
FOREWORDS ...........................................................................................................3
CHAPTER 1: INTRODUCTION TO LABVIEW .................................................4
1.1 LabVIEW: ....................................................................................................4
1.2 Setup LabVIEW on your PC: ....................................................................5
1.3 Getting started with LabVIEW: ..............................................................14
1.4 How to use? ................................................................................................15
1.5 Front Panel and Block Diagram Panel:...................................................20
1.5.1 Front Panel: .....................................................................................20
1.5.2 Block Diagram Panel: .....................................................................21
Chapter 2: Programming .......................................................................................22
2.1 Elements in LabVIEW: .............................................................................22
2.1.1 Structures: ........................................................................................22
2.1.2 Data Types: ......................................................................................27
2.1.3 Numeric Palette: ..............................................................................29
2.1.4 Comparison Palette: ........................................................................32
2.1.5 Boolean Palette: ...............................................................................37
2.1.6 Timing Palette: ................................................................................40
2.1.7 Array and Clusters:.........................................................................42
2.1.8 String: ...............................................................................................46
2.2 Algorithm: ..................................................................................................48
** Small exercises: ..........................................................................................50
CHAPTER 3: LABVIEW+ARDUINO .................................................................51
3.1 Introductions:.............................................................................................51
3.2 Hardwares: .................................................................................................51
3.3 Softwares: ...................................................................................................51
**Small exercises: ...........................................................................................54
CHAPTER 4: REFERENCE .................................................................................54
2
FOREWORDS
I have been using LabVIEW for nearly a year when working with a
project name “Water level tank control”. Before knowing LabVIEW, I just
knew a little bit of Matlab and wanted to find a simulation software which can
indicate results combined with Transfer Function to look more reality and
animated. That’s how I know LabVIEW.
But in the first time approaching this software, I had a concern of how
can I work with it, just like I had the same thought with Matlab eventhough I
had spent 3 months working with Matlab and still it was so complicated. On
the contrary, LabVIEW proves to be friendlier than Matlab but if you want to
ask me of which software will be better in solving Automatic Control System
or strong in combination of mathematics, analyze characteristics and
supportive in researches ? I’d rather choose Matlab than LabVIEW. Anyway,
with the same amount of time to get acquainted to LabVIEW, I could
understand some basic elements in this software and finalized my project
quite well (not totally well in mathematics but in simulation was fine).
What I mentioned there was just that each software has its own strong points
depend on what kind of applications we are working with. LabVIEW has its
strong points at indicating results animatedly, faster loading time, there are
lots of open-sourced modules with high accuracy which help you connect to
various types of peripheral devices. There was a time I almost needed to
reinstall my Window Operations because I couldn’t connect Arduino UNO to
Matlab for reasons until now I haven’t had an answer but just for a few clicks,
I made it easily with LabVIEW and module NIVISA.
This book only provides introduction to LabVIEW with nothing huge
in knowledge, you can easily find some similar documents like the one you
are reading now but in Việt Nam there are less of documents about
LabVIEW, I only want to contribute my little knowledge of this software to
the community along students, students who are studying Engineering majors,
researchers or even engineers. There will be mistakes in this book and
misunderstanding terms, please be generous and send me your thoughts. I do
appreciate that.
Thank you,
Trung.
3
CHAPTER 1: INTRODUCTION TO LABVIEW
1.1 LabVIEW:
The graphical language is named "G"; not to be confused with G-code. Originally
released for the Apple Macintosh in 1986, LabVIEW is commonly used for data
acquisition, instrument control, and industrial automation on a variety of operating
systems (OSs), including Microsoft Windows, various versions of Unix, Linux,
and macOS.
Interfacing to devices
4
Figure 1 Example of LabVIEW.
5
Figure 2 LabVIEW components
Figure 3 Press OK
6
Figure 4 Unzip and wait till it's done
7
Figure 6 Press "Next" and fill out your information
8
Figure 8 Should leave the directory in C drive
9
Figure 10 Leave that little square empty
10
After installations, no need to reset your computer. Keep installing the
modules. I will show you how to install one module and the following
modules that suit your purpose, you can install them alike.
11
Figure 14 No ticking and "Next"
12
After our installations are succeeded, let’s “crack” them up.
13
1.3 Getting started with LabVIEW:
Figure 18 Homepage
14
Figure 20 Front Panel and Block Diagram Panel
15
Figure 21 In Front Panel
16
Figure 23 Open Help menu
17
Figure 25 Open Help and Examples
Figure 26 Roll the Help menu to lowest and you will see "Open Example", click on it
- After clicking, you will receive a VI file they created. Following this
file, you can get to know more clearly of how the command works,
when you should apply this one or what elements it requires.
18
Figure 27 Front Panel of the Example
19
1.5 Front Panel and Block Diagram Panel:
1.5.1 Front Panel:
20
As you have seen, Control Palette of Front Panel has 2 objects:
Controls: Used for changing the values of the variables while
simulating.
Indicators: Used to show the results of the code while simulating.
21
CHAPTER 2: PROGRAMMING
2.1 Elements in LabVIEW:
2.1.1 Structures:
Structures are located in Structure Palette in Block Diagram Panel.
Like you can see, we will mostly work with For Loop, While Loop,
Formula Node. If you have had some experiences in programming
languages, then these loops construction wouldn’t have been hard to deal
with.
22
While Loop:
Repeats what located inside it until the conditional terminal receives a
particular Boolean value. By default, if the conditional terminal receives a
True (Boolean Value) the iteration stops. However, this condition can be
changed by right-clicking on it and changing the continuation behavior from
Stop if True to Continue if True.
For Loop:
For Loop and While Loop are two necessary commands in any programming
language. The main difference between these two is that by the latter the
number of the iterations is limited to the predefined number (N). The iteration
(i) terminal provides the current loop iteration count, which ranges from 0 to
n-1.
23
Formula Node
This node calculates the mathematical formulas. Many mathematical formulas
such as sin, asin, cos, acos, absolute value and so on can be used with this
node.
Corresponding
Function Description
LabVIEW Function
abs(x) Absolute Value Returns the absolute value of x.
Rounds x to the next higher integer
Round Toward
ceil(x) (smallest
+Infinity
integer x).
Computes the cosine of x, where x is in
cos(x) Cosine
radians.
Computes the cotangent of x (1/tan(x)),
cot(x) Cotangent
where x is in radians.
Computes the value of e raised to the x
exp(x) Exponential
power.
Truncates x to the next lower integer
floor(x) Round To –Infinity (largest
integer x).
int(x) Round To Nearest Rounds x to the nearest integer.
Rounds x to the nearest integer between x
intrz(x) — and
zero.
Computes the natural logarithm of x (to
ln(x) Natural Logarithm the
base of e).
24
Natural Logarithm
lnp1(x) (Arg Computes the natural logarithm of (x + 1).
+1)
Computes the logarithm of x (to the base
log(x) Logarithm Base 10 of
10).
Compares x and y and returns the larger
max(x,y) Max & Min
value.
Compares x and y and returns the smaller
min(x,y) Max & Min
value.
Computes the remainder of x/y, when the
mod(x,y) Quotient & Remainder
quotient is rounded toward –Infinity.
pow(x,y) Power of X Computes x raised to the y power.
Produces a floating-point number between
Random Number (0 –
rand( ) 0
1)
and 1 exclusively.
Computes the remainder of x/y, when the
rem(x,y) Quotient & Remainder
quotient is rounded to the nearest integer.
Returns 1 if x is greater than 0, returns 0 if
x
sign(x) Sign
is equal to 0, and returns –1 if x is less
than 0.
Computes the sine of x, where x is in
sin(x) Sine
radians.
Returns the size of the dimension di
sizeOfDim(ary,di) — specified
for the array ary.
sqrt(x) Square Root Computes the square root of x.
Computes the tangent of x, where x is in
tan(x) Tangent
radians
25
Flat Sequence
Consists of one or more subdiagrams, or frames, that execute sequentially.
Use the Flat Sequence structure to ensure that a subdiagram executes before
or after another subdiagram.
Data flow for the Flat Sequence structure differs from data flow for other
structures. Frames in a Flat Sequence structure execute from left to right and
when all data values wired to a frame are available. The data leaves each
frame as the frame finishes executing. This means the input of one frame can
depend on the output of another frame. [2]
Case Structure
Condition structure, where you will receive condition input is TRUE or
FALSE and inside the structure, you will implement some processing codes
or warning.
26
Feedback Nodes and Shift Registers
These two are memory elements that save data between subsequent cycles of
While Loop or For Loop. [3]
These are used in case the data of a present terminal is dependent on the
previous data.
Feedback Node and Shift Registers are almost the same.
27
Table 2 Numeric Data types table
28
2.1.3 Numeric Palette:
Use the Express Numeric functions to create and perform arithmetic and
complex mathematical operations on numbers and to convert numbers from
one data type to another.
29
30
Figure 41 Details about Numeric Palette [1]
31
2.1.4 Comparison Palette:
32
33
34
35
Figure 44 Details about Comparison Palette [1]
36
2.1.5 Boolean Palette:
37
38
Figure 46 Details about Boolean Palette [1]
39
2.1.6 Timing Palette:
Palette Description
Object
Date/Time Converts a cluster of time values into a timestamp measured as
To Seconds the number of seconds that have elapsed since 12:00 a.m.,
Friday, January 1, 1904, Universal Time, assuming is DST is set
to 1.
Elapsed Indicates the amount of time that has elapsed since the specified
Time start time.
Format Displays a timestamp value or a numeric value as time in the
Date/Time format you specify using time format codes.
String
Get Returns a timestamp of the current time. LabVIEW calculates
Date/Time In this timestamp using the number of seconds elapsed since 12:00
Seconds a.m., Friday, January 1, 1904, Universal Time.
Get Converts a timestamp value or a numeric value to a date and time
Date/Time string in the time zone configured for the computer. The function
String interprets timestamp and numeric values as the time-zone-
independent number of seconds that have elapsed since 12:00
a.m., Friday, January 1, 1904, Universal Time.
High Returns the relative current time in seconds. Use the difference
Resolution between two successive values to measure the elapsed
Relative
Seconds time between the calls. Use this VI to measure time spans with
40
much higher resolution than you can obtain from the Tick Count
(ms) function. The time resolution of this VI may vary with
different operating systems and CPU types.
Seconds To Converts a timestamp value or a numeric value to a cluster of
Date/Time time values.
41
2.1.7 Array and Clusters: [3]
An array, which consists of elements and dimensions, is either a control or an
indicator – it cannot contain a mixture of controls and indicators. Elements
are the data or values contained in the array. A dimension is the length,
height, or depth of an array. Arrays are very helpful when you are working
with a collection of similar data and when you want to store a history of
repetitive computations.
Array elements are ordered. Each element in an array has a corresponding
index value, and you can use the array index to access a specific element in
that array. In NI LabVIEW software, the array index is zero-based. This
means that if a onedimensional (1D) array contains n elements, the index
range is from 0 to n – 1, where index 0 points to the first element in the array
and index n – 1 points to the last element in the array.
42
Figure 49 Clusters Palette
Palette Description
Object
Array Use this constant to supply a constant array value to the block
Constant diagram.
Array Max Returns the maximum and minimum values found in array, along
& Min with the indexes for each value.
Array Size Returns the number of elements in each dimension of array.
Array Returns a portion of array starting at index and containing length
Subset elements.
Array To Converts a 1D array to a cluster of elements of the same type as
Cluster the array elements. Right-click the function and select Cluster
Size from the shortcut menu to set the number of elements in the
cluster.
Array To Converts an array to a matrix of elements of the same type as the
Matrix array elements. Wire data to the Real 2D Array input to determine
the polymorphic instance to use or manually select the instance.
Build Array Concatenates multiple arrays or appends elements to an n-
dimensional array.
Cluster To Converts a cluster of elements of the same data type to a 1D array
Array of elements of the same data type.
Decimate 1D Divides the elements of array into the output arrays, placing
Array elements into the outputs successively. This function drops any
elements that cause the output arrays to have different lengths.
Delete From Deletes an element or subarray from n-dim array of length
Array elements starting at index. Returns the edited array in array w/
43
subset deleted and the deleted element or subarray in deleted
portion.
Index Array Returns the element or subarray of n-dimension array at index.
Initialize Creates an n-dimensional array in which every element is
Array initialized to the value of element.
Insert Into Inserts an element or subarray into n-dim array at the point you
Array specify in index.
Interleave Interleaves corresponding elements from the input arrays into a
1D Arrays single output array.
Interpolate Linearly interpolates a decimal y value from an array of numbers
1D Array or points using a fractional index or x value.
Matrix To Converts a matrix of elements to an array of elements of the same
Array data type. Wire data to the Real Matrix input to determine the
polymorphic instance to use or manually select the instance.
Replace Replaces an element or subarray in an array at the point you
Array specify in index.
Subset
Reshape Changes the dimensions of an array according to the values of
Array dimension size 0..m-1.
Reverse 1D Reverses the order of the elements in array, where array is of any
Array type.
Rotate 1D Rotates the elements of array the number of places and in the
Array direction indicated by n.
Search 1D Searches for an element in a 1D array starting at start index.
Array Because the search is linear, you need not sort the array before
calling this function. LabVIEW stops searching as soon as the
element is found.
Sort 1D Returns a sorted version of array with the elements arranged in
Array ascending order. If array is an array of clusters, the function sorts
the elements by comparing the first elements. If the first elements
match, the function compares the second and subsequent
elements. The connector pane displays the default data types for
this polymorphic function.
Split 1D Divides array at index and returns the two portions with the
Array element of index at the beginning of second subarray.
Threshold Interpolates points in a 1D array that represents a 2D non-
1D Array descending graph. This function compares threshold y to the
values in array of numbers or points starting at start index until it
finds a pair of consecutive elements such that threshold y is
greater than or equal to the value of the first element and less than
or equal to the value of the second element.
Transpose Rearranges the elements of 2D array such that 2D array[i,j]
2D Array becomes transposed array[j,i].
44
Table 5 Details about Cluster palette [2]
45
Use this function on the block diagram of a subVI when you
want to guarantee that LabVIEW downcasts a LabVIEW class
output of the subVI node to the same class type as a LabVIEW
class input when the subVI receives a child class of the expected
input type.
To More Typecasts a reference, such as a control or a type definition, to a
Generic Class more generic class in the inheritance hierarchy.
To More Typecasts a reference, such as a control or a type definition, to a
Specific Class more specific class in the inheritance hierarchy.
Unbundle Splits a cluster into each of its individual elements.
Unbundle By Returns the cluster elements whose names you specify.
Name
2.1.8 String:
46
Table 6 Details about String Palette [2]
2.2 Algorithm:
Algorithm is the most important thing to every job, without Algorithm, you
can only solve simple problems like: 1 + 1 = ? or A dog and a lion, which one
is faster ?
But when you meet a problem with higher complexity, algorithm helps you
define specifically what kind of problem you are dealing with, in step by step
you take to the final answer.
Talking about Algorithm, let’s meet Flowchart Diagram.
48
Figure 51 Flowchart symbols( picture is taken from google.com)
49
Figure 52 Example of Flowchart (picture is taken from google.com)
** Small exercises:
1. Adjust a knob, indicate results on a Water tank and Number indicator
of the level water in side the Tank.
2. A traffic light has 3 colors, Red light lasts for 10 secs, Green light lasts
for 10 secs and Yellow light lasts for 5 secs. Let it run nonstop until
press Stop button.
3. Enter a number, check if it’s a prime number. If it’s true, turn on the
Light and show “Great!”. If not, don’t turn on the Light and show “Oh
no!”.
4. Enter a number n, run in a loop structure to calculate the sum of
numbers from 0 to n-1. Indicate results in Vertical bar.
5. Fill an array with 3 contexts: Name, Year of birth, Job. Length of array
is input by user. When you adjust Index number, example: at index 3,
data are {Haul, 1988, Driver}, show data on Array. If press Show, all
information is shown on cluster.
6. Input a string, rotate that string.
7. Make a switch, if it’s ON. Show information consists of 3 data types:
Double, Integer, String. If it’s OFF, show information of 3 values with
same data type.
8. Enter a number n, draw a random values from 0 to n on a chart, Stop
the loop after 10 secs.
9. Count the number of letters from a string you input.
50
CHAPTER 3: LABVIEW+ARDUINO
3.1 Introductions:
This application is applied for quite a long time since Arduino is widely
choosen for its convenience and cheap in price.
Despite of its prevalent, Arduino is not strong at dealing with signal
processing, open-sourced libraries are shown with low precisions…
The question was made up: How to combine the simplicity of Arduino and
the precision of a scientific software together to reach higher levels of
experiments and analysis. That’s how combinations of Arduino and
LabVIEW or Matlab were founded.
3.2 Hardwares:
You just need Arduino UNO/Arduino Mega2560 with cable.
3.3 Softwares:
First, install NIVISA modules.
Download LIFA library to interface Arduino with LabVIEW.
Extract files into a folder.
Open LIFA_Base.ino.
51
Plug cable to your PC and upload code. Leave the code there, don’t do
anything.
Download VI Package Manager on www.ni.com and install.
Figure 54 VIPM
After it’s finished, go to Block Diagram Panel, Right-Click and you will see
Arduino Palette.
52
Watch some examples in the palette and you can figure how we can start
working with it.
This is my work.
Figure 57 My Example
Figure 58 Results
53
**Small exercises:
1. Show temperatures from LM35.
2. Pulse generation from LabVIEW to pin 13 on Arduino.
3. Work in groups, find a way to plot data from a Vibration sensor on
Frequency Domain.
4. Work in groups, when a car is running straight, how to change its
directions? You will receive small gifts from teacher if you can change
its directions smoothly. If you can adjust, set the output to a digital pin
on Arduino.
CHAPTER 4: REFERENCE
This document is for free but if you are mentioning some of the contents inside this lecture, please remember to leave a reference to some people in
this chapter.
54