0% found this document useful (0 votes)
17 views113 pages

Chap 3

Uploaded by

osamaotako09876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views113 pages

Chap 3

Uploaded by

osamaotako09876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 113

Programming with

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

2. Mathematical representation of the issue:


-It means to give the perception of the mathematical question of the
compatibility of inputs and outputs
- in other words linking parameters of the problem
-Creating mathematical formula

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

6. Entering the program and data to the computer

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

The arrow shows the direction of next step


Expression or processing or
assigning a value to variable Connection

Comment
Example 4

Create a LabVIEW program which prints “hello world”


Example 4
Create which prints the solution of the following equation f ( x)  a  x  b
a ,b are real numbers
Example 5
Create which prints the solution of the following equation f ( x)  a  x  b
a ,b and x are integer numbers
Is the solution presented in example 4 presents a solution for
all cases of the problem?

No

How to avoid –inf, inf, NaN, errors ?

How to write a perfect solution of this problem?


Improving Example 4
Start

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 a0

x ← -b/a

Print "x=",x

End
Improving Example 4: part 2
Start

Print “a="

Input a

Print “ b="

Input b

N
if a0

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

- Adjusting the level of the tank using adjustment system


-Check the level of the tank
-If the level reach 7m, switch on the pump
Improving Example 7
Design a LabVIEW program which calcultes z from the following expression

1  x, x  a;

z   x 2 , a  x  b;
2 x , x  b

Example 7 nested condition

Find the max of three numbers


Switch statement: Multi if and else
Example 7:
Switch statement: Multi if and else
Formula node

Evaluates mathematical formulas and expressions similar to C.


When you work with variables, remember the following points:
•There is no limit to the number of variables or equations in a
Formula Node.

•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.

•You must wire all input terminals.


Expression Node
Example 8:
Three buttons A, B, C to be selected by a menu . Develop a LabVIEW VI to realized the process
Example 8b:
►Looping

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

Input of Arrays and matrices

Initialization of array and matrices

Operations with array and matrices


Adding array or matix to front panel
Creating input array

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

Develop a VI in which separates odd and even numbers (from 0 to n-


1) in two indicators
Example 13: Nested if with for loop

Develop a VI in which separates located in define interval


For example:
Numbers located in 2<x<8 will be shown in indicator 1
The numbers which are <2 and >8 will be displayed in indicator 2
Example 14: Nested if with for loop

Develop a VI in which does the following


If i is odd then the presented I has a negative value
Else i will be presented as i^2

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

Develop a VI in which separates odd and even numbers (from 0 to n-


1) in two indicators
Example 14: Nested if with for loop

Develop a VI in which does the following


If i is odd then the presented I has a negative value
Else i will be presented as i^2

If i odd -I
If i even  i^2
Operations with Array

Size of array
Operations with Array

Obtaining an element with a given index


Operations with Array

Max and Min


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

You might also like