Presentation is loading. Please wait.

Presentation is loading. Please wait.

Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi.

Similar presentations


Presentation on theme: "Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi."— Presentation transcript:

1 Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi

2 D. While Loops LabVIEW While Loop Flowchart Pseudo Code 28.09.2012
Repeat (code); Until Condition met; End; Demonstrate creation of while loop: To create a While Loop complete the following: Select the While Loop from the palette Use the cursor to drag a selection rectangle around the section of the block diagram you want to repeat When you release the mouse button, a While Loop boundary encloses the section you selected Add block diagram objects to the While Loop by dragging and dropping them inside the While Loop LabVIEW While Loop Flowchart Pseudo Code

3 D. While Loops Iteration terminal: returns number of times loop has executed; zero indexed Conditional terminal: defines when the loop stops Iteration Terminal Conditional Terminal

4 Practice Add a STOP button to the previous practice, then include everything in a while loop in order to stop the program when the user hit STOP. Add a CHART and display the current iteration number on it. Please note: from now on the RUN CONTINOUSLY button won’t be used, use the RUN button instead. AVOID HITTING THE ABORT BUTTON AT ALL COSTS!!

5 D. While Loops – Tunnels Tunnels transfer data into and out of structures The tunnel adopts the color of the data type wired to the tunnel Data pass out of a loop after the loop terminates When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel

6 Practice Please open again the previous vi. Using an input tunnel display the time the vi has been active (in seconds) and stop it when such time is MORE THAN 20s or if the user hits the STOP button. Think about this: what are the differences between a simple wire and a tunnel? Can a wire HOLD data? Can a tunnel?

7 F. Timing a VI Why do you need timing in a VI?
Control the frequency at which a loop executes Provide the processor with time to complete other tasks, such as processing the user interface

8 F. Timing a VI – Wait Functions
A wait function inside a loop allows the VI to sleep for a set amount of time Allows the processor to address other tasks during the wait time Uses the operating system millisecond clock

9 F. Timing a VI – Elapsed Time Express VI
Determines how much time elapses after some point in your VI Keep track of time while the VI continues to execute Does not provide the processor with time to complete other tasks

10 Practice Open task manager and run the previous vi. Add to the previous practice the proper wait function in order to force the loop time to 200ms Open task manager and run the vi again. Add to the previous practice the proper function in order to display a string version of time elapsed

11 E. For Loops LabVIEW For Loop Flowchart Pseudo Code 28.09.2012 N=100;
Until i=N: Repeat (code;i=i+1); End; LabVIEW For Loop Flowchart Pseudo Code

12 E. For Loops Create a For Loop the same way you create a While Loop
If you need to replace an existing While Loop with a For Loop, right-click the border of the While Loop, and select Replace with For Loop from the shortcut menu The value in the count terminal (an input terminal) indicates how many times to repeat the subdiagram

13 E. For Loops – Conditional Terminal
You can add a conditional terminal to configure a For Loop to stop when a Boolean condition or an error occurs

14 E. For Loops – Numeric Conversion
The number of iterations a For Loop executes must be specified in nonnegative integers If you wire a double-precision, floating-point numeric value to the count terminal, LabVIEW converts the larger numeric value to a 32-bit signed integer

15 E. For Loops – Numeric Conversion
Normally, when you wire different representation types to the inputs of a function, the function returns an output in the larger or wider format LabVIEW chooses the representation that uses more bits However, the For Loop count terminal always coerces to a 32-bit signed integer Coercion Dot If you use a signed integer with an unsigned integer, it will coerce to the unsigned integer. If you use an unsigned integer with a floating point, it will coerce to the floating point. If you use a floating point integer with a complex integer, it will coerce to the complex integer. If you use two numbers of the same type with different bit widths, LabVIEW will coerce to the larger of the two bit widths. However, the For Loop count terminal may work in the opposite manner. If you wire a double-precision, floating-point numeric value to the 32-bit count terminal, LabVIEW coerces the larger numeric value to a 32-bit signed integer. Although the conversion is contrary to normal conversion standards, it is necessary, because a For Loop can only execute an integer number of times. The For Loop count terminal will always coerce to a 32-bit signed integer data type.

16 E. For Loops – Numeric Conversion
Avoid coercion for better performance Choose matching data type Programmatically convert to the matching data type

17 Practice Reproduce the following block diagram What will be the result displayed in A? in B? in C? When? What will be the content of D?

18 E. For Loops – Conditional Terminal
For Loops configured for a conditional exit have: Red glyph next to the count terminal Conditional terminal in the lower right corner

19 E. For Loop/While Loop Comparison
Executes a set number of times unless a conditional terminal is added Can execute zero times Tunnels automatically output an array of data While Loop Stops executing only if the value at the conditional terminal meets the condition Must execute at least once Tunnels automatically output the last value

20 A. Arrays An array consists of elements and dimensions
Elements: data that make up the array Dimension: the length, height, or depth of an array An array can have one or more dimensions and as many as (231)–1 elements per dimension, memory permitting Consider using arrays when you work with a collection of similar data and when you perform repetitive computations

21 A. Arrays The first element shown in the array (3.00) is at index 1 and the second element (1.00) is at index 2 The element at index 0 is not shown in this image, because element 1 is selected in the index display The element selected in the index display always refers to the element shown in the upper left corner of the element display

22 A. Arrays – Creating Place an array shell on the front panel
Drag a data object or element into the array shell

23 A. Arrays – 2D Array Stores elements in a grid
Requires a column index and a row index to locate an element, both of which are zero-based To create a multidimensional array on the front panel, right-click the index display and select Add Dimension from the shortcut menu You also can resize the index display until you have as many dimensions as you want

24 A. Arrays – Initializing
You can initialize an array, or leave it uninitialized For initialized arrays, you define the number of elements in each dimension, and the contents of each element Uninitialized arrays have dimension but no elements

25 A. Arrays – Creating Constants
To create an array constant: Select an array constant on the Functions palette Place the array shell on the block diagram Place a constant in the array shell You can use an array constant to store constant data or as a basis for comparison with another array Array constants also are useful for passing data into a subVI

26 A. Arrays – Auto-indexing
If you wire an array to or from a For Loop or While Loop, you can link each iteration of the loop to an element in that array by enabling auto-indexing on tunnel The tunnel changes from a solid square to the image shown above to indicate auto-indexing

27 A. Arrays – Auto-indexing Input
For Loop executes a number of times equal to the number of elements in the array

28 A. Arrays – Auto-indexing Input
If the iteration count terminal is wired and arrays of different sizes are wired to auto-indexed tunnels, the actual number of iterations becomes the smallest of the choices. LabVIEW does not exceed the array size. This helps to protect against programming error. LabVIEW mathematical functions work the same way—if you wire a 10 element array to the x input of the Add function, and a 5 element array to the y input of the Add function, the output is a 5 element array. Although the for loop runs 5 times, the iterations are zero based, therefore the value of the Iterations indicators is 4.

29 Practice Create a new VI having the following block diagram Which values will be displayed by A,B and C?

30 A. Arrays – Auto-indexing Output
When you auto-index an array output tunnel, the output array receives a new element from every iteration of the loop Auto-indexed output arrays are always equal in size to the number of iterations

31 A. Arrays – Creating 2D Arrays
You can use two For Loops, one inside the other, to create a 2D array

32 Practice @HOME Open the thermostat practice VI, Instead of generating a single temperature value per cycle, create a set of 100 samples, put them in an array. Display all the 100 samples on both the CHART and the GRAPH, while controlling the boolean indicators only on the AVERAGE of the array Please try to keep you block diagram as tidy as possible


Download ppt "Previously… We created a simulated temperature reader which alerts if too hot or too cold… Download the solved practice to keep in sync: Thermostat.vi."

Similar presentations


Ads by Google