Anda di halaman 1dari 21

Prof.Dr.

Doru URSUTIU CVTC University TRANSILVANIA of Brasov Department of Physics

Graphical Programming

LabVIEW

2007

1. 2. 3. 4. 5. 6.

Introduction ................................................................................................2 Graphical Programming G .......................................................................4 First Virtual Instrument in LabVIEW ...........................................................5 Data Acquisition with LabJack....................................................................9 Laboratories using LabVIEW....................................................................17 References...............................................................................................20

1. Introduction
The aim of this document is to give you an introduction to LabVIEW versions 8.2, 8.2.1 and 8.5. We try to use all this versions because their last two years apparitions. It is assumed that you have LabVIEW installed (or you need to install it) on your computer and access to the INTERNET and Remote Engineering MARE Master site. The introduction is for the "core" LabVIEW and not to any particular LabVIEW toolkit or module. Only a basic introduction is given, enough to make you able to develop your own LabVEIW programs. If you need additional information, use the LabVIEW Help or search for relevant examples in LabVIEW and at www.ni.com. LabVIEW, or Laboratory Virtual Instrument Engineering Workbench its now a strong and real Graphical Programming Language G, that has been widely adopted throughout industry, academia, and research labs as the standard for data acquisition and instrument control software. Currently running on near all computers and software platforms, LabVIEW its a powerful and flexible instrumentation and analysis software system. Computers are much more flexible than standard instruments, and creating your own LabVIEW program, or Virtual Instrument (VI) (Fig.1.1), is simple. LabVIEW intuitive user interface makes writing and using programs exciting and fun!

Fig. 1-1 A simple Virtual Instrument VI (Advanced Harmonic Analyzer) The terms Virtual Instrument and Virtual Lab supposes both creating some applications which can simulate certain phenomena or processes (physical, chemical, biological, technological, mathematical) and introducing the concepts of virtual instrumentation and computer-based measurement and automation in order to create a distinct philosophical and material environment, that determine us to bring in the PC computer with the measurement instruments. So, the automation of measurement can be done using PC computer. The whole concept of virtual instrumentation has been to create more powerful, flexible and cost-effective instrumentation systems built around a PC using software as the engine and interface. A VI can easily export and share its data and information with other software applications since they often reside on the same computer. And what can be easier and more pleasant than browsing on the Web and find applications that run as user interfaces and at the other end acquisition and control hardware is running in real time. A method to create such virtual labs is given by the graphical programming language, LabVIEW. Why did we choose this language? Because of the multiple objects already created which make ease the creation of complex programs even by a person who is not a specialist in computer programming, with a minimum effort. Another reason for making this choice is the origin of this language. At the beginning, LabVIEW was software, which accompanied the data acquisition boards and GPIB. Later, it has developed as a real programming language. This offers him the advantage of a strong basis in the field of data acquisition and analyzes. In addition to this, the development of a nucleus of objects for communication on Internet recommends the using of this language, in order to create some virtual labs used for distant learning.

2. Graphical Programming G
LabVIEW departs from the sequential nature of traditional programming languages and features and easy-to-use graphical programming environment, including all of the tools necessary for data acquisition (DAQ), data analysis, and presentation of results. With its graphical programming language, called G, you program using a graphical block diagram that compiles into machine code. Ideal for countless number of science, engineering and education applications, LabVIEW helps you to solve many types of problems in only a fraction of the time and hassle it would take to write conventional code. Perhaps the best way to describe the expansion (or perhaps explosion) of LabVIEW applications is to generalize it. There are places in many industries where measurements of some kind are required most often of temperature, whether it be in an oven, a refrigerator, a greenhouse, a clean room, or a vat of soup. Beyond temperature, users measure pressure, force, displacement, strain, light intensity, pH, and so on, ad infinitum. Personal Computers PCs are used virtually everywhere. LabVIEW is the catalyst that links the PC with the measuring things, not only because it makes it easy, but also because it brings along the ability to analyze what you have measured and display it and communicate it halfway around the world if you so chose. After measuring and analyzing something, the next logical step often is to change (control) something based upon the results. For example, measure temperature and then turn on either a furnace or a chiller. When National Instruments introduced LabVIEW over 20 years ago, it created a unique software tools for creating VIs. The appeal of LabVIEW is largely tied to its graphical programming nature, since it is very easy prototype and develops an application in a fraction of time of what it would take to produce the same in a language such as C++. There is an interesting parallel between the success and popularity of LabVIEW and the popularity of the Web. In both cases, it was not so much the underlying technology that was so innovative, but rather the welldesigned graphical interface that made it accessible. After all, almost everything you could do in LabVIEW could be done in C or assembly code years before LabVIEW was popular. The Internets use goes back to the 1960s. Most of what it took to create these revolutionary tools, though, was the development of an intuitive, human-friendly interface. For LabVIEW, that meant programming by wiring graphical objects together, like building a breadboard circuit. For the Web, it meant a Web browser application that involved little more than just pointing and clicking on images or words that were of interest and were hyper linked to other places on the Web. So, you might say that using LabVIEW to create Internet-enabled applications (Fig.2.1) brings some of the best user interfaces designs together. The

possibilities are exciting for creating easy-to-use and intuitive networked applications that take virtual instrumentation to another level.

Fig. 2-1 Server-Client application

3. First Virtual Instrument in LabVIEW


We must install the LabVIEW environment and from the start panel (Fig.3.1) to select a New VI.

Fig. 3-1 Start panel of LabVIEW application After this we can see two windows, one PANEL and one DIAGRAM, as can se in Fig.3.2. The front panel of a VIs is a combination of controls and indicators. Controls simulate the type of the input devices you might find on a conventional instrument, such as knobs and switches, and provide a mechanism to move input from the front panel to the underlying block diagram. On the other hand, indicators provide a mechanism to display data originating in the block diagram back on the front panel. Indicators include various kinds of graphs and charts, as well as numeric, Boolean, and string indicators. Thus, when we use the term controls we mean inputs, and when we say indicators we mean outputs.

Fig. 3-2 Panel and Diagram (from Windows we can select Tile Up and Down or Tile Left and Right to arrange the windows) You place the controls and indicators on the front panel by selecting and dropping them from the Controls palette. Once you selected a control (or indicator) from the palette and release the mouse button, the cursor will change to a hand icon, which you then use to carry the object to the desired location on the front panel and drop it by clicking on the mouse button again. At this moment you must label the control with your desired name (to be easy recognized from the other controls name). Once an object is on the front panel, you can easy adjust its size, shape, and position. If the Controls palette is not visible, you can either pop up on an open area of the front panel windows, or select Show Controls Palette from the Windows pull-down menu. You access the numeric controls and indicators from the Numeric subpalette located on the Controls palette, as shown in Fig.3.3.

Fig. 3-3 Controls palette (with the Numeric and Boolean subpalette) Now we can start to develop the first Virtual Instruments in LabVIEW. We intend to calculate and represent the Maxwell distribution of particles speed. All the systems in thermal equilibrium have a well-defined distribution of velocities of the particles. One distribution function is the Boltzmann function:

E (r , v ) f (r , v )drdv = A" exp dxdydzdv x dv y dv z kT


where A is a normalization constant (a number to make

fdrdv = 1 )

and E(r,v)

is the total energy of a particle at r with velocity v. The distribution function f depends on both position (r) and velocity (v). When there are no interactions between particles, the distribution simplifies to the Maxwell distribution. The total energy is the kinetic energy:
2 2 m( v x + vy + v z2 ) f (v x , v y , v z ) = A' exp 2kT

The form of Maxwell distribution is f(vx,vy,vz) integrated over all directions of v. The resultis the Maxwell distribution of speeds:

mv 2 f (v) = Av exp( ) 2kT


2

where:

m 2 ) A = 4 ( 2kT
This distribution function f depends only on the speed v=|v|. Our MaxwellDist.vi from the Fig.3.4 shows the Maxwell speed distribution for a gas of hydrogen atoms at T=300K, 600K, 900K and 1200K. First of all must open a new LabVIEW project and Save As the new VI like MaxwellDist.vi. After this select from the Windows pull-down menu Tile Up and Down. Now, as we presented in Fig.3.4, must add to the Panel the necessary Digital Controls (for mass, Boltzmann constant and the starting temperature).

In the control panel its necessary to put also two Waveform Graph selecting Controls>Graph>Waveform Graph. With this operations finished we have all the necessary controls and indicators in the panel. Now must change to the Diagram and we select two For Loop and one Formula Node from Functions > Structures > For Loop and Functions > Structures > Formula Node. One For Loop its necessary to compute the speed distribution and second one to be able to compute de speed distribution for different temperatures. In the Formula node we introduce all the necessary constants and we compute the speed distribution and energy. To add the necessary entries and outputs for the Formula Node we can click on his icon with the right taste of the mouse and select Add Input or Add Output. All the necessary information connected with the writing of formulas can be automatically vizualizated if the Show Context Help was activated (from Help > Show Context Help). To calculate the value of the N in the internal For Loop we used the numeric icons from the subpalette Numeric of the Functions palette (Fig.3.5). This value of N its connected with the range of the maximum particles speed V0 (we used N=3 V0) calculated for all the selected temperatures T=300K, 600K, 900K and 1200K.

Fig. 3-4 The MaxwellDist.vi present particle speed distribution and energy 8

Fig. 3-5 The Numeric subpalette and the N calculus

4. Data Acquisition with LabJack


In the last years a great number of companies designed and seal on the Data Acquisition market a high number of DAQ cards with a great variability in the ratio PRICE/QUALITY. We selected LabJack (Annex I.) for our laboratory applications because satisfy us with one of the best ratio price/quality but have also more others qualities: Its an external card, easy to manipulate in laboratory Easy and reliable hot USB connectivity Have an excellent connection interface Has a watchdog timer function available High quality of AD, DA conversion resolution Good low noise precision PGA amplifier to provide gains up to 20 Have a good compensated tension reference One frequency counter up to 1MHz LabVIEW drivers, applications and SDK included in price Flexible programming facilities

In the distribution package you will receive the LabJack card, USB connection cable, a small documentation and a CD with all the necessary files. To be able to use the LabJack DAQ card for the first time its very easy. With the PC on and using the included cable, connect the LabJack U12 to the USB port on the PC or USB hub. The USB cable provides power and communication for the LabJack U12. The status LED should immediately blink 4 times (at about 4 Hz), and then stay off while the LabJack enumerates.

Enumeration is the process where the PCs operating system gathers information from a USB device that describes it and its capabilities. The low-level drivers for the LabJack U12 come with Windows and enumeration will proceed automatically. The first time a device is enumerated on a particular PC, it can take a minute or two, and Windows might prompt you about installing drivers. Accept all the defaults at the Windows prompts, and reboot the PC if asked to do so. The Windows Installation CD might also be needed at this point. Make sure a CD with the correct version of Windows is provided. Enumeration occurs whenever the USB cable is connected, and only takes a few seconds after the first time. When enumeration is complete, the LED will blink twice and remain on. This means Windows has enumerated the LabJack properly. If the LabJack fails to enumerate: Make sure you are running Windows OS version 4.10.2222 or higher, Try connecting the LabJack to another PC, Try connecting a different USB device to the PC, Check our online forum and/or contact LabJack. When the LabJack installation is finished, it will start the National Instruments LabVIEW Run-Time Engine (LVRTE) setup. The LVRTE is required for the example applications: LJconfig, LJlogger, LJscope, and LJtest. If prompted to reboot after this installation, go ahead and do so. Virus scanners can often interfere with the installation of the LVRTE. If you have trouble running the example applications, repeat the LabJack software installation to make sure the LVRTE is installed. In the case of manual installation and CD browsing, we can find two main directories: Image o docs o drivers o examples o and executable applications (LJconfig, LJcounter, LJfg, LJlogger, LJscope, LJstream, LJtest) LabVIEW o with the LabVIEW virtual instruments library
Ljackuw.llb

After the initial software installation its good to test LabJack card with the help of the executable softwares (LJconfig, LJcounter, LJfg, LJlogger, LJscope, LJstream, LJtest). For this can execute the LJtest and LJconfig applications. In Fig.4.1 you can see the LabVIEW interface in the case of one LabJack unit connected to the USB port of our PC and was run LJtest.

10

If you need to use more like one LabJack unit connected to the PC, you can use the LJconfig application to see the serial of the cards and to change the Local ID. In the Fig.4.2 you can se the panel of the application LJconfig and you can observe the serial and the Local ID of one LabJack card who was connected at the test moment. In this case we connected a LabJack card with the Serial number 100000692 and the card received the Local ID 0 (was detected only one card in the system).

Fig. 4-1 The LabVIEW panel of LJtest after first test running

11

Fig. 4-2 The LabVIEW panel of LJconfig after running (can se the serial and the Local ID) After this step was finished in good condition we can now to make the first measurements using the LJcounter, LJfg, LJlogger, LJscope, Ljstream applications. To measure external tensions can be used the internal thermal compensated tension reference of 2.500 V or you can program the DA converter at a specified tension. The LabJack U12 has 2 screw terminals for analog output voltages. Each analog output can be set to a voltage between 0 and the supply voltage (+5 volts nominal) with 10-bits of resolution. The output voltage is ratiometric with the +5 volt supply, which is generally accurate to 5%. If an output voltage of 5 volts is specified, the resulting output will be 100% of the supply voltage. Similarly, specifying 2.5 volts actually gives 50% of the supply voltage. If improved accuracy is needed, measure the +5 volt supply with an analog input channel, and the actual output voltage can be calculated. For instance, if an analog output of 2.5 volts is specified and a measurement of +5V returns 5.10 volts, the actual output voltage is 2.55 volts. Alternatively, the analog output can itself be measured with an analog input. There is a 1st order low-pass filter on each analog output with a 3dB frequency around 22 Hz. In Fig.4.3 we present the results of the measurements with LJlogger application and LabJack card with: reference signal connected to the AI0 channel the AO0 channel fixed at 5V and connected to AI1 the AO1 channel fixed at 2.5V and connected to AI2

12

Fig. 4-3 Measurements using LJlogger application The external features of the LabJack U12 are: USB connector, DB25 digital I/O connector Status LED, 30 screw terminals. The USB connection provides power and communication. No external power supply is needed. The +5 volt connections available at various locations are outputs; do not connect a power supply. Figure 4.4 shows the top surface of the LabJack U12. Not shown the USB and DB25 connector, which are both on the top edge. The DB25 connector provides connections for 16 digital I/O lines, called D0-D15. It also has connections for ground and +5 volts. All connections besides D0-D15, are provided by the 30 screw terminals shown in Figure 12. Each individual screw terminal has a label, AI0 through STB. The status LED blinks 4 times at power-up, and then blinks once and stays on after enumeration (recognition of the LabJack U12 by the PC operating system). The LED also blinks during burst and stream operations, unless disabled. The LED can be enabled/disabled through software using the functions AISample, AIBurst, or AIStreamStart. Since the LED uses 4-5 mA of current, some users might wish to disable it for power-sensitive applications (can do this as you can see in Fig.4.3 with LED on or off function).

13

Fig. 4-4 Top surface of the LabJack U12.

With the LabJack and LabVIEW software installed on your PC you can now use the specific LabJack icons to write any new applications using LabVIEW Virtual Instruments. The LabJack palette of 21 icons (LJAI, LJAO, Bits to volt, Volts to bits, LJcount, LJDIO, LJreset) inserted in the standard palette of LabVIEW you can see now on the Fig.4.5.

14

Fig. 4-5 LabJack palette of icons in LabVIEW We selected only 2 of the icons from 21, the LJAI and LJAO, to be introduced in Fig.4.6 together with the minimal help for connection in LabVIEW applications. We can use now these icons to easy build specific applications for the laboratory.

Fig. 4-6 LabJack icons and LabVIEW help In the Fig. 4.7 we used the LJAI and LJAO to build a virtual instrument named GenRead.vi who generate 2 voltages and this voltages can be read on Cannel 1 and Channel 2 voltmeters. Like in Fig. 4.3 the reference signal was connected to the AI0 channel and the AO0 channel fixed at 3V was connected to AI1 and the AO1 channel fixed at 4V and connected to AI2.

Fig. 4-7 Applications in LabVIEW using LJAI and LJAO Now relatively easy can build laboratory applications that involve control or measure currents and tensions. To adapt the signals can use the facilities offered by the LabJack card.

15

The LabJack U12 has 8 screw terminals for analog input signals. These can be configured individually and on-the-fly as 8 single-ended channels, 4 differential channels, or combinations in between. Each input has a 12-bit resolution and an input bias current of 90 A. Input configuration: Single-Ended: The input range for a single-ended measurement is 10 volts. Differential channels can make use of the low noise precision PGA to provide gains up to 20, giving an effective resolution greater than 16-bits. In differential mode, the voltage of each AI with respect to ground must be between 10 volts, but the range of voltage difference between the 2 AI is a function of gain (G) as follows: G=1 20 volts G=2 10 volts G=4 5 volts G=5 4 volts G=8 2.5 volts G=10 2 volts G=16 1.25 volts G=20 1 volt The reason the range is 20 volts at G=1 is that, for example, AI0 could be +10 volts and AI1 could be -10 volts giving a difference of +20 volts, or AI0 could be 10 volts and AI1 could be +10 volts giving a difference of -20 volts. For some experiments you can use also the DIO lines. Connections to 4 of the LabJacks 20 digital I/O are made at the screw terminals, and are referred to as IO0-IO3. Each pin can individually be set to input, output high, or output low. These 4 channels include a 1.5 k . series resistor that provides overvoltage/shortcircuit protection. Each channel also has a 10 M resistor connected to ground. One common use of a digital input is for measuring the state of a switch. If the switch is open, IO0 reads FALSE. If the switch is closed, IO0 reads TRUE. While providing overvoltage/short-circuit protection, the 1.5 k . series resistor on each IO pin also limits the output current capability. For instance, with an output current of 1 mA, the series resistor will drop 1.5 volts, resulting in an output voltage of about 3.5 volts. Connections to 16 of the LabJacks 20 digital I/O are made at the DB25 connector, and are referred to as D0-D15. These 16 lines have no overvoltage/short-circuit protection, and can sink or source up to 25 mA each (total sink or source current of 200 mA max for all 16). This allows the D pins to be used to directly control some relays. All digital I/O are CMOS output and TTL input except for D13-D15, which are Schmitt trigger input. Each D pin has a 10 M. resistor connected to ground.

16

5. Laboratories using LabVIEW


Using this combination of LabVIEW software and LabJack card its easy to develop a great variety of teaching and laboratory applications. Laboratories, which are found in all engineering and science programs, are an essential part of the education experience. Not only do laboratories demonstrate course concepts and ideas, but they also bring the course theory alive so students can see how unexpected events and natural phenomena affect realworld measurements and control algorithms. However, equipping a laboratory is a major expense and its maintenance can be difficult. Teaching assistants are required to set up the laboratory, instruct in the laboratory, and grade laboratory reports. These time-consuming and costly tasks result in relatively low laboratory equipment usage, especially considering that laboratories are available only when equipment and teaching assistants are both available. What if some of the basic laboratory experiments could be made available 24 hours a day, seven days a week? What if students could have access to experiments from their home or student dormitories? What if a professor wanted his students to take a closer look at a classroom demonstration? What if a professor wanted to make a research demonstration available to students and others at irregular times? What if a professor deriving a complex equation for some application wanted his students to try different sets of parameters to bring out the essence of the model? What if a professor wanted his students to see an electronic circuit in action, and even give them control of the operating parameters? All of these and many more exciting applications are now easily achievable with the new technology available with National Instruments LabVIEW Remote Panels. With this standard feature of LabVIEW, a user can quickly and effortlessly publish the front panel of a LabVIEW program for use in a standard Web browser. Once published, anyone on the Web with the proper permissions can access and control the experiment from the local server. If the LabVIEW program controls a real-world experiment, demonstration, calculation, etc., LabVIEW Remote Panels turns the application into a remote laboratory with no additional programming or development time. A remote laboratory (Fig.5.1) is defined as a computer-controlled laboratory that can be accessed and controlled externally over some communication medium. For this discussion, a remote laboratory is an experiment, demonstration, or process running locally on a LabVIEW platform but with the ability to be monitored and controlled over the Internet from within a Web browser. In the simplest case, the remote laboratory server can be an experiment connected to a computer through a standard interface (DAQ, GPIB, serial, parallel, etc) and with the host computer connected to the Internet. The client can be any computer connected to the Internet running a simple browser. Once connected, the client

17

will see the same front panel as the local host and also have the same program functionality.

Fig. 5-1 Internet control of a remote laboratory In many of the previous successes of remote laboratories, LabVIEW was used but extensive programming of Java, CGI, or other third-party software tools was required to bring local laboratory functionality to a browser environment. Now, with LabVIEW 6.1 Remote Panels, remote execution is just a couple of clicks away. Without any additional programming, a LabVIEW program can be enabled for remote control through a common Web browser (Fig.5.2). With this new technology, the user simply points the Web browser to the Web page associated with the application. Then, the user interface for the application shows up in the Web browser and is fully accessible by the remote user.

Fig. 5-2 LabVIEW Remote Panels Now we introduce the interface (PhotovoltaicPanelCharacterization.vi) of the measuring system (using a DAQ card and a LabVIEW VI) used to do laboratory investigation of the Solar Panels (or Cells). This application (Fig.5.3) will be one of the first laboratory works on the Solar Cell Laboratory.

18

Fig. 5-3 The Panel and Diagram of the PhotovoltaicPanelCharacterization.VI Now we can use this Virtual Instrument to present how easy we can build Remote Panels using the LabVIEW facilities. In the Fig. 5.4 we present this Virtual Instrument web remote controlled with LabVIEW.

Fig. 5-4 Web control of the PhotovoltaicPanelCharacterization.VI To build this application, you must use the LabVIEW (from version 6.1 to the last one) and make some simple steps. First of all must open the application. After this select Tools > web Publishing Tool and you open a simple interface (Fig.5.5) when you can introduce some informations (Text 1 and Text 2) about your application and after that: must Start Web Server and Preview in Browser. If you are satisfied you must close all with Save to Disk (an put the Photovoltaic Panel Characterization.htm in www directory of LabVIEW).

19

Fig. 5-5 Web Publishing in LabVIEW In the Annex 2 we present now some Virtual Instruments with the Panels and Diagrams and a short description. This applications was build to proof the capability of LabVIEW software to be a flexible tool to develop: teaching support, laboratory applications and also sophisticated research virtual instruments. The creation of same virtual instruments gives the possibility to produce some rather cheap research environments of high quality, with a friendly interface and an easy maintenance. Also, virtual labs and virtual instrumentation can sustain very well the theoretical courses from the perspective of both practical and research work parts. The appearance of some software as LabVIEW, that dont request very strong programming knowledge in order to create some complex applications, gives aid at the creation of virtual labs and virtual instrumentation

6. References
1. P. Cotfas, D. Ursutiu, D. Cotfas, C. Samoila Implementarea Metodei Entropiei Maxime in LabVIEW RIV Anul III, Vol. III, Nr 3(11), toamna 2000, ISSN 1453-8059; 2. D. Ursutiu Initiere in LabVIEW Programarea grafica in fizica si electronica, Editura Lux Libris, Brasov, 2001; 3. P. Cotfas, D. Ursutiu, C. Samoila Using LabVIEW in Computer Based Learning, Interactive Computer aided Learning Tools and Applications Ed. M.Auer and U. Ressler, ICL99 Workshop, ISBN 3-7068-0755-6;

20

4. P. Cotfas, D. Ursutiu, C. Samoila Creating a Virtual Lab using LabVIEW International Conf. TICE 2000, 18-20.10.2000, Troyes, France; 5. P. Cotfas, D. Ursutiu, C. Samoila Virtual Laboratory and Virtual Instrumentation ,Internet as a Vehicle for Teaching, Ed. Susan English, Mihai Jalobeanu, Nicolaie Nistor, Romanian Internet Learning Workshop RILW2001, august 11-20 2001, ISBN 973-85023-7-3 6. http://www.labjack.com/support.html LabJack company documentation 7. http://www.ni.com National Instruments company documentation 8. Cotfas,P., Ursutiu, D., Cotfas D., Samoila C. Implementarea Metodei Entropiei Maxime in LabVIEW RIV Anul III, Vol. III, Nr 3(11), toamna 2000, ISSN 1453-8059 9. Egarievwe, S.U., Adepeju, A., Gautam, B., Oseoghaghare, K.O., La Keisha A.F., Shean. K.T.,Eugene C.W. Internet Application of LabVIEW In Computer Based, EURODL 2000

21