Chapter 2 LabVIEW

27
1 Chapter 2 LabVIEW Dr. Minhhuy Le 606-A4, EEE, Phenikaa Uni. [email protected]

Transcript of Chapter 2 LabVIEW

Page 1: Chapter 2 LabVIEW

1

Chapter 2LabVIEW

Dr. Minhhuy Le

606-A4, EEE, Phenikaa Uni.

[email protected]

Page 2: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni.

Chapter 21. LabVIEW Programming Development

2. Loops and Waveform Graphs

3. Data Files and Character Strings

4. Important Programming Structures: cases, shift registers...

Outline

2

Page 3: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni.

Outline

3

Sensor DAQ Algorithm

Display

Save data

DAQ Output

Load data

PC

Page 4: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni.

2.2 Loops and Waveform Graphs

4

While loop

While loops

Condition met?

Code

End

Repeat (code)Until condition met;End;

While (condition met):{Code;}

Flowchart Pseudo Code C code

Page 5: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 5

While loops

Right-click on Block diagram-> Structures-> While loop

2.2 Loops and Waveform Graphs While loop

Page 6: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 6

While loops

Left-mouse drag & drop While loopError ???

No Stop-condition

Iteration

2.2 Loops and Waveform Graphs While loop

Page 7: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 7

Example: generate a random value in range (0,1) and offset by a “Center numeric” valueBoolean to control stop of while loop

2.2 Loops and Waveform Graphs While loop

Page 8: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 8

While loop

Right-click on Block diagram-> Structures-> For loop

2.2 Loops and Waveform Graphs While loop

Page 9: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 9

For loop

Example: generate a random value in range (0,1) and offset by a “Center numeric” value

Numeric: number of loops“Loops” = “Numeric” - 1

2.2 Loops and Waveform Graphs For loop

Page 10: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 10

While loop <-> For loop

Right-click on the boundary of loop-> Replace with For Loop

2.2 Loops and Waveform Graphs For loop

Convert While -> For loop

Wire: error

Page 11: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 11

Tunnel Modes:Last valueIndexingConcatenatingConditional

2.2 Loops and Waveform Graphs For loop

Right-click

Page 12: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 12

Tunnel Modes:Last valueIndexingConcatenatingConditional

2.2 Loops and Waveform Graphs For loop

Last value

Indexing: build array

Page 13: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 13

Timing:Tick Count: current time in ms

Wait: stop execution in an amount of timeWait until next ms

Multiple: Execute loop in an interval time

2.2 Loops and Waveform Graphs Timing

Page 14: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 14

Timing:Tick Count: current time in ms

Wait: stop execution in an amount of timeWait until next ms

Multiple: Execute loop in an interval time

2.2 Loops and Waveform Graphs Timing

Interval = 100ms

Page 15: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 15

Case structure = If, else

2.2 Loops and Waveform Graphs Case structure

True

False

Page 16: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 16

Waveform graphs:Right click on Front panel -> Modern -> GraphChartGraphXY Graph3D Graphs...

2.2 Loops and Waveform Graphs Waveform graphs

Page 17: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 17

Waveform Chart: Update by a single value

2.2 Loops and Waveform Graphs Waveform graphs

Page 18: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 18

Waveform Chart: Click on Waveform graph variable on Block diagram - > Ctrl + H -> Show Context Help -> Input data to the graph

2.2 Loops and Waveform Graphs Waveform graphs

Ctrl + H

N points-> N Charts

Page 19: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 19

Waveform Chart: Plot legend can be adjust plot styles, color, line style, line width ....

2.2 Loops and Waveform Graphs Waveform graphs

Plot legend Multiple plot -> multiple legends

Plot properties

Page 20: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 20

Waveform Graph: Input an array

2.2 Loops and Waveform Graphs Waveform graphs

Single value1D array

Page 21: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 21

XY Graph: Input 2 arrays: x array, y array -> BundleMultiple bundles -> Multiple XY Graphs

2.2 Loops and Waveform Graphs Waveform graphs

Bundle

Page 22: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 22

Data types on Wires:Different data types cannot be wired

2.2 Loops and Waveform Graphs Waveform graphs

Page 23: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 23

3D Graphs: surface, mesh, surface graph ...

2.2 Loops and Waveform Graphs 3D graphs

Plot helper-> Input data

Plot variable: display

Empty 3D surface graph

Page 24: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 24

2.2 Loops and Waveform Graphs 3D graphs

3D Graphs: Example

Data generationPlot helper

Display

Page 25: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 25

2.2 Loops and Waveform Graphs 3D graphs

Find examples:On an VI -> Help-> Find Examples...-> Enter keyword(s)

Page 26: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 26

2.2 Loops and Waveform Graphs 3D graphs

Graph example coding: x = a*sin(2*pi*f*t + phi) + b

Sin waveform generator

Waveform graph

Page 27: Chapter 2 LabVIEW

Minhhuy Le, EEE, Phenikaa Uni. 27

2.2 Loops and Waveform Graphs Summary

Summary:• For & While loops• Case structure (if/else)• Waveform chart• Waveform graph• XY graph• 3D Graphs

Homework: x = a*cos(2*pi*f*t - phi) + b• Waveform chart in while/for loop• XY graph: x-axis: time t; y-axis: x value