Exercise 5: Basic LabVIEW Programming

Similar documents
Virtual Instruments with LabVIEW

Data Acquisition HANS-PETTER HALVORSEN,

Datalogging in LabVIEW

Solutions. Discretization HANS-PETTER HALVORSEN,

2. The LabView Environment Two panes will open, one is the Front panel, and one is the Block Diagram

NI LabView READ THIS DOCUMENT CAREFULLY AND FOLLOW THE INSTRIUCTIONS IN THE EXERCISES

Control and Simulation in. LabVIEW

LabVIEW programming I

Above Threshold Warning of Temperature Data

INTRODUCTION TO LABVIEW

The LabVIEW Programming Environment and Basic Operations

OpenStax-CNX module: m Thermometer VI * National Instruments

NI mydaq HANS-PETTER HALVORSEN, Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Getting Started with LabVIEW Virtual Instruments

Introduction to National Instruments LabVIEW and Data Acquisition (DAQ)

Lab 4 - Data Acquisition

Learn the three palettes. Learn how data is passed in LabVIEW. Create a subvi using two different methods.

Computer Interfacing Using LabView

Introduction to LabVIEW Exercise-1

Experiment 1: Introduction to Labview 8.0 (tbc 1/7/2007, 1/13/2009,1/13/2011)

Read Temperature Data

Hands-on Lab 1: LabVIEW NI-DAQ Basics 1

ME 224: EXPERIMENTAL ENGINEERING. Lecture 2

Exercise 11: Discretization

Labview. Masood Ejaz

Introduction to LabVIEW

PHYC 500: Introduction to LabView. Exercise 1 (v 1.3) M.P. Hasselbeck, University of New Mexico

Wireless DAQ using ZigBee

University of Pennsylvania. Department of Electrical and Systems Engineering. ESE Undergraduate Laboratory. Introduction to LabView

Høgskolen i Telemark Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics.

Experiment 1: Introduction to Labview 2010 (tbc 1/7/2007, 1/13/2009,1/9/2012, 1/10/2012)

Exercise 0 - Open and Run a Virtual Instrument (Slide 12)

Lesson 4 Implementing a VI

LabVIEW basics. BME MIT János Hainzmann, Károly Molnár, Balázs Scherer, Csaba Tóth

Concept: Debugging. Goal. Description. Implementation. Use the debugging tools built into LabVIEW.

2 Lab 2: LabVIEW and Control System Building Blocks

LabVIEW. Table of Contents. Lesson 1. Pre-reqs/Technical Skills Basic computer use

Engineering Project-I. Module 1: Familiarization of LabVIEW and the Vernier Toolkit

Virtual Instrumentation With LabVIEW

Virtual Instrumentation With LabVIEW

CISE 318: Computer Control Systems Laboratory Exercises

Introduction to LabVIEW

Homework Assignment 9 LabVIEW tutorial

Table 1. Inputs and Outputs

Introduction to LabVIEW. By Finn Haugen, TechTeach

Lesson 1 Introduction to LabVIEW. TOPICS LabVIEW Environment Front Panel Block Diagram Dataflow Programming LabVIEW Help and Manuals Debugging a VI

Introduction to LabVIEW

Linear Control Systems LABORATORY

Data Acquisition Laboratory

LabVIEW Academy. 12. óra event, property node

Engineering Innovation Center LabVIEW Basics

NI Vision System HANS- PETTER HALVORSEN,

Dept. of Electrical, Computer and Biomedical Engineering. Data Acquisition Systems and the NI LabVIEW environment

Small rectangles (and sometimes squares like this

Step-by-Step Data Acquisition Part II Exercise 2: Generating an Analog Output Waveform

University of Illinois Department of Electrical and Computer Engineering ECE 451 Automated Microwave Measurements Laboratory

NAME EET 2259 Lab 3 The Boolean Data Type

LabVIEW Express VI Development Toolkit User Guide

ECE 202 LAB 1 INTRODUCTION TO LABVIEW

Using LabVIEW to Send Commands via RS232 to Ontrack Control Systems ADR Interfaces

Lab 1: Getting familiar with LabVIEW: Part I

Part 1. Summary of For Loops and While Loops

LabVIEW programming I

Introduction to Labview and Temperature Measurement

Tutorial: Getting Started with the LabVIEW Simulation Module

ME 365 EXPERIMENT 3 INTRODUCTION TO LABVIEW

Part 1. Creating an Array of Controls or Indicators

Certified LabVIEW Associate Developer Exam. Test Booklet

FRC LabVIEW Sub vi Example

Lab Exercise 2: Data Acquisition with NI LabVIEW

LABVIEW LAB SKILLS ACTIVITY 1 PROGRAMING ENVIRONMENT

Page 1 of 6. ME 3200 Mechatronics I Laboratory Lab 2: LabView Computer Systems. Introduction

Certified LabVIEW Associate Developer Exam. Test Booklet

DAQ in MATLAB HANS-PETTER HALVORSEN,

Basic Data Acquisition with LabVIEW

Simulation in LabVIEW. Hans-Petter Halvorsen, M.Sc.

Excel. Spreadsheet functions

ECE 451 Automated Microwave Measurements Laboratory. Experiment No. 2. Automated RF Power Detection Using LabVIEW

Faculty of Computing, Engineering and Technology. Real Time Systems 1 CE LabVIEW David D. Hodgkiss & Staffordshire University 1

Arrays are lists of elements of the same data type. They are analogous to arrays in traditional languages.

Lab 2: Introduction to LabVIEW 8.5

Certified LabVIEW Associate Developer Examination

Today. 4/5/11 Physics 262 Lecture 10 Questions about Exams Homework. Lab: Continue project. Lecture. Review your exams and review practice exam again.

BE/EE189 Design and Construction of Biodevices Lecture 1. BE/EE189 Design and Construction of Biodevices - Caltech

Introduction to Electronics Workbench

PHYC 500: Introduction to LabView. Exercise 8 (v 1.3) M.P. Hasselbeck, University of New Mexico. Arrays, XY Graphs, Disk I/O

Microsoft How to Series

c01.qxd p /18/01 11:03 AM Page 1 Fundamentals

Certified LabVIEW Associate Developer Examination

PHY 351/651 LABORATORY 1 Introduction to LabVIEW

LabVIEW Basics. Based on LabVIEW 2011 Student Edition

Department of Chemical Engineering ChE-101: Approaches to Chemical Engineering Problem Solving Excel Tutorial VIII

A. Front Panel Design Lesson 4 Implementing a VI

ECE 463 Lab 1: Introduction to LabVIEW

Pre-Lab Excel Problem

Shift Register: Exercise # 1: Shift Register Example VI. 1. Build the following front panel. Figure (8.1): Shift register exercise front panel

Analytical Instrumentation

NI USB-TC01 Thermocouple Measurement Device

PHYC 500: Introduction to LabView. Exercise 16 (v 1.2) Controlling hardware with DAQ device. M.P. Hasselbeck, University of New Mexico

Excel Simulations - 1

Transcription:

Exercise 5: Basic LabVIEW Programming In this exercise we will learn the basic principles in LabVIEW. LabVIEW will be used in later exercises and in the project part, as well in other courses later, so it is crucial that we learn and know about the basic features in LabVIEW. LabVIEW is a general programming language, but the main difference between e.g. Visual Basic/C# and LabVIEW is that LabVIEW is a graphical programming language, while the others are text- based languages. LabVIEW is an excellent tool for simulation and control because it has a lot of built- in features for these applications that programming languages like Visual Basic/C# or tools like Maple are missing. MathScript/MATLAB is good to use in the design phase when creating your control system, while LabVIEW is a much better tool when it comes to practical implementation of the control system and communication with the real process. As an engineer you need to use several tools to get the job done. Recommended LabVIEW Videos: LabVIEW Quickie! by Finn Haugen LabVIEW 101 by National Instruments Getting Started with NI LabVIEW Student Training by National Instruments Short Introduction to LabVIEW 1 - Getting Started LabVIEW programs are called Virtual Instruments, or VIs, because their appearance and operation imitate physical instruments, such as oscilloscopes and multimeters. When opening LabVIEW, you first come to the Getting Started window. Select File New VI (Ctrl + N) in order to get started. Faculty of Technology, Postboks 203, Kjølnes ring 56, N-3901 Porsgrunn, Norway. Tel: +47 35 57 50 00 Fax: +47 35 57 54 01

2 2 - Front Panel vs. Block Diagram Then, 2 different windows appear: The Front Panel and the Block Diagram. You use the Front Panel to create you Graphical User Interface (GUI), while you use the Block Diagram to create your code, i.e. the logic that makes your program works. Both the Front Panel and the Block Diagram are saved in the same file (.vi). You can easily switch between the Front Panel and the Block Diagram using Ctrl + E. Front Panel User Interface window Block Diagram Code window 3 - Controls Palette and Functions Palette When you right- click on the Front Panel, the Controls Palette appears. Here you will find all the necessary elements you will need to create your GUI. When you right- click on the Block Diagram, the Functions Palette appears. Here you will find all the functions you need to create the logic in your program. Controls Palette (right- click on the Front Panel) Functions Palette (right- click on the Block Diagram) Note! It might look different on your computer depending on what you have installed.

3 You may also configure the appearance by selecting Customize and then Change Visible Palettes. In the window that appears, select Select All and then OK. This can be done for both the Controls palette and the Functions palette. 4 - Controls and Indicators In LabVIEW we distinguish between Controls and Indicators. A Control is an element on the Front Panel where the user can change the value (interact with it), while an Indicator is an element only for information, i.e. the user cannot interact with it. We have different kinds of Controls and Indicators; the most common are Numeric, Boolean and String. Numerics (orange color) are used for numbers, Booleans (green color) are used for True/False, while Strings (red/pink color) are used for text and letters. The appearance of Controls and Indicators on the Front Panel The appearance of Controls and Indicators on the Block Diagram Note! LabVIEW have different layout for Controls and Indicators ( Silver, Modern, System and Classic ). These can be used interchangeable and it is a matter of taste which one you prefer. The icons on the Block Diagram may also look a little different depending on your settings:

4 or: or: or: You may easily change this by right- clicking on the icons and select View As Icon. 5 Wiring: Creating the logic In order to create the logic in the program, we need to wire the different icons on the Block Diagram together: 6 - Run the Program We are now ready to test the program, i.e. run it. When you are ready to test your program, click the Run button on the toolbar (or Ctrl + R).

5 Simple Example Create a user interface (Front Panel) with the following controls (right- click to open the Controls palette then select Modern Numeric ): Vertical Pointer Slide (Note! This is a Control ) Tank (Note! This is an Indicator ) The Front Panel shall now look like this: The Block Diagram should look like this: Wire them together like this:

6 Set the slider on e.g. 5: Run the program by clicking the Run button: Then click the Run Continuously button and change the value for the Slide and observe what s happens. While Loop In some situations the Run Continuously button is handy to use, but in most situations we rather want to use a While Loop instead. So we will extend the program with a While Loop. Right- click to open the Functions palette on the Block Diagram and select a While Loop ( Structures While Loop ). Drag the While Loop over the blocks we already have on the Block Diagram so it looks something like this:

7 Next, we need to specify when the While loop is going to end using the Loop Condition. The Loop Condition is a True/False value. When it is False, the loop is running. When it is True, the loop is stopping. We will wire a Stop button to this condition: Front Panel: Right- click to open the Controls palette on the Front Panel and add a Stop Button ( Modern Boolean Stop Button ). The Front Panel should look like this: Block Diagram: Wire the Stop Button to the Loop Condition. The Block Diagram should now look like this:

8 Run the program by clicking the Run button and change value on the Slider and observe what s happening.

9 Task 1: Simple Calculator Note! LabVIEW have different layout for Controls and Indicators ( Silver, Modern, System and Classic ). These can be used interchangeable and it is a matter of taste which one you prefer. Task 1.1 Create the following simple program that adds 2 numbers: Simple Calculator.vi This simple calculator will add 2 numbers together. Step- by step instructions: Front Panel: Add 2 Numeric Controls and name them Number1 and Number2 Add a Numeric Indicator and name it Answer Block Diagram: Insert an Add function from the Functions palette: Connect (wire) the different objects together like this:

10 Push the Run button in the Toolbar to do the calculations. Congratulations!! You have created your first LabVIEW program. Task 1.2 Extend your calculator (make sure to rename your file) so it can handle the 4 basic calculations (Add, Subtract, Multiply, Divide). Front Panel: Step- by step instructions: Calculator.vi For selecting the different Operators ( Add, Subtract, Multiply, Divide ), you should use an Enum :

11 Enter Add, Subtract, Multiply, Divide inside the Enum (right- click and select Add Item After ). Block Diagram: The Block Diagram should look like this when you are finished: Use the Case Structure for this. Wire the Enum ( Operator ) to the sign on the Case structure.

12 Push the Run button in the Toolbar to do the calculations. Task 2: While Loop Note! LabVIEW have different layout for Controls and Indicators ( Silver, Modern, System and Classic ). These can be used interchangeable and it is a matter of taste which one you prefer. Create the following program: While Loop.vi The program will update the date and time each second using a While loop until you stop the program using the Stop button. Front Panel: Add 2 String Indicators and name them Date and Time. Block Diagram: The Block Diagram should look like this when you are finished:

13 While Loop: Add a While Loop to your program. Get Date/Time String: Use the Get Date/Time String function in order to get the current Date and Time from the computer: Wait (ms): The Date and Time strings should be updated every second. You can use the Wait (ms) for that:

14 Task 3: Advanced Calculator Note! LabVIEW have different layout for Controls and Indicators ( Silver, Modern, System and Classic ). These can be used interchangeable and it is a matter of taste which one you prefer. Create the following program: Advanced Calculator.vi Front Panel: Add the User Interface objects as shown in the Figure above. The calculations will be performed when you click the Calculate button. Block Diagram: You need to use the following in your program: While Loop: Event Structure: Add an Event Structure inside the While Loop.

15 The Block Diagram should look like this when you are finished: Task 4: SubVIs Task 4.1 Create a SubVI from the Calculator created in a previous task: Calculator.vi Define inputs and outputs as in the illustration above (click with you mouse).

16 Task 4.2 Icon Editor: This includes creating a nice icon using the Icon Editor : Right- click in the upper right window and select Edit Icon in order to open the Icon Editor. Task 4.3 Using and testing the Sub VI: We will now create a new program that uses the Sub VI. Block Diagram: Create a new blank VI and open the Block Diagram. Insert the Sub VI by right- click and select Select a VI in the Functions palette. Right- click on the Sub VI inputs and select Create Control

17 The Block Diagram should look like this when you are finished: Front Panel: The Front Panel could look like this:

18 Test of SubVI Calculator.vi Test your program by using the Run button in the Toolbar. Task 5: Plotting Create the following program: Plotting.vi

19 Front Panel: Use the Waveform Chart Control: Block Diagram: Random Number (0-1): Use the Random Number (0-1) function in order to create some random data in your plot: Waveform Chart: Insert the Waveform Chart inside the While Loop. Wait (ms): Update the chart every second by using the Wait (ms) : The Block Diagram should look like this when you are finished:

20 Additional Task We want to convert the temperature from degrees Celsius to degrees Fahrenheit. The Front Panel may look like this: The conversion formula is as follows: Temperature.vi T! = 9 5 T! + 32 Create a SubVI that converts the temperature from degrees Celsius to degrees Fahrenheit. Use the SubVI to convert the temperature in the VI above ( Temperature.vi ).

21 Additional Resources Tutorial: Introduction to LabVIEW: http://home.hit.no/~hansha/?tutorial=labview LabVIEW Starter: http://home.hit.no/~hansha/training/labview/starter Here you will find tutorials and other resources. LabVIEW Videos: LabVIEW Quickie! by Finn Haugen LabVIEW 101 by National Instruments Getting Started with NI LabVIEW Student Training by National Instruments