Introduction to LabVIEW Lab 6 Introduction to Engineering and Design LAB 6: Introduction to LabVIEW 6.1 Objective The purpose of Lab 6 – LabVIEW – is to introduce a graphical programming language. Once the desired knowledge has been acquired, it will be utilized to obtain data from inside and outside the computer by creating four LabVIEW programs. LabVIEW will also be used in later laboratories such as the design project. 6.2 Introduction 6.2.1 Background LabVIEW is short for Laboratory Virtual Instrument Engineering Workbench. It is s a program development application that uses a graphical programming language G, to create programs in block diagram forms, which are unlike C++ or any other text-based programming language. LabVIEW can be used for data acquisition, instrument controls, filters, linear algebra, array arithmetic, and signal processing. LabVIEW programs are called Virtual Instruments – VIs – because their appearance and functions simulate actual instruments. A VI has both an interactive user interface and a source code interface equivalent. Data can be passed between the two interfaces. Other LabVIEW applications in this course are: Lab Number and Name VIs Used 1. Lab 7: Thermal Insulation Therm. & Therm1 2. Lab 8: Microphone TimeFreq 3. Lab 9: Electrical Filters Oscilloscope A VI has three main components 1. The front panel – the user interface. The front panel is the window where the controls, indicators, and buttons are placed; it also displays graphs and other data charts. 2. The back panel – the VI source code. The window where the actual code is written and the icons represent lower-level VIs and built in functions. 67 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design 3. The icon and connector of a VI allow other VIs to pass data to the VI. The icon represents a VI in the block diagram of another VI. The connector defines the input and outputs of the VI. Terms and icons Front Panel Set Color Run Operate Value Continuous Run Position/Size/Select Stop Edit Text Pause Connect Wire Block Diagram Get Color Execution Highlighting Scroll Window Start Single Stepping Set/Clear Start Single Stepping Probe Data Object pop up Control and Indicators The controls and the indicators are differentiated by the thicknesses of their borders. The control is the data input; it allows the user to have interactions between the code panel and the displayed data. It resembles a real switch knot, whose appearance in the back panel is a box with a thick border. The Indicator is the displayed data – output. It is distinguished from the control by its thin border. It does not allow the user to change any data. Color Representation 1. Numeric Type (Orange) Extended Precision Floating Point Single/Double Precision Floating Point 68 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Complex Extended Precision Floating Point Complex Single/Double Precision Floating Point 2. Word/Bytes (Blue) Unsigned 32-bit, 16-bit, 8-bit Integer 32-bit Integer (Long Word), 16-bit Integer (Word) 8-bit Integer 3. Booleans (Green) 4. String (Pink) 5. Clusters (Brown) 6. I/O Functions (Aqua) Path Refnum Structures Structures are important in any programming language because they not only allow the user to produce multiple outputs and create conditions, but they also control the time of the programs. The structures that will be discussed in this section are: while and for loops, conditional case, and sequence structure. While Loop Repeats the same piece of code until the specified condition becomes FALSE. i.e.: While this is TRUE do {// program code; }. While loops can be found in the Functions menu. Counter Boolean Controller While loop illustration 69 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design For loop Runs the same code for count times. The count can be setup by wiring a value from the outside of the loop to the count terminal. i.e. for i = 0 to N <= 200{ //Execute program;} For loops can be found in the Functions menu. For loop illustration: Control ler Counter Case Structure Is also known as the conditional case statement. It executes according to the matched case indicated by a controller, switch, or constants. If there are no matches it executes the default case. Case Structures can be found in the Functions menu. Selector Terminal Connection Input Output Tunnel Sequence Structure The sequence structure is a sequence of executions. It follows a control flow executing from frame 0 to frame n. It can be found in the Structs & Constants palette of the Functions menu. Sequence figure. 70 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design 6.3 Materials/Equipment 6.3.1. The materials needed to perform this experiment are 1. The LabVIEW Software 2. A Data Acquisition Board (DAQ board) 3. The manual and a PC 6.3.2 Equipment Setup – To begin the experiment, open the LabVIEW program (if not opened) and select “New VI” from the LabVIEW first selection window. Set the panel windows so that the front and back panels are visible at the same time (for reading purposes) by clicking on “windows >Show Left & Right” or simply by pressing “Ctrl+T ”. Once both windows are opened and visible, begin creating one by one, the four programs specified by the procedures section. 6.4 Procedures 6.4.1.1 Simple Calculator – Design Create a program that simulates a basic-calculator, which will allow the user to perform three of the four basic operations: Addition, Subtraction, and Multiplication (+, -, *). The inputs to the program may be introduced from the keyboard or the Input/Output I/O – board located inside the computer (the DAQ board will be used to access the I/O board). The minimum required icons to use are: Front Panel One switch to control which arithmetic operation to perform (+, -, *). A second switch to control where the incoming data is being entered from: externally – keyboard or internally – I/O board. Three LED’s (BOOLEAN) indicators to specify the operation selected (+, -, *). Two numeric controls to allow the user to input the data from the keyboard. A numeric indicator – to display the output of the data entered. Diagram Panel 71 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Use at least one case statement to control the arithmetic operations. 6.4.1.2 Simple Calculator - Test Enter different input numbers through the control icon in the front panel. Observe the indicator and make sure the correct transaction is being processed. 6.4.1.3 Data Print each of the programs created, and then make sure to obtain the instructor’s signature after s/he tested it. 6.4.1.4 Analysis Calculate the transactions by hand or using a calculator and compare them to the displayed results through the indicator in LabVIEW. 6.4.2.1 Thermal Control – Design Generate a program that simulates a house temperature control, which may be controlled manually or automatically. The air conditioner MUST turn on when the temperature is above 80o F. The heater MUST turn on when the temperature is less than 60o F. The heater and the air conditioner MUST be off while the temperature range is between 60o F and 80o F. Use the following requirements as a minimum. Front Panel Two LED’s: one to represent if the AC is on/off and the second to represent if the heater is on/off. A switch to select between manual and automatic operation of the AC and heater. The manual operation will allow the user to turn the AC and heater on/off. A temperature control represented by either a vertical slide or a thermometer. Diagram Panel A Boolean case statement to control the manual and automatic operation of the AC and the heater. 6.4.2.2 Test Manually enter different temperature ranges and make sure the A/C or heater light turns ON/OFF appropriately. 72 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Run the program automatically and assure the front panel displays the correct reading 6.4.2.3 Data Print out the results of one or two tests performed (one manually controlled and the other automatically). 6.4.2.4 Make sure the instructor’s initials are on your data after s/he has tested it. Analysis N/A 6.4.3.1 Lighting System – Design Design a Program that simulates a typical household lighting system by using “real” (LEDs) and simulated (LabVIEW) lights, so that the user can get a feeling of turning the house lights on and off, as in a real house. Note: An LED’s lighting depends on its input and its pin number from the DAQ board; therefore, each light should have its own pattern Front Panel Each room MUST be represented with a light Optional: A main switch may be used to turn ALL the lights off Diagram Panel A “Port Config” and “Port Write” should be used to control the LED’s through the DAQ board o Each light should have its own switch and illuminate either separately or simultaneously with the other lights. A Boolean case for each LED Note: Refer to the introduction of this lab experiment for more information about Port Config, Port Write and DAQ board connections. 6.4.3.2 Test Turn the master switch ON and turn all lights (manually) on Turn the master switch OFF – Make sure all the lights turn off 73 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Make sure each light turns on with the right pattern 6.4.3.4 Data Print out the front and back panel (with TA’s approval) and make sure he/she initials after testing it. 6.4.3.4 Analysis Analyze the lighting system and understand the pattern each light switch follows. 6.4.4.1 Voltmeter – Design Create a program that will allow the user to input a voltage into the I/O block and then display the voltage reading using a seven-segment display – ref. to fig.4.1. The voltage reading may vary from –5 to +5 volts; any number above or below this range should be displayed as a –5 or +5 depending whether it’s a high or low number. Finally the displayed number should be rounded to the nearest integer e.g. 2.65V should be rounded up to 3V. Front Panel A Seven-segment indicator consisting of seven LED indicators A negative sign LED indicator, which turns on if the voltage reading is negative and off if the voltage reading is positive. Diagram Panel A case statement to control the different possible LED indicator combinations that result from the different inputs o If the input is 3, then LEDs 1, 2, 3, 4, an 7 should light up on the sevensegment display to indicate the input 3 Seven Segment Display (Before Activation) Seven Segment Display (4 LED’s are lit to show “3”) 74 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Fig. 6.1 6.4.4.2 Test Enter different values into the controller and make sure it displays the correct rounded number to the closest whole number. Make sure the highest number displayed is the 5 and the lowest number displayed is – 5. 6.4.4.3 Data Print the front and back panels and make sure the instructor initials it after s/he tested it. 6.4.4.4 Analysis N/A *** Remember not to save the programs while running them. *** 6.5 Discussion Independent Report (One report per student) The report and the presentation should be written according to the experiments performed in this lab. Remember to include a title page for the report and the original data attached at the end of the report (signed by the TA). The following should be discussed in both the presentation and the report: 75 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Explain what a VI is. Briefly explain how you implemented each program What are some advantages and disadvantages of LabVIEW Brainstorm possible designs to complete the following objective o Use an actual thermocouple wire as a sensor for the thermal control (using the DAQ board) 6.7 Closing Upon the completion of each program, have your instructor inspect it and sign it. Also, if you are confused about how to operate any icon use the HELP window from LabVIEW. It will help you with the operation of the icon and connection of the same. Make sure each person from the team gets a turn using the LabVIEW software. And finally take advantages of the references available from LabVIEW to help you in future programs. 76 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design SUPPLEMENTAL NOTES DAQ – Data AcQuisition Board The Data AcQuisition Board is the interface, which allows the user to send and receive data outside the computer structure. The data sent/received can be of Analog or Digital form. DAQ Icons – The icons most frequently used by EG101R are: One Input Analog Channel Port Config Port Write Analog Tools Pin numbers 1-9 represent the analog data pins, where pin 9 is the analog ground. Easy I/O, Analog One Point Input Channel: The value is a Device Line: The value is an integer. The DAQ string. For EG101R is recognized by the computer as 1. (blue) purposes the string will be set to 0. (pink) Output Upper Limit: The value is a real Lower Limit: The value is a real number. For number. For EG101R purposes, it EG101R purposes, it indicates the lowest voltage indicates the highest voltage the DAQ the DAQ can take in (– 5). (brown) can take in (+ 5). (brown) Digital Tools Pin numbers above 13 represent the digital pin numbers, where pin 13 is the digital ground. 77 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Port Configuration (config) is a tool which informs the DAQ that it will be sending or receiving data. Typically the variables are set as follows: Device Line: The value is an Task ID out: connects integer. The DAQ is recognized by to the task Id in, of port the computer as 1 write or port read DAQ Channel: The value is a String, tools. which is either 0,1 or 2, depending on the channel selected by the user. Line Direction Map: The value Port Width: The value is an integer. It is an integer. It configures the determines the number of pins (in the DAQ), used DAQ tool to either read (0) or for each channel (set in multiples of 8, we will write (-1). (We will use write) use 8) Port Write is a tool, which allows the information to be written and sent to the DAQ. Pattern: The value is an integer. Task ID in It determines which pin(s) will be activated. Each pin is set by factor of 2. (i.e. 20=pin 14, 21=pin 15) Ref. To pin chart Pattern Table The following table can be used as a reference when the tools such as Port Config and Port Write are being used. Each pin number is represented with a LabVIEW equivalent. This equivalent would depend on the pattern and the channel being used. 78 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design Pattern 27 26 25 24 23 22 21 20 Chart 1 Channel Port Width of 8 with corresponding Pin # 0 21 20 19 18 17 16 15 14 1 29 28 27 26 25 24 23 22 2 37 36 35 34 33 32 31 30 Chart 2 Note: You can only use one “Port Config” and one “Port Write” for a program. This is because the power supplied will fluctuate between each VI. Compound Arithmetic The compound arithmetic icon can be used to control multiple pins at the same time. It performs arithmetic additions, subtractions, multiplications, and divisions on two or more numeric inputs or Boolean inputs. By using the arrow tool and extending it down, new inputs can be added up. The total pattern number is added and outputted. This The pattern numbers of each value lights the corresponding pin may be placed on this pin numbers when connected to side. the Port Write Pattern Field. Light Emitting Diodes (LED’s) Cathode Anode Negative Positive Ground Voltage 79 Introduction to LabVIEW Lab 6 Introduction to Engineering and Design 80