Presentation is loading. Please wait.

Presentation is loading. Please wait.

LabVIEW Course Course 2.

Similar presentations


Presentation on theme: "LabVIEW Course Course 2."— Presentation transcript:

1 LabVIEW Course Course 2

2 Analyzing and saving data
Course Map Course 1 Course 2 Course 3 Making a decision First steps with LabVIEW Controlling property Loops Creation of new VI and customization Arrays Project Signal generation Modular programming Saving data Analyzing and saving data Data acquisition Express VI Labview

3 Lesson 5 Make a decision TOPICS Function select Case Structures
Formula Nodes Boolean and text format Labview

4 Datas take the specific road if decision
Function “Select” Input for right decision output Input for false Datas take the specific road if decision « Right » « False » Input for right right false output output Input for false Labview

5 Case Structures Boolean Case Structure Example:
If Temp Scale is TRUE, execute True case; if temp scale is FALSE, execute False case. Case Structures • In the Structures subpalette of Functions palette • Enclose nodes or drag them inside the structure • Stacked like a deck of cards, only one case visible at a time The Case structure allows you to choose a course of action depending on an input value. In the Structures subpalette of the Controls palette. Analogous to a case statement in Pascal or if-then-else statement in other languages. Like a deck of cards. You can see only one case at a time. Customers often think that when separate cases are shown, it means to create two or more case structures. Stress that you need only one case structure. (See next slide for example of this idea.) Labview

6 Create a Case Structures (1/3)
Select the case structure into the Function Palette Insert the structure into D Link data input/output to borderline of the case structure The Case structure allows you to choose a course of action depending on an input value. In the Structures subpalette of the Controls palette. Analogous to a case statement in Pascal or if-then-else statement in other languages. Like a deck of cards. You can see only one case at a time. Customers often think that when separate cases are shown, it means to create two or more case structures. Stress that you need only one case structure. (See next slide for example of this idea.) Each output must be connected in every case of the case structure Output connector : white => 1 case connector not linked (here the false one)

7 Create a Case Structures (2/3)
Link every output connector The Case structure allows you to choose a course of action depending on an input value. In the Structures subpalette of the Controls palette. Analogous to a case statement in Pascal or if-then-else statement in other languages. Like a deck of cards. You can see only one case at a time. Customers often think that when separate cases are shown, it means to create two or more case structures. Stress that you need only one case structure. (See next slide for example of this idea.)

8 Create a Case Structures (3/3)
Create the boolean condition The Case structure allows you to choose a course of action depending on an input value. In the Structures subpalette of the Controls palette. Analogous to a case statement in Pascal or if-then-else statement in other languages. Like a deck of cards. You can see only one case at a time. Customers often think that when separate cases are shown, it means to create two or more case structures. Stress that you need only one case structure. (See next slide for example of this idea.)

9 Exercise 5.1 – User choice Goal Concepts Homework Create a simple VI
Topic : display the generated temperature in the specific scale selected by user Concepts Make a decision with the “select function” and “case structure” Boolean, text and numeric formats Homework Open Gen_temp_conv.vi Step 1 : create a program to allow user to choose and select the unit of the generated temperature and display it in only one indicator. (using the select function) Step 2 : With the same method, display the unit (in text format) in another indicator. Save in “Gen_Simple_Choice.vi” Step 3 : replace the 2 functions “select” by only 1 case structure. Save as “Gen_case.vi” Labview

10 Exercise 5.1 – D solution with select function
Labview

11 Exercise 5.1 – D solution with case structure
Labview

12 Exercise 5.1 – FP Labview

13 Note As you can notice, when you change the unit, the thermometer scale is not necessarily well adapted. The ideal would be a scale which would change according to the unit chosen. In order to achieve this, you have to work on the intrinsic properties of the indicator. This requires the use of "property nodes"… Estimate completion time: 20 minutes. The exercise is easy, but since it will be the first VI that we actually create, it is good to allow ample time to explore the LabVIEW environment. Instructions: Build a VI that converts °C to °F. When run, the VI should take an input value (°C), multiply it by 1.8, add 32, and display the result (°F). The front panel should display both the input value and the result. Save the VI as Convert C to F.vi. Labview

14 Lesson 6 How to control properties of objects by programming
TOPICS Property nodes Labview

15 What is a property node ? Each objects that you use in Labview owns its intrinsic properties. It can be the "visibility", the "state" (active or not active), or for indicators the "scale"… Working on these properties inside a program lead to the use of "property nodes" allowing to edit or modify these different properties. Labview

