Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables Read...

12
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables Read Bishop, Sections 5.6 to 5.12. Lab #8 and Homework #8 due next week. Quiz #4 next week

Transcript of Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables Read...

Page 1: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

EET 2259 Unit 8Other Structures; Local Variables

Read Bishop, Sections 5.6 to 5.12.

Lab #8 and Homework #8 due next week.

Quiz #4 next week

Page 2: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Review: Structures Structures control the flow

of a program’s execution. We’ve looked at:

For Loops While Loops Case Structures Sequence Structures (flat or

stacked) This week we’ll look at:

Formula Nodes Diagram Disable Structures Local Variables Global Variables

Page 3: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Entering Formulas

You can perform just about any mathematical calculation using LabVIEW’s built-in arithmetic functions on the Functions >> Mathematics palette.

Example:

But for long, complicated formulas, there’s an easier way, called a Formula Node.

Page 4: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Formula Node

The Formula Node lets you type formulas using the same syntax used in C or C++.

Formulas must end in a semicolon (;). To raise a number to a power, type **. For

example, to set y equal to x4, type

y = x**4;

(Bishop, pp. 250-253)

Page 5: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Diagram Disable Structure

The Diagram Disable structure lets you disable specific sections of code on the block diagram.

It is similar to commenting out code in a text- based programming language.

(Bishop, p. 254)

Page 6: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Usefulness of Diagram Disable Structure

This structure is primarily useful as a debugging tool. If you’ve got some code that you know or suspect is not working correctly, you can temporarily disable that code while you test the rest of your program.

Eventually you’ll probably want to remove all diagram disable structures, after all of your code works correctly.

Page 7: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Example of Diagram Disable Structure

Page 8: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Local Variables

Local variables let you access front panel objects from more than one location in a single VI. They pass information between objects that can’t simply be connected with a wire.

(Bishop, p. 255)

Local variable

Page 9: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Creating Local Variables

To create a local variable, right-click the desired front panel object and select Create >> Local Variable.

(Bishop, p. 257)

Page 10: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Use Local Variables with Care

Since local variables are not inherently part of the LabVIEW dataflow execution model, overusing them or misusing them can make block diagrams difficult to read or create unpredictable situations.

(Bishop, p. 257)

Page 11: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Global Variables

Local variables are called local because they only let you pass data from one place to another within a single VI.

In LabVIEW you can also create global variables (not discussed in the text) that pass data between VIs running on the same computer.

Global variable

Page 12: Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 8 Other Structures; Local Variables  Read Bishop, Sections 5.6 to 5.12.  Lab #8 and Homework #8 due.

Floyd, Digital Fundamentals, 10th ed

Use Global Variables with Extreme Care

With global variables it can be very hard to see where data is going or where it’s coming from. Misusing them can make block diagrams very difficult to read and can create unpredictable situations.

LabVIEW provides better ways to pass data between VIs, but they’re more complicated and more difficult to set up than global variables.