cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · web viewlabview handout 2....

12
LABVIEW HANDOUT 2 CHAPTER 2: THE FOR LOOP AND THE WAVEFORM GRAPH Open a Blank VI. Place a For Loop on the Block Diagram: Functions Palette>>Programming >>Structures>>For Loop The initial value of the Loop Iteration Terminal is zero, and increments by one integer each iteration. The Loop Count Terminal

Upload: ngominh

Post on 13-Feb-2018

230 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

LABVIEW HANDOUT 2

CHAPTER 2: THE FOR LOOP AND THE WAVEFORM GRAPH

Open a Blank VI. Place a For Loop on the Block Diagram:

Functions Palette>>Programming >>Structures>>For Loop

The initial value of the Loop Iteration Terminal is zero, and increments by one integer each

iteration. The Loop Count Terminal resides in the upper left-hand corner. The loop

terminates when i = N − 1. Place a Waveform Graph on the Front Panel:

View>>Controls Palette>>Modern>>Graph>>Waveform Graph

Page 2: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Change the x-axis label to x (radians) and the y-axis label to sin(x). On the Block Diagram,

move the Waveform Graph outside of the For Loop. Place a Sine Function icon in the For

Loop. Wire the Loop Iteration Terminal to the input of the Sine Function. Eliminate the red

Coercion Dot on the Sine Function input. Divide the Loop Iteration output (Sine Function

input) by 5. Create a constant for the input of the Loop Count Terminal equal to 100. Wire the

output of the Sine Function to the Waveform Graph.

Page 3: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Notice that the output wire of the For Loop is thick and orange, denoting a one-dimensional

array of double precision floating point numbers. A small box on the edge of the For Loop is

called the Auto-Indexed Tunnel. This accumulates the array of values. When the For Loop

completes its last iteration, it sends the array of numbers to the Waveform Graph. Run the

program.

Insert a Bundle Function on the wire that connects the For Loop and the Waveform Graph:

Right-Click>>Insert>>All Palettes>>Programming>>Cluster, Class, & Variant>>Bundle

Page 4: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word
Page 5: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Broken wires can be deleted by typing CTRL-B. Resize the Bundle to have three inputs by

pulling down on its lower edge.

Copy the constant 5 box by left-click highlighting the constant and then typing CTRL-C. Place

the cursor close to the Bundle and left-click. Then paste the constant using CTRL-V. Wire

constants to the top and middle inputs with values 0 and 0.2, respectively. Wire the output of the

For Loop to the bottom input of the Bundle. Wire the output of the Bundle to the Waveform

Graph. Notice the color of the output wire of the bundle has changed to pink. Use Show

Context Help to determine the meaning of the color and the inputs for the Waveform Graph.

Run the program.

Page 6: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Change the For Loop to a While Loop:

Right-Click>>Replace with While Loop

Page 7: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Insert a logical comparison function on the Block Diagram:

Functions Palette>>Programming>>Comparison>>Equal?

Bring the constant (100) into the While Loop and compare it to the Loop Iteration Terminal

using the Equal? Function. Wire the output of the Equal? Function to the Loop Condition

Terminal. This will stop the While Loop after 101 iterations.

Page 8: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Place an Array Indicator on the output wire of the While Loop:

Right-Click>>Create>>Indicator

Page 9: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Rerun the program. Resize the Array Indicator and examine the contents.

Place probes on several wires using the Probe Data Function:

View>>Tools Palette>>Probe Data

Page 10: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Rerun the program and observe the data. Delete the probes. On the Tools Palette, click on

Automatic Tool Selection. Change the constant 100 to 5. Press the Highlight Execution button

on the Block Diagram.

Rerun the program. Notice how the array of Sine Function data is stored at the Auto-Indexed

Tunnel at the edge of the While Loop until the iterations are complete.

Page 11: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word

Clean up the appearance of the Block Diagram and make it as compact as possible. Place your

name on the Front Panel. Print out the program using Microsoft Word by taking a screen shot of

the Front Panel and Block Diagram.

Page 12: cecs.wright.educecs.wright.edu/~sthomas/labviewhandout02.docx  · Web viewLABVIEW HANDOUT 2. CHAPTER 2: THE FOR LOOP AND THE WAVEFORM ... Print out the program using Microsoft Word