16 How to create it ? Right click on the indicator Labview

17 How to modify it ? As default value the property is the visibility, but you can change it by right clicking on the property node and choosing another property. Labview

18 How to add another property node ?
You can create another property node by the same method, however a more simple solution exists. Indeed, once a property node has been created, you just have to pull down, and others property nodes are added… Pull down Property nodes automatically added If you want to change the properties added, you just have to refer the previous step. Labview

19 Exercise 6.1 Goal Topics Homework
Adjust the scale of temperature indicators by programmation Topics Use of property node Customization of user interface Homework Open “Gen_case.vi " Use property nodes to automatically adjust the scale of the temperature indicator according to the unit chosen. Save as “Gen_case_adjusted.vi" Estimate completion time: 20 minutes. The exercise is easy, but since it will be the first VI that we actually create, it is good to allow ample time to explore the LabVIEW environment. Instructions: Build a VI that converts °C to °F. When run, the VI should take an input value (°C), multiply it by 1.8, add 32, and display the result (°F). The front panel should display both the input value and the result. Save the VI as Convert C to F.vi. Labview

20 Exercise 6.1 - D °F : min = 0 max = 200 °K : min = 100 max = 300
Labview

21 Exercise FP Labview

22 Lesson 7 Repetition and Loops
TOPICS While Loops For Loops Accessing Previous Loop Data Labview

23 Structures and Loops Sequence While For Case Formula node

24 Sequence Structure Execute the program in a specific order
Dans les langages de base, le programme s’exécute dans l’ordre des lignes de code. Dans le flux de données, un nœud est exécuté quand les données sont valides sur tous ces terminaux d’entrée. Quelquefois il est difficile de déterminer exactement l’ordre d’exécution. Souvent, certains événements doivent se dérouler avant d’autres événements. Quand vous avez besoin de contrôler l’ordre d’exécution des codes dans votre diagramme, vous pouvez utiliser la structure Séquence. Structure Séquence : utilisée pour contrôler l’ordre dans lequel les nœuds seront exécutés dans un diagramme. Dans le sous-menu « Execution control » : ● Regarder le film comme une suite d’images. ● Utilisé pour exécuter le diagramme de façon séquentielle. ● Clic droit sur le bord pour créer une nouvelle « image ».

25 While Loops LabVIEW While Loop Flow Chart Pseudo Code Repeat (code);
Until Condition met; End; While Loops execute a sequence of events while a condition is True (analogous to a “Do...While” statement). While Loop functionality: A While Loop executes the code contained inside it until a Boolean False is passed to the conditional terminal. Thus, it always executes at least once. The iteration terminal contains the number of executions (zero-indexed). LabVIEW While Loop Flow Chart Pseudo Code Labview

26 Select the Loop Condition
Click the Conditional Terminal with the Operating tool to define when the loop stops Default: Stop if True Iteration Terminal Conditional Terminal Labview

27 For Loops LabVIEW For Loop Flow Chart Pseudo Code N=100; i=0;
Until i=N: Repeat (code; i=i+1); End; A For Loop executes the diagram inside its border for a predetermined number of iterations (analogous to a “For...Next” statement). Explain the difference between While Loops and For Loops: While Loops run until a condition is met. For Loops run a predetermined number of times. LabVIEW For Loop Flow Chart Pseudo Code Labview

28 Insert a loop (example with white loop)
1. Select While Loop 2. Enclose code to be repeated 3. Drop or drag additional nodes and then wire Place loops in your diagram by selecting them from the Structures palette of the Functions palette (demonstrate): When selected, the mouse cursor becomes a special pointer that you use to enclose the section of code you want to repeat. Click the mouse button to define the top-left corner, click the mouse button again at the bottom-right corner, and the While Loop boundary is created around the selected code. Drag or drop additional nodes in the While Loop if needed. Labview

29 Wait Functions Wait Until Next ms Multiple
Functions»Time & Dialog palette Take the time to carefully explain the above slide. This chart is also printed in the book; have them follow along on page 3-10. Show how this function times on a ms Multiple; not a definite passage of time. Show how you could lose some time on the first loop due to pre-loop code. Labview

30 Structure Tunnels Tunnels feed data into and out of structures.
The tunnel is a block that appears on the border; the color of the block is related to the data type wired to the tunnel. When a tunnel passes data into a loop, the loop executes only after data arrive at the tunnel. Data pass out of a loop after the loop terminates. Labview

31 Accessing Previous Loop Data – Shift Register
• Available at left or right border of loop structures • Right-click the border and select Add Shift Register • Right terminal stores data on completion of iteration • Left terminal provides stored data at beginning of next iteration 5 5 10 10 15 Initial Value Value 1 Value 2 Initial Value Final Value 15 Value 1 Value 2 Value 3 Shift registers transfer data from one iteration to the next: Right click on the left or right side of a For Loop or a While Loop and select Add Shift Register. The right terminal stores data at the end of an iteration. Data appears at the left terminal at the start of the next iteration. A shift register adapts to any data type wired into it. Stress why you need a shift register—to retain values from one iteration to the next. Explain the slide in detail. Go slowly and repeat yourself. Before Loop Begins First Iteration Second Iteration Last Iteration Labview

32 Additional Shift Register Elements
Right-click the left terminal to add new elements Previous values are available at the left terminals Right-click the border for a new shift register Latest value is passed to right terminal 1 loop ago 2 loops ago 3 loops ago You can configure the shift register to remember values from several previous iterations. Right click on the left terminal and choose Add Element to create additional terminals. Explain the slide: The shift register allows you to access values from the past three iterations if you have three terminals. This method is different from using separate shift registers: One shift register with added terminals is storing multiple previous values of one variable. Multiple shift registers maintain a single previous value of multiple variables. Demonstrate the difference between adding a shift register vs. adding an element to a shift register. Labview

33 Exercise 7.1 Goal Concepts Homework
Replace continuous mode running by a while loop Control data acquisition and display Concepts While loop, wait function, Tunnel structure, shift register Chart, Homework Open the vi that acquires a temperature with a choice stage for displaying the temperature either in Kelvin or Fahrenheit unit. Insert while loop with wait function in order to control the speed from UI Display in real-time generated temperature data with a chart (search for chart) Display separately the last acquired data with its right unit Insert shifts registers in order to average acquired signal over the 4 last acquisitions Display signal and averaged signal on the same chart (search for how to connect chart for multiple plots, and especially the function “bundle”) Save in « while.vi » Labview

34 Waveform Charts Selected from the Controls»Graphs and Charts palette
LabVIEW has three types of charts: Strip chart: Scrolling display. Scope chart: Retracing display. The plot is erased after reaching the right border of the plotting area. Sweep chart: Like the scope chart, but the plot is not erased. Instead, a vertical line marks new data and moves across the display as data is added. Place on the front panel by selecting the Graph subpalette of the Controls palette. Because less overhead is involved in retracing the plot, scope and sweep charts are much faster. To increase the speed of the strip chart, disable the X axis. Describe the graphic: A chart may have one trace or multiple traces. Labview

35 Wiring to Charts Single-Plot Chart Multiple-Plot Chart Bundle function
For a single plot, wire from the numeric control to the chart terminal. For multiple traces, bundle each number together and then wire to the strip chart. Open the chart example with the Example Wizard. It is important that students know that these examples are shipped with the package. If they have questions about how to wire to a strip chart, they have a good resource that shows all possible ways to display data on a chart. Transition to next topic: Now we will discuss topics related to plotting: chart properties and mechanical action of booleans. Bundle function Labview

36 Exercise FP With simulation Labview

37 Exercise D Labview

38 Exercise 7.1 : complement 1 Try to initialize the chart (i.e to delete the chart history) at each run of the VI. Try to adapt the y scale in function of the selected temperature unit Save it as « while_adjusted.vi » Labview

39 Exercise 7.1 complement 1 - D (only for the initialization of the chart history)
Labview

40 Summary Two structures to repeat execution: While Loop and For Loop
Loop timing controlled using Wait Until Next ms Multiple function, the Wait (ms) function, or the Time Delay Express VI. Feedback nodes and shift registers transfer data values from one iteration to the next Use shift registers only when more than one past iteration is needed Do not immediately display this slide. Suggested questions for class participation: What structure must ALWAYS run at least once? What structures are used to repeat execution of certain functions? How can you control the speed at which the loop executes? Describe the difference between the three types of charts. Why would you want to use a shift register? Why would you want to use a feedback node? How do you retain multiple values from previous iterations? Review the slide: The purpose of Lesson Four was to introduce LabVIEW structures. Structures control the flow of data in a VI. Labview

41 Lesson 8 Arrays and data analyzing
TOPICS Introduction to Arrays Auto Indexing Arrays Array Functions Polymorphism Labview

42 Arrays • Collection of data elements that are of same type
• One or more dimensions, up to 2 elements per dimension • Elements accessed by their index; first element is index 0 31 index 10-element array 1.2 3.2 8.2 8.0 4.8 5.1 6.0 1.0 2.5 1.7 2D array Arrays are lists of elements of the same data type. They are analogous to arrays in traditional languages. Arrays can have one or more dimensions. Arrays can have up to 2^31 elements per dimension. Actual array sizes that students can create is limited by memory. Elements are accessed by “index”. The index ranges from 0 to N-1 (N = number of elements in the array). Arrays are zero-indexed (first element is zero) in each dimension. A 2D array is analogous to a spreadsheet or table. Example: Temperature readings and time stamp. One column is time values, and the other column is readings. Point out element (2,3) and element (3,2) on the slide. Be careful to specify the element you really want. Example: The first element in an array is array (0), not array(1). 1 2 3 4 Five row by seven column array of 35 elements Labview

43 Array Controls and Indicators
1. Select the Array shell from the Controls palette 2. Place data object inside shell Creating arrays in LabVIEW: Choose Array from the Array and Cluster palette You can place any data type in an array shell except an array. You cannot have an array of arrays; use a 2D array instead. Two components: index and data object. Emphasize that this is a two-step process. Students often place only empty array shells on the front panel. Remind them they must place a data type inside the array shell. Demonstrate the following on your computer: Create a numeric array. Point out index and data object components. Show how to create a 2D array. Show how to display multiple array elements. Show that index elements always reference the upper-leftmost object in the array display. Show how elements in an array are initially “grayed-out,” indicating that a portion of the array has not been defined. Add Dimension for 2D arrays Labview

44 Creating Array Constants
1. Select Array Constant shell from the Array subpalette Creating array constants uses the same two-step process as a front panel array. Select an array constant from the Array subpalette of the Functions palette. Place a constant data type inside the empty array shell. Note again that the data types are “grayed-out” and must be manually defined if the user wants to store values in the array constant. 2. Place the data object in the array shell Labview

45 Auto-Indexing Auto-Indexing Enabled Loops can accumulate arrays at their boundaries with auto-indexing For Loops auto-index by default While Loops output the final value by default Right-click on tunnel and enable/disable auto-indexing Wire becomes thicker 1D Array Auto-Indexing Disabled Wire remains the same size For Loops and While Loops can index and accumulate arrays at their boundaries. This is known as auto-indexing. The indexing point on the boundary is called a tunnel. The For Loop default is auto-indexing enabled. The While Loop default is auto-indexing disabled. Examples: Enable auto-indexing to collect values within the loop and build the array. All values are placed in array upon exiting loop. Disable auto-indexing if you are interested only in the final value. Only one value (last iteration) is passed out of the loop Labview

46 Creating 2D Arrays Inner loop creates column elements
You can use two nested For Loops to create a 2D array. Auto- indexing must be enabled for both. Inner loop creates column elements. Outer loop creates row elements. Explain the different line thicknesses. Demonstrate on your computer: How to change indexing and line thickness. Enable Indexing in pop-up menu means indexing is currently disabled. The menu choice is the opposite of the current index mode. Students get confused about this feature. Inner loop creates column elements Outer loop stacks them into rows Labview

47 Exercise 8.1 Goal Create and anlyze table of datas Concepts
Tunnef structure with/without indexation function Datas generated by loop : real time value, last acquired value, all values Homework Open the last vi (while_adjusted.vi”) At the end of the program, display in a table, all generated value Analyze datas : number of datas, mean, RMS, Min, Max, Range Labview

48 Exercise D Labview

49 Exercise FP Labview

50 Summary Arrays group data elements of the same type. You can build arrays of numeric, Boolean, path, string, waveform, and cluster data types. The array index is zero-based, which means it is in the range 0 to n – 1, where n is the number of elements in the array. To create an array control or indicator, select an Array on the Controls»Array & Cluster palette, place it on the front panel, and drag a control or indicator into the array shell. If you wire an array to a For Loop or While Loop input tunnel, you can read and process every element in that array by enabling auto-indexing. By default, LabVIEW enables auto-indexing in For Loops and disables auto-indexing in While Loops. Polymorphism is the ability of a function to adjust to input data of different data structures. Do not immediately display this slide. Suggested questions for class participation: What is an array? Where might it be used? How would I create a 2D array of numeric controls? How can a loop create an array? Which loops can be used to do so? What does “polymorphic” mean? Labview

51 Wiring the Block Diagram
Scalar 1D Array 2D Array Numeric Boolean String Not a complete list of data types; just ones that are used frequently through this course. Explain that in LabVIEW, you use wires to connect multiple terminals together to pass data in a VI. The wires must be connected to inputs and outputs that are compatible with the data that is transferred with the wire, therefore understanding the different data types is key to correct wiring. Explain the difference in colors and thicknesses. Explain that arrays and strings will be covered later in the course. Also, dynamic data type does not change width based on contents. Students are often looking for a more detailed list of all the data types in LabVIEW. If they ask about that, point them to the Help >> VI, Function, & How-To Help… On the Index Tab, search for data types and double click on the keyword to get a display on all of the data types and terminal representations in LabVIEW. Dynamic Labview

52 Lesson 9 Signal generation
TOPICS Analog and digital signal generation Labview

53 Steps for creating an generation task
How to create a task to generate a tension ? In Diagram, open Function Palette Express > Input > Assistant DAQ Analogous signal Générer un signal > Sortie analogique > Tension Digital signal Générer un signal > Sortie numérique > Sortie de ligne (1 Voie) ou port (plusieurs voies) Labview

54 Steps for creating an generation task
How to create a task to generate an digital tension ? In Diagram, open Palette de fonction Express > Entrées > Assistant DAQ Générer un signal > Sortie numérique > Sortie de ligne (ou port) Labview

55 Exercise 9.1 Goal Concepts Homework
Topic : Interface with LEDs and thermistance Concepts Analog and digital signal generation LEDs alimentation : 0-5 Volts Homework Step 1: Acquire temperature every 200ms and define 2 controls for temperature limits T0 and T1. Step 2 : When measured temperature is less than T0, light up LED1 (green) with an intensity that depends on measured temperature. greater than T0 and less than T1, light up LED2 (yellow) as a warning, and stop lighting up LED1 greater than T1, blink LED3 (red), and stop lighting up LED2 Step 3 : create and save historical data (time and data) Labview

56 Exercise D Labview

57 Lesson 10 Data saving TOPICS How to use several String functions
About file I/O operations How to use the high-level File I/O Vis How to format text files for use in spreadsheets Labview

58 High-level File I/O VIs
Write to Spreadsheet File Read from Spreadsheet File Write Characters to File Read Characters from File Read Lines from File Write to Spreadsheet File: Converts a 1D or 2D array of numbers to a single-precision, tab-delimited string and writes the string to an ASCII file. Useful for quickly creating ASCII spreadsheet files as in the last slide. Read from Spreadsheet File: Reads a tab-delimited ASCII file and converts the data back to a 1D or 2D array of numbers. Useful for reading data created with Write to Spreadsheet File, or data saved as an ASCII file from a spreadsheet program. Write Characters to File: Writes a character string to a file. Read Character from File: Reads a character string from a file. Read Lines from File: Read a specified number of lines from an ASCII file. All of the high-level VIs take care of opening/creating/replacing the file, reading/writing the file, and closing the file in one VI.

59 Data to string Date/Time Date to string Concatenate chain
Concatenated chain Number to engineering string Concatenated chain

60 Exercise 10.1 Goal Concepts Homework
Save temperature acquisitions into file Concepts Save datas into file Homework Open the last vi Save datas and time into spreadsheet file Save VI in « 13_Savefile.vi » and read data from a new vi …

61 Summary Use the File I/O VIs and functions located on the Functions»File I/O palette to handle all aspects of file I/O. When writing to a file, you open, create, or replace a file, write the data, and close the file. Similarly, when you read from a file, you open an existing file, read the data, and close the file. To access a file through a dialog box, do not wire file path in the Open/Create/Replace File VI. To write data to a spreadsheet file, you must format the string as a spreadsheet string, which is a string that includes delimiters, such as tabs. Use the Format Into File function to format string, numeric, path, and Boolean data as text and write the text to a file Suggested questions for class participation: What are some uses of strings? How are files opened using the Intermediate File I/O functions? When is it preferable to write data to a file in ASCII format? In binary integer format? In what ways can you write to a spreadsheet file?

62 Lesson 11 Programming with Express VI
TOPICS Save data Labview

63 Exercise 11.1 Goal Concepts Homework
Simulate, analyze and save only using Express VIs Concepts Express VI Homework Create a new vi that generates 2 signal independantly, filters the signal, indicates by a warning indicator if the signal amplitude exceeds a certain limit, and records the data when user ask. The speed of execution have to be controlled. Only with Express VIs

64 Exercise D Labview

65 Exercise F Labview


Download ppt "LabVIEW Course Course 2."

Similar presentations


Ads by Google