Lecture -1 Introduction LabVIEW Basics Customizing front panel objects Lecture -2 Data flow programming Documentation Lecture -3 Front panel object manipulation (graphs) Modular Programming: Temperature Conversion VI and Thermometer VI Lecture -4 Repetition and Loops (While Loop) Structure Tunnels Lecture -5 Repetition and Loops (For Loop) Feedback Node Shift Registers Lecture -6 Arrays 1-D and 2-D arrays Auto-indexing Loop Count control Challenge -1 (homework) Challenge -2 (homework) Lecture -7 Clusters Short note on MathScript Sample applications L e c t u r e - 1 LabVIEW Basics LabVIEW is a graphical programming language you can use to solve various problems. Having a strong problem solving skills and a strong background in mathematics and engineering/engineering technology principles are essential to create solutions in LabVIEW LabVIEW stands for: Laboratory Virtual Instrument Engineering Workbench (LabVIEW). In order to be successful, it is important to develop habits of planning, writing proper codes, and documenting code. Throughout this course, we will learn many different capabilities of labVIEW. Towards the end of semester, each team will implement and expand on their knowledge by demonstrating a successful project. Lesson -1 Navigating LabVIEW This lesson introduces how to navigate the LabVIEW environment. This includes using menus, toolbars, palettes, tools, help, and common dialog boxes of LabVIEW. Additionally, you will learn how to run a VI and gain general understanding of a front panel and block diagram. At end of this lesson, you will create a simple VI that acquires, analyzes, and presents data. Topics: 1. Virtual Instrument - VI 2. Parts of a VI 3. Starting a VI 4. Project Explorer 5. Front Panel Window 6. Block Diagram window 7. Searching for controls, Vis, and functions 8. Selection tool 9. Data Flow 10. Creating a simple VI A. Virtual Instruments (Vis) LabVIEW programs are called virtual instruments, or VIs, because their appearance and operation imitates physical instruments, such as oscilloscopes and multimeters. LabVIEW contains a comprehensive set of tools for acquiring, analyzing, displaying, and sorting data, as well as tools to help troubleshoot code. In LabVIEW, you use projects to group together LabVIEW and non-LabVIEW files, create build specifications, deploy and download files to targets, and build applications and shared libraries. More on LabVIEW projects later on in the course. Will refer to them when we build applications. B. Parts of a VI LabVIEW VI contains three main components: The front panel, the block diagram, and the icon/connector pane. Front Panel Window The front panel window is the user interface for the VI. See Figure 1-1 below Figure 1-1 Front Panel You create the front panel window with controls and indicators. These controls and indicators are the interactive input and output terminals of the VI, respectively. Block Diagram Window After creating the front panel window, you add code using graphical representations of functions to control the front panel objects. Figure 1-2 shows an example of a block diagram window. The block diagram window contains the graphical source code. Front panel objects appear as terminals on the block diagram. Both, the front panel and the block diagram, contain toolbars, palettes, and short-cut menus to aid in creating a VI Figure 1-2. Block Diagram Icon and Connector Pane The icon and connector pane allows one to use and view a VI in another VI. A VI that is used in another VI is called sub VI. Think of text based programming (subroutines, sub-functions, modules) In order to use a VI as a sub VI, it must have an icon and connector pane. Every VI displays an icon in the upper right corner of the front panel window and block diagram window. An example of a default icon is shown here . When you start a blank VI, look at the top right corner of the front panel window. You should see similar to the icon shown here. To use a VI as a sub VI, you will need to build the conne ctor pane shown here. on connector pane later in the course. . More C. Starting a VI When you launch LabVIEW, the Getting Started window appears. Use this window to create new VI and projects, select among the most recently opened LabVIEW files, find examples, and search LabVIEW help. You can also access information and resources to help you learn about LabVIEW such as specific manuals, help topics, and resources at ni.com The Getting started window closes when you open an existing file or when you create a new VI. You can always display the window by selecting View>>Getting Started Window Figure1- 3. LabVIEW Getting Started Window You can configure LabVIEW (though not advised to do so) to open a new, blank VI on launch instead of displaying the Getting Started Window. Select Tools>>Options>>Environment>> then place a check mark in Skip Getting Started Window on Launch checkbox. Creating or Opening a VI or a Project You can begin in LabVIEW by starting from a blank VI or project. Opening an existing VI or project and modifying it, or opening a template from which to begin your new VI or project. Creating New Projects and Vis To open a new project from the Getting Started Window, select Empty Project in the New list. A new unnamed project opens. You can add files to it and save it. Just look at this and do nothing at this time. To open a new, blank VI that is not associated with a project, select Blank VI in the New list in the Getting Started Window. Creating a VI from a Template Select File>>New to display the New dialog box, which lists the built-in VI templates. Or, you can directly click on the New link in the Getting Started Window. Saving a VI To save a new VI, select File>>Save. If you have already saved your VI, select File>>Save As to access the Save As dialog box. From this dialog box, you can create a copy of the VI, or delete the original VI and replace it with a new one. Try this option in class. D. Front Panel Window When you open an existing VI, the front panel window of the VI appears. This is the user interface for the VI. Controls and Indicators. You create the front panel window with controls and indicators, which are interactive input and output terminals of the VI. Controls are knobs, push buttons, dials, and other input devices. Indicators are graphs, LEDs and other displays. Controls simulate instrument input devices and supply data to the block diagram of the VI. Indicators simulate instrument output devices and display data the block diagram acquires or generates. Numeric Controls and Indicators The numeric data type can represent numbers of various types, such as integer or real. The two common numeric objects are the numeric control and the numeric indicator. Note, objects such as meters and dials represent numeric data. Demo increment/decrement - Shape of control and indicator Boolean Controls and Indicators The Boolean data type represent data that has only two states, such as True and Fales (ON or OFF) Boolean objects simulate switches, push buttons, and LEDs Demo - Show vertical toggle switch - Round LED String Controls and Indicators The string data type is a sequence of ASCII characters. Use String controls to receive text from user such as password/user name. Use text indicators to display text to the user. The most common string objects are tables and text entry boxes. Demo table (control and indicator) Controls Palette The controls palette contains the controls and indicators used to create the front panel. You access the controls palette by selecting: View>>Controls Palette or by right clicking on the front panel. The controls palette is broken into various categories (subpalettes) You can expose all categories Demo – Controls Palette and categories Shortcut Menus All LabVIEW objects have shortcut menu associated with them. They are right click menus You can use the shortcut menu to change the appearance or behavior of front panel or block diagram objects. Demo – visible and digital display Property Dialog Box Objects in the front panel window have properties associated with them Demo – show it Front Panel Window Toolbar - Demo some features Back to Top L e c t u r e - 2 Ex -1 Acquire a Signal (in class) >> Launch LV >> NEW>> NEW VI >> VI from a Template>> Generate and Display - Notice the preview >> click OK Examine the front panel and block diagram Run the VI Stop the VI Adding a control to Front Panel: Select the Knob control in the numeric control subpalette and place it on the front panel. Save AS the VI in n:\MyWork\Acquiring a signal.vi Changing Signal Type The simulated signal icon on the block diagram represents Simulated Signal Express VI. The default simulated signal is a sine wave. >> right click on the Simulated Signal Express VI and select properties >>Select Sawtooth and press OK >>Expand the Simulated Signal Express VI to show to show other inputs/outputs. >>connect the Knob numeric control to the amplitude input >> Save the VI (Click Save) Run and explore the VI Modifying the Signal >> on the block diagram, delete the wire between the Simulated signal Express VI and the Waveform Graph >>Show the functions palette >>Select the Scaling and Mapping Express VI (typically found in Arithmetic & Comparison Palette) >> The configure Scaling and Mapping dialog box automatically opens >> change the slope to 10 and click OK >>connect the sawtooth signal output to the scaling input and the scaling output to the waveform graph. Cleanup the wiring >>Run the VI and notice the amplitude change. Stop the VI Now, to merge two signals: >> connect the sawtooth directly to the waveform graph (notice the Merge Signals Function appears automatically) >> Save the VI Customize the Knob >> display the Knob Properties >>In the label section on the appearance tab, delete the label knob and type Amplitude. Also, on the scale tab, change the maximum value to 5 Note, we could have done this directly on the front panel using Text tool. >> Save the VI >> Explore the knob properties by, for example, changing the Marker Text Colors. However, click Cancel Customizing the Waveform Graph >> move over to the graph legend (on top) in the front panel >> expand the legend to show the legend for the second plot >>display the graph properties >>on the plot tab, select sawtooth, click the line color, select a new line color >>repeat for sawtooth (scaled) select a new line color >> check the box: “Do not use waveform names from plot name” >>in the name tex box, change the name to Scaled Sawtooth >>click ok Run the VI, the save it o Dataflow programming LabVIEW follows a dataflow model for running VIs. A block diagram node executes when all of its inputs are available. Once a node completes execution, it supplies its data to the output terminals and passes the output data to the next node in the dataflow path. demoe x+y then result is subtracted (z – 50) now, demo two parallel functions Here, it is not possible to know because the inputs to the add and divide are available at the same time and the random function has no inputs. In situations where one code segment must execute before another, and no data dependency occurs between the segments, use other programming methods. This is future item Back to Top Ex -2 – Dataflow example. (in class) >>select help>>find example>>click search filter >> select filter (some versions may have to select filtering)>> find the example VI called express filter.vi, open it >>open the block diagram and click highlighted execution >>run Notice the data flow and see how the Tone Measurements VI cannot output data until it receives data from the filter express VI. LabVIEW Documentation and Resources Use the Context Help window, the labVIEW help, and the NI example finder to help you build and edit VIs. o Context Help Window The context help window displays basic information about labVIEW objects as you move the cursor over each object. <CTRL-H> for shortcut Back to Top L e c t u r e - 3 Ex -3-1 Reduce Sample - (In class work) Here, we are to use LabVIEW documentation resources to build a VI that generates a signal, reduces the number of samples in the signal, and displays the resulting data on the the front panel. >> start with a blank VI >>on the block diagram, bring up the functions palette and click the thumbtack to hold it. >> activate the Context Help, click on the input palette on the functions palette. Move the mouse to locate the Express VI that simulates a sine wave. [ select simulated signal and place it on the block diagram] >>move the cursor over the different items (amplitude, frequency,..) in the Configure Simulated signal dialog box and watch the context help. >>Configure the simulated signal to f = 10.7 Hz, and amplitude = 2. Watch how the “result preview” changes automatically. >> press OK >> on the block diagram, move the cursor over the simulated signal and watch the contents of the context help. >>save the VI as: Reduce Samples.vi Using LabVIEW Help to modify the signal >>Go to LabVIEW help, then click the search tab, type: sample compression >>double click the result Sample Compression to see the list >> read about the topic, once done reading, click “place on the block diagram” >> ensure the function is placed on the block diagram. A dialog box should open up automatically. >> configure the sample compression for a reduction factor of 25 using the mean of these values. >>close the Configure Sample Compression dialog box by clicking OK >> wire the sine output in the simulated signal VI to the Signals input in the sample compression VI >> Configure the lock diagram to look like the figure below. >> open the front panel. Notice the legend on the graph “plot 0” ?! >> run the VI and notice the legend adjusts to name automatically. >>Save the VI >>Place a while loop around the complete VI developed on the block diagram. >> control the speed of execution by inserting a 0.250 second time delay. Thus, the loop iterates every ¼ th of a second. This time will use the Time Delay Express VI found in the Execution Control palette (same place you found the while loop) >> Run the VI, click the Enable switch and see what happens. >> stop the VI >> Save the VI Using a Table to display data >> On the front panel, select the Express Table indicator. >> on the block diagram, move the express table VI inside the while loop and wire its signal input to the mean value of the Sample Compression Express VI >> display the front panel and run the VI >> click the Enable switch. The table displays the mean value every 25 samples. >> Stop the VI >> Experiment with the properties of the table – for example, change the number of columns to 1 Back to Top Modular Programming When a VI is used within another VI, it is called a sub VI. In this lesson, we are to learn how to build the icon and connector pane of a VI so that it is used as a sub VI. Exercise3-2 (In class work) >> create the following numeric control and indicator on the front panel. >> wire the items on the block diagram as shown >>To identify terminals on a function, right click the multiply function, and select Visible Items>> Terminal >> display the front panel >> save the VI as: Convert C to F.vi >> enter a number in the numeric control by using the operating tool or manually typing a number >>click run and observe the result. Icon and Connector Pane >> on the upper right corner of the front panel is an icon. Right click it and select Edit Icon >>double click the select tool and press delete >>double click the rectangle tool to redraw the border >>double click the text tool and change the font size to small >> using the text too, type C F (note, while the text is active you can use the arrows to move text.) >> use appropriate tool to draw an arrow (basically, inside the triangle draw the figure below) CF >>Select the icon and click o.k >>right click the icon in the front panel and select Show Connectors, then select, show patterns >>chose a the connector with one input and one output >> follow in –class demo >>save the VI >> close the VI Exercise 3-3 Thermometer VI (In class work) Using the sub VI Convert C to F, build the thermometer VI >> starting with a blank VI, build the following front panel icons Document the VI, >>select, File>>VI properties >> from Category pull down menu, select documentation >> type the following in the VI Description text box: This VI measures temperature using he temperature sensor on the DAQ device. >> click OK Document the thermometer and the switch: >>right click the thermometer indicator and select Descriptions and Tips >>in the Description box type: Displays the temperature >> in the tips box, type: Temperature >> OK >>repeat for the switch as follows >> in the description box type: Determines the scale (Fahrenheit or Celsius) to use for the temperature measurements >>in the Tips bos type: scale –C or F >>click Ok Enable the context help and notice its contents as you move the cursor over the thermometer or switch. >>on the block diagram, place a number control to simulate temperature reading >>place the Convert C to F VI on the block diagram from: Functions,>> Select VI. >> place the Select function located on the functions>> arithmetic & Comparison>>Express Comparison >>display the front panel and click the Run Continuously button Icon and Connector Pane Create an icon to indicate a thermometer. For the connector, the inputs are the selection and temperature measurement and the output is the thermometer. Back to Top L e c t u r e - 4 Repetition and Loops While loops For Loops Accessing data from previous loop iteration While Loop: Executes a subdiagram until a condition is true. This loop is similar to a DO Loop or Repeat Until in text based programming. This loop executes at least once The default behavior of the loop is STOP if True. (continues executing until it receives a true at the Conditional Terminal receives a True. The iteration number is an output terminal. This number always starts from 0. In the illustration below, the while loop executes until the control input is >= 10 and the Enable input is True. Note, could end up with an infinite loop Note, we can change the behavior of the loop to Continue if True. Thus, it continues execution until it receives a False. Structure Tunnels Data can be passed into or out of the loop through a tunnel. Tunnel appears as a solid block on the border of the loop. Note, the block has the color of the data type. Data passes out of the loop after the loop terminates. Whereas, when a tunnel passes data into a loop, the loop executes only after the data arrives at the tunnel. This is a way to use loops and can also be used to control order of execution ! – explain in class Exercise 3-1 - in class work Auto Match -- To pass data out of a loop through a tunnel. Build the following front panel Set the data range for control input to prevent the user from selecting incompatible data. - right click Number to Match control and select Data Entry. 1. remove the check mark from “Use Default Limits” checkbox 2. set minimum to 0 and select Coerce from the output range action pull-down menu 3. set max to 10000 and select Coerce 4. set increment value to 1 and select Coerce to nearest. Do not close the dialog box yet. - Modify Digits Precision: 1. select the Display Format Tab 2. select floating point and change significant digits to digits of precision 3. type 0 in the digits of precision and click OK 4. Repeat the Modify Digits Precision steps for Current Number and for # of Iterations. complete the block diagram save the VI as Auto Match.vi display the front panel change the number to Match and run the VI again Note how the current number updates continuously and the # of iterations updates at end of loop Now, change the number to match to a number that is outside the data range ( 0 to 10000) Run the VI, notice how LabVIEW coerces the out of range value to nearest value in the specified range. Back to Top L e c t u r e - 5 For Loops A For Loop executes a subdiagram a set number of times. The number of times, N, is controlled by the count terminal. The iteration number, input terminal contains the number of iterations. The iteration count always starts at 0. Exercise 3-2 Timed Temperature VI. In this exercise, we are to read the temperature once every second for one minute. >> Open a blank VI and build the front panel shown. >> build the following block diagram Note: The VI you created last time (Thermometer VI) is placed here. Modify the input to that VI so that it is a random number multiplied by 30. The VI has one input terminal (switch to select C or F) and one output (Thermometer reading) For you convenience, here are the front panel and block diagram of that VI: >> Save the VI as Timed Temperature.VI Accessing Previous Loop Data In many cases, you may need to access data from previous iteration of a loop. For example, one may wish to display a running average of a temperature readingthus, you will need to use data generated in previous loops. Two ways of accessing previous data are the shift register and feedback node. Shift Registers: Use shift registers on For Loops and While Loops to transfer values from one loop iteration to the next. These are similar to static variables in text based programming. A shift register transfers any data type and automatically changes to the data type of the first object it connects to. To initialize the shift register, wire any value from outside of the loop to the left terminal. You may stack shift registers by using Add Element. You will need to initialize all registers. Feedback Node. The feedback node - not a popular choice – appears automatically in a For or While Loop if you wire the output of a sub VI, function, or a group of sub VIs or functions to the input of that same VI/function. Like a shift register, the feedback node stores data when the loop completes an iteration, sends the value to the next iteration of the loop and transfers any data type. You may use feedback node to avoid long wires. The arrow on the feedback node indicates the direction of data flow. Exercise 3-3 Accessing Previous Data This exercise will demonstrate the use of shift registers and the feedback node. >> On a blank VI, create the front panel shown >> Complete the block diagram shown >> Run the VI The top section of the code reads the initialized feedback node and passes this value to the multiply function The bottom section of the code, reads the initialized feedback node and passes this value to the indicator The multiply function does not execute until the next iteration of the loop >>Click Highlighted Execution, Run the VI to observe the order of execution. >> once understood, remove the highlighted Execution. >> Replace the bottom feedback node with a shift register as shown below. >> run the VI. Here , both the feedback node and the shift register have the same effect. >> Revise the shift register to display the last three iterations of the For Loop data. >> display the front panel, Run the VI and notice the three values in the shift registers. > > Close the VI – Do Not Save. Back to Top L e c t u r e - 6 Arrays Objectives: 1About arrays 2Creating arrays with loops using auto-indexing 3Using Array Functions 4Polymorphism Arrays group data elements of the same type. An array consists of elements and dimensions. A dimension is the length, height, depth of an array. An array can have one or more dimensions Arrays can be built of numeric, Boolean, path, string, waveform, and cluster data type (next topic) Use arrays when working with a collection of similar data type and when performing repetitive computations. Arrays are ideal for storing data that is collected from waveforms or data generated in loops. You cannot create an array of arrays. However, you can create an array of clusters where each cluster may contain one or more arrays. (next topic.) An array uses an index so each element of the array can readily be accessed. The index is zero based. Creating an array control or indicator … (demo) If no object is inserted into the array shell, the array is empty .. A 2-D array stores elements in a grid. Column index and row index are required (Demo) To add a dimension to an array, right click on the index display and select >> add dimension … or just resize using the positioning tool. Demo < create an array constant > these are typically useful for passing data into a sub VI Auto-indexing: When the auto indexing is enabled, the output tunnel of a loop receives an element following every iteration. If disabled - then the last element exits the loop. The For loop defaults to enabled auto indexing The while loop defaults to disabled auto indexing Auto indexing to set to the loop count If the auto indexing in enabled on an array wired to the input of the for loop, the loop count is automatically set to the array size. If more than one input tunnel is auto indexed or if the N count is wired, then the loop count is automatically set to the lower count number. Demo: 1- create a 1-D array (For Loop) – Auto indexing 2- Demo a 2-D array (For Loop) – Auto indexing 3- Demo- disabling auto indexing 4- Demo – using auto-indexing to set the For Loop count Array functions: Show the palette Array size, initialize array, array subset, build array, concatenate inputs, index array (returns the element or sub array of n-dimensions array at index. (so returns an element or an array) <show> Polymorphism This means that the inputs to these types of functions can be different data structures. Such as: scaled values and arrays, e.g, add a scalar to an array or add two arrays together. Also if you say add two 1-D arrays of different sizes, the two arrays are added and the result is the smaller size of the two. Build a VI that accumulates an array of temperature values using the thermometer VI. Set the array size with a control on the front panel. Initialize an array using the Initialize array function of the same size where all the values are equal to 10. Add the two arrays, calculate the size of the final array, and extract the middle value from the final array. Display the Temperature array, Initialized Array, Final Array, and Mid Value The Front Panel should END UP looking like this C h a l l e n g e s : Challenge -1 **Build a VI that simulates the roll of a die with possible values of 1 through 6 and records the number of times the die rolls each value. The input is the number of times to roll the die The outputs include the number of times the die falls on each possible value. Use only ONE shift register. Challenge -2 Build a VI that generates a 1-D array and then multiplies pairs of elements together, starting with elements 0 and 1, and returns the resulting array. For example, if the input array is 1 7 9 10 15 20, the resulting array is then: 7 90 300 Back to Top Clusters - Objective: Learn about Clusters Learn how to use cluster functions Introduce error clusters Clusters: Clusters are group of data elements of mixed data types. A cluster is similar to a record or a struct in text based programming When incorporating several data elements into a cluster, wiring clutter and connector terminal numbers are reduced. Like with arrays, a cluster is either a control or an indicator. A cluster cannot contain a mixture of controls and indicators. Cluster elements are ordered. Cluster elements must be unbundled to access certain elements in the cluster. Create a cluster control and a cluster indicator. - Create Cluster control i. Create the cluster ii. Size to fit iii. Reorder elements in the cluster The order of the cluster elements is according to the order they were placed (not according to their place in the cluster block.) The first object is element 0 and so on. - To reorder elements: select Reorder Control in Cluster The toolbar and menu change The white box on each element indicates the current order The black box shows the new order/place To change the order, type the new order number in the Click to Set Click the confirm button when done Or cancel to revert to the original order Good practice: Corresponding elements in different clusters must have similar data types – makes connections among clusters easy. Example demo – of reordering – the connection will be invalid until fixed! Cluster Functions Use clusters functions on the clusters palette to create and manipulate clusters. Use bundle and bundle by name to assemble and manipulate clusters Use the unbundle and unbundle by name to disassemble functions. Demo: Unbundling, then partial bundling – followed by replacing an element. Assembling and disassembling a cluster 123456- combining different elements into a cluster - show example adding an element to a cluster – show example bundle – refer to the data type/ order bundle by name – refer to element name show unbundle and unbundle by name to access individual elements update a cluster content. Cluster Practice -1 Build a VI that uses polymorphism with clusters.- Scaling Cluster Build the following VI and save it as Cluster Scaling vi (display on screen) Connect the block diagram and verify – it is important to see the polymorphism Error Clusters Error clusters are mechanism to check for errors. This tells a programmer where and why an error occurs. Error with I/O files, instruments are bound to happen. Examples of benefits of error handling are: 1234- you will know if you initialized communication incorrectly if an external device lost power or not working properly path to a file may have changed etc. By default, LabVIEW automatically handles errors that occur whenever a VI is running. However, you may want a whole application to stop if a certain loop execution times out! Or may be you want a certain loop to tray another time … - VIs and functions return errors in one of two ways: numeric error codes (functions) error clusters (VIs) Error handling follows the data flow model. As a VI runs, LV tests for error at every execution node. Wire error clusters to pass error information through VIs. As LV tests for errors at every execution node, if no error is found, LV executes normally. If an error is found, then the error is passed from one node to the next without execution. Use the Simple Error handler VI to handle an error at the end of execution flow. Error clusters and dialog are visited later in a lot more details When we build an application.. Show the error cluster appearance. Note on MathScript - math text programming (recall Matlab!) Demo a Matlab code and run it - demo –recommended to be used: MathScript node; Sample Applications – In class practice 1- keyboard/mouse 2-Dual tone Multiple Frequency (see link below) Start the VI in class- students complete the work. http://www.dialabc.com/sound/dtmf.html Back to Top