Chap 3
Chap 3
LabVIEW
Basic of LabVIEW
►Introduction to programming
► Linear programming
►Basic of Flowchart
►conditional programming
►Looping
►Timing
Introduction to programming
1. Problem Formulation
-Formulation of the matter is properly resolved,
-re-writing the problem in a form suitable to computing concept
3. Preparation of Algorithm
This means the sequence of operations providing the solution of the
problem and obtaining the results
4. Selecting a programming language
In this stage the algorithm is transformed into a program or “code “
5. Preparation of initial data
7. Debugging
•Errors
•Expressions
•Data
8. Testing
Methods of description of a solution of a problem
in words
- The description of the solution is presented in sentences
- The sequence of operations that leads to solve the problem are presented in steps
Using Flowchart
- Each operation is presented in a geometric shape
- The sequencing is achieved by connectors
- it is readable for anyone
Calling
Overview of Flowchart
start end Condition
output
input loop
Comment
Example 4
No
Print “a="
Input a
Print “ b="
Input b
Y
if a=0
x ← -b/a
Print "x=",x
End
Improving Example 4 :part1
Start
Print “a="
Input a
Print “ b="
Input b
N
if a0
x ← -b/a
Print "x=",x
End
Improving Example 4: part 2
Start
Print “a="
Input a
Print “ b="
Input b
N
if a0
x ← -b/a
Print "x=",x
End
Example 6:
Level Control and Alarm system
Improving Example 6
Design a LabVIEW program which does the following
1 x, x a;
z x 2 , a x b;
2 x , x b
Example 7 nested condition
•No two inputs and no two outputs can have the same name, but
an output can have the same name as an input.
•You can declare and use a variable inside the Formula Node
without relating it to an input or output wire.
For Loop
Start index
End index
Condition
Operation or statement(s) in the loop
For Loop in C/C++
Increasing i decreasing i
for(i=0;i<N;I++) for(i=N;i>0;I--)
{ {
//Loop body
//Loop body
}
}
For Loop in LabVIEW
For Loop in LabVIEW
Example 9: simple used of for loop
Develop a VI which presents the number from 0 to 10, start index =0, default
Example 9: simple used of for loop (delay to see the numbers)
Develop a VI which presents the number from 0 to 10 (start index =0 ,default)
Understanding Shift register
While dealing with loops, you may have situations where the tracking of
previous data elements is needed. LabVIEW provides shift registers to
accomplish such tasks.
You can create shift registers by right clicking on the border of either For Loop or
While Loop and selecting Add Shift Register.
Shift registers are local variables that feed back or transfer values from the
completion of one iteration to the beginning of the next.
By selecting Add Shift Register from the loop border pop-up menu, you can create a
register anywhere along the vertical boundary only, as shown in the illustration..
Understanding Shift register
To initialize a shift register, wire a value from outside the loop to
the left terminal.
If you do not initialize the register, the loop uses as the initial value
the last value inserted
Example 10: sum of the numbers from 1 to 10
Example 11: Multiple shift register
Arrays and matrix
1
2
3
Creating input array
1
2
3
Example 12: initialize B From A
Example : Adding to arrays
Example : Plotting realitionship
Example 13: Odd and even numbers
If i odd -I
If i even i^2
Example 15: Nested if with for loop
sums the first N terms of the series (1+i^2). Where i is an integer varies from 0 to
infinity.
While Loop in LabVIEW
While loop
Count=0;
While (condition(s))
{
Statements;
Count++;
}
While loop
Count=0;
Do {
Statements;
Count++;
} While (condition(s))
Example 17: simple used of for loop (delay to see the numbers)
Develop a VI which presents the number from 0 to 10 (start index =0 ,default)
Example 18: sum of the numbers from 1 to 10
Example 19: Odd and even numbers
If i odd -I
If i even i^2
Operations with Array
Size of array
Operations with Array
Searching in array
Operations with Array
Sort an array
Initialization an array from for loop
Initialization an array from for loop
Displaying the elements of array an array from for loop
Sin Generator From Array
Sin Generator From Array
Design a LabVIew VI which Generts the following signals
Sin
Cos
Ramp
Square
Note:
1. use Loops and/or arrays
2. The user can select the type of produced signal
Operation with Matrix: adding to Matrix
Logic Operation
Operation with Matrix
Operations with Matrix
Determinant of matrix
Eigenvalues
Solving linear equations
Solving linear equations
Solving linear equations(Method1)
Solving linear equations (Method2)
Simulation of Models
Simulation of sensor Models
Simulation of sensor Models
Simulation of sensor Models
Polynomials P(x) = (x – r1)(x – r2)…(x – rn) = xn + Pn – 1xn – 1 + … + P1x + P0
Working with spreadsheets
Excel file
Working with spreadsheets
Working with spreadsheets
Working with spreadsheets
Working with textfiles
Working with textfiles
Circle
Circle
Circle