Sunteți pe pagina 1din 18

LabVIEW

Lectures #3

Dept. of Mechanical and Industrial


Engineering
University of Toronto
18-06-2019
Implementing a VI

This lesson teaches you how to implement code in LabVIEW.

1. These skills include designing a user interface,


2. Choosing a data type,
3. Documenting your code,
4. Using looping structures such as While Loops and For Loops,
adding software timing to your code,
5. Displaying your data as a plot,
6. And making decisions in your code using a Case structure.
A. Designing Controls and Indicators

In the design phase of the software development method, you


identify the inputs and outputs of the problem.

Inputs for the design can come from the following actions:

• Acquiring from a device such as a data acquisition device or a


multi meter
• Reading directly from a file
• Manipulating controls on the front panel

1. You can display the inputs of the problem on the front panel with
controls, such as numeric, boolean, or string controls, but not all
input appears on the front panel.

2. You can display the outputs of the problem with indicators, such as
graphs, charts, or LEDs, or log the outputs to a file. You also can
output data to a device using signal generation.
Labels:

Make sure to label controls and indicators clearly.

These labels help users identify the purpose of each control and
indicator.

Also, clear labeling helps you document your code on the block
diagram.
While Loops

Similar to a Do Loop or a Repeat-Until Loop in text-based programming


languages, a While Loop, shown in Figure3-12, executes a sub diagram
until a condition occurs.
For Loops

A For Loop, shown as follows, executes a sub diagram a set number


of times.
Figure3-17 shows a For Loop in LabVIEW, a flowchart equivalent of
the For Loop functionality, and a pseudo code example of the
functionality of the For Loop.
Timing a VI

When a loop finishes executing an iteration, it immediately


begins executing the next iteration, unless it reaches a stop
condition.

Wait Functions

Place a wait function inside a loop to allow a VI to sleep


for a set amount of time.

This allows your processor to address other tasks during


the wait time.

Wait functions use the millisecond clock of the operating


system.
Data Feedback in Loops

When programming with loops, you often must access data


from previous iterations of the loop in LabVIEW.

For example, if you are acquiring one piece of data in each


iteration of a loop and must average every five pieces of data,
you must retain the data from previous iterations of the loop.

Shift Registers

Shift registers are similar to static variables in text-based


programming languages.

Use shift registers when you want to pass values from


previous iterations through the loop to the next iteration.

A shift register appears as a pair of terminals directly opposite


each other on the vertical sides of the loop border.
Initializing Shift Registers
Initializing a shift register resets the value the shift register passes to the
first iteration of the loop when the VI runs.

Initialize a shift register by wiring a control or constant to the shift


register terminal on the left side of the loop, as shown in Figure3-24.

If you do not initialize the shift register, the loop uses the value
written to the shift register when the loop last executed or, if the
loop has never executed, the default value for the data type.
Stacked Shift Registers

Stacked shift registers let you access data from previous loop
iterations.

Stacked shift registers remember values from multiple previous


iterations and carry those values to the next iterations.
Plotting Data—Waveform Chart

The waveform chart is a special type of numeric indicator that


displays one or more plots of data typically acquired at a constant
rate.

Waveform charts can display single or multiple plots.


Case Structures

A Case structure has two or more sub diagrams, or cases.

Only one sub diagram is visible at a time, and the structure executes only
one case at a time.

An input value determines which sub diagram executes.

The Case structure is similar to switch statements or if...then...else


statements in text-based programming languages.
Integer Case Structure

Add (0)

Subtract (1)
Quiz

1-If an input to a function is marked with a red dot (known as a


coercion dot), what does the dot indicate?

a. Data was transferred into a structure.


b. A For Loop was configured with a conditional terminal.
c. A For Loop iteration terminal is unwired.
d. The value passed into a node was converted to a different
representation.
2-Which structure must run at least one
time?
a. While Loop
b. For Loop

3-Which is only available on the block diagram?


a. Control
b. Constant
c. Indicator
d. Connector pane
Assignment 3: Question # 1

Front Panel
Write a program in LabVIEW as shown in the
screen shots of Front Panel and Block
Diagram to generate Sine and Cosine of an
angle X where 0 < X < 360.

You can save your LabVIEW program file in


the following format:
“Your name Initials-DDMMYYYY-3-1.vi”

Block Diagram
Assignment 3: Question # 2
The Question 1 is further expanded to compute the amplitude and phase of the wave
form graph of Sine and Cosine output. Screen shot of the Block Diagram of extended
Portions 5 and 6 of the Sequence are given here.
Portion Portion Portion

“Inverse Tangent”
Assignment 3: Question # 2
Write a program in LabVIEW as shown in the screen shots of Front Panel and Block Diagram to
compute the generated Sine and Cosine of an angle X where 0 < X < 360.

You can save your LabVIEW file in the following format:


“Your name Initials-DDMMYYYY-3-2.vi”
Front Panel

Block Diagram

S-ar putea să vă placă și