1 / 32

Previously…

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. 28.09.2012. D. While Loops. Repeat (code); Until Condition met; End;.

rusty
Télécharger la présentation

Previously…

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Previously… • Wecreated a simulated temperature readerwhichalertsiftoo hot or toocold… • Download the solvedpracticetokeep in sync: • Thermostat.vi 28.09.2012

  2. D. While Loops Repeat (code); Until Condition met; End; LabVIEW While Loop Flowchart Pseudo Code 28.09.2012

  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 28.09.2012

  4. Practice • Add a STOP buttonto the previouspractice, then include everything in a whileloop in orderto stop the programwhen the user hit STOP. • Add a CHART and display the currentiterationnumber on it. • Please note: fromnow on the RUN CONTINOUSLY buttonwon’t beused, use the RUN buttoninstead. • AVOID HITTING THE ABORT BUTTON AT ALL COSTS!! 28.09.2012

  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 28.09.2012

  6. Practice • Please open again the previous vi. • Usingan input tunnel display the time the vi hasbeenactive (in seconds) and stop itwhensuchtimeis MORE THAN 20s or if the userhits the STOP button. • Thinkaboutthis: what are the differencesbetween a simplewire and a tunnel? Can a wire HOLD data? Can a tunnel? 28.09.2012

  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. • Addto the previouspractice the properwaitfunction in ordertoforce the looptimeto 200ms • Open task manager and run the vi again. • Addto the previouspractice the properfunction in orderto display a stringversionoftimeelapsed

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

  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 28.09.2012

  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 Loopcount terminal alwayscoerces to a 32-bit signedinteger Coercion Dot

  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 • Whatwillbe the resultdisplayed in A? in B? in C? When?Whatwillbe the contentof D? 28.09.2012

  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 For Loop • 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 28.10.2012

  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 28.09.2012

  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 28.09.2012

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

  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 28.09.2012

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

  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. 28.09.2012

  29. Practice • Create a newVIhaving the following block diagram • Whichvalueswillbedisplayedby A,B and C? 28.09.2012

  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 28.09.2012

  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 thermostatpracticeVI, • Insteadofgenerating a single temperature value per cycle, create a set of 100 samples, put them in anarray. • Display all the 100 samples on both the CHART and the GRAPH, whilecontrolling the booleanindicatorsonly on the AVERAGE of the array • Pleasetrytokeepyou block diagramastidyaspossible 28.09.2012

More Related