Lab VIEW Course 2 1 Course Map Course
Lab. VIEW Course 2 1
Course Map Course 1 First steps with Lab. VIEW Course 2 Course 3 Making a decision Controlling property Loops Creation of new VI and customization Arrays Project Modular programming Signal generation Saving data Analyzing and Data acquisition saving data Labview 2009 -2010 Express VI 2
Lesson 5 Make a decision TOPICS Function select Case Structures Formula Nodes Boolean and text format Labview 2009 -2010 3
Function “Select” Input for right decision output Input for false Datas take the specific road if decision « Right » Input for right Labview 2009 -2010 « False » output false Input for false output 4
Boolean Case Structure Example: Case Structures. If Temp Scale is TRUE, execute True case; • In the Structures if temp scale is FALSE, execute False subpalette of case. Functions palette • Enclose nodes or drag them inside the structure • Stacked like a deck of cards, only one case visible at a time Labview 2009 -2010 5
Create a Case Structures (1/3) 1. Select the case structure into the Function Palette 2. Insert the structure into D 3. Link data input/output to borderline of the case structure Each output must be connected in every case of the case structure Output connector : white => 1 case connector not linked (here the false one)
Create a Case Structures (2/3) 4. Link every output connector
Create a Case Structures (3/3) 5. Create the boolean condition
Exercise 5. 1 – User choice • Goal – 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 2009 -2010 9
Exercise 5. 1 – D solution with select function Labview 2009 -2010 10
Exercise 5. 1 – FP Labview 2009 -2010 12
Note As you can notice, when you change the unit, 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"… Labview 2009 -2010 13
Lesson 6 How to control properties of objects by programming TOPICS Property nodes Labview 2009 -2010 14
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 2009 -2010 15
How to create it ? Right click on the indicator Labview 2009 -2010 16
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 2009 -2010 17
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 2009 -2010 18
Exercise 6. 1 • Goal – 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" Labview 2009 -2010 19
Exercise 6. 1 - D °F : min = 0 max = 200 Labview 2009 -2010 °K : min = 100 max = 300 20
Exercise 6. 1 - FP Labview 2009 -2010 21
Lesson 7 Repetition and Loops TOPICS While Loops For Loops Accessing Previous Loop Data Labview 2009 -2010 22
Structures and Loops • Sequence • While • For • Case • Formula node
Sequence Structure • Execute the program in a specific order
While Loops Repeat (code); Until Condition met; End; Lab. VIEW While Loop Code Labview 2009 -2010 Flow Chart Pseudo 25
Select the Loop Condition Click the Conditional Terminal with the Operating tool to define when the loop stops Default: Stop if True Iteration Terminal Labview 2009 -2010 Conditional Terminal 26
For Loops N=100; i=0; Until i=N: Repeat (code; i=i+1); End; Lab. VIEW For Loop Flow Chart Pseudo Code Labview 2009 -2010 27
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 Labview 2009 -2010 28
Wait Functions Wait Until Next ms Multiple Functions» Ti me & Dialog palette Labview 2009 -2010 29
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 2009 -2010 30
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 Initial Value 0 Labview 2009 -2010 First Iteration 15 Value 1 Value 2 0 Value 1 Before Loop Begins 10 10 0 Value 2 Second Iteration Value 3 Final Value 15 Last Iteration 31
Additional Shift Register Elements 2. Rightclick the left terminal to add new elements Labview 2009 -2010 Previous values are available at the left terminals 1 loop ago 2 loops ago 3 loops ago Latest value is passed to right terminal 1. Rightclick the border for a new shift register 32
Exercise 7. 1 • Goal – 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 Labview 2009 -2010 33 connect chart for multiple plots, and especially the function “bundle”)
Waveform Charts Selected from the Controls» Graphs and Charts palette Labview 2009 -2010 34
Wiring to Charts Single-Plot Chart Multiple-Plot Chart Bundle function Labview 2009 -2010 35
Exercise 7. 1 - FP With simulation Labview 2009 -2010 36
Exercise 7. 1 - D Labview 2009 -2010 37
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 2009 -2010 38
Exercise 7. 1 complement 1 - D (only for the initialization of the chart history) Labview 2009 -2010 39
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 Labview 2009 -2010 40
Lesson 8 Arrays and data analyzing TOPICS Introduction to Arrays Auto Indexing Arrays Array Functions Polymorphism Labview 2009 -2010 41
Arrays • Collection of data elements that are of same type 31 • One or more dimensions, up to 2 elements per dimension • Elements accessed by their index; first element is index 0 index 10 -element array 0 1 2 3 4 5 6 7 8 9 1. 2 3. 2 8. 0 4. 8 5. 1 6. 0 1. 0 2. 5 1. 7 2 D array 0 0 1 2 3 4 5 6 1 2 3 4 Five row by seven column array of 35 elements Labview 2009 -2010 42
Array Controls and Indicators 1. Select the Array shell from the Controls palette 2. Place data object inside shell Add Dimension for 2 D arrays Labview 2009 -2010 43
Creating Array Constants 1. Select Array Constant shell from the Array subpalette 2. Place the data object in the array shell Labview 2009 -2010 44
Auto-Indexing • Loops can accumulate arrays at their boundaries with auto-indexing • For Loops autoindex by default • While Loops output the final value by default • Right-click on tunnel and enable/disable auto -indexing Labview 2009 -2010 Auto-Indexing Enabled Wire becomes thicker 1 D Array 0 1 2 3 4 5 Auto-Indexing Disabled Wire remains the same size Only one value (last iteration) is passed out of the loop 45
Creating 2 D Arrays 1 D Array 2 D Array 0 1 2 3 4 5 • Inner loop creates column elements • Outer loop stacks them into rows Labview 2009 -2010 46
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 2009 -2010 47
Exercise 8. 1 - D Labview 2009 -2010 48
Exercise 8. 1 - FP Labview 2009 -2010 49
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, Lab. VIEW enables auto-indexing in For Loops and disables auto-indexing in While Loops. • Polymorphism is the ability of a function to adjust to input Labview 2009 -2010 50 data of different data structures.
Wiring the Block Diagram Scalar 1 D Array 2 D Array Numeric Boolean String Dynamic Labview 2009 -2010 51
Lesson 9 Signal generation TOPICS Analog and digital signal generation Labview 2009 -2010 52
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 2009 -2010 53
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 2009 -2010 54
Exercise 9. 1 • Goal – Topic : Interface with LEDs and thermistance • Concepts – Analog and digital signal generation – LEDs alimentation : 0 -5 Volts • Homework – Step 1: Acquire temperature every 200 ms and define 2 controls for temperature limits T 0 and T 1. – Step 2 : When measured temperature is – less than T 0, light up LED 1 (green) with an intensity that depends on measured temperature. – greater than T 0 and less than T 1, light up LED 2 (yellow) as a warning, and stop lighting up LED 1 – greater than T 1, blink LED 3 (red), and stop lighting up LED 2 – Step 3 : create and save historical data (time and data) Labview 2009 -2010 55
Exercise 9. 1 - D Labview 2009 -2010 56
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 2009 -2010 57
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 58
Data to string Date/Time Date to string Concatenate chain Number to engineering string Concatenated chain
Exercise 10. 1 • Goal – 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 … 60
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 61
Lesson 11 Programming with Express VI TOPICS Save data Labview 2009 -2010 62
Exercise 11. 1 • Goal 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 63
Exercise 11. 1 - D Labview 2009 -2010 64
Exercise 11. 1 - F Labview 2009 -2010 65
- Slides: 64