Presentation is loading. Please wait.

Presentation is loading. Please wait.

LabVIEW for Physicists 24 th October 2002 Ben Jeffery.

Similar presentations


Presentation on theme: "LabVIEW for Physicists 24 th October 2002 Ben Jeffery."— Presentation transcript:

1 LabVIEW for Physicists 24 th October 2002 Ben Jeffery

2 What is it? Laboratory Virtual Instrument Engineering Workbench. Development environment for the G language. Produced by National Instruments for all major operating systems. Originally developed for communication with lab devices. A really useful tool.

3 Why use LabVIEW? Easy to Learn - Intuitive. Easy to Use. No Syntax. Source code reads like schematic. Speed of development. Ready made controls for many instruments. Support. Easy and instant debugging. Power – Instant Parallel threads. No memory concerns. (Within Reason) As versatile as text-based languages. Fun. Honest!

4 Disadvantages: Cost £1000 minimum. Hard to master advanced techniques. Code can become an impenetrable mess if youre not careful! Creating highly customized applications can become time consuming.

5 The Language Building an application Front Panel Source Diagram Programming Structures Built-in Functions User Vis Tips Overview:

6 The G Language: Completely graphical programming language. Data travels along wires. Source code is a diagram of nodes and wires. Flow of data controls execution. Not flow of code! Position on diagram is irrelevant. Being an expert in C can be a disadvantage…

7 A New Way of Thinking: DataflowNOTCodeflow UnlockCAL(HeaterMat); GetTempCAL(HeaterMat); SetTempCAL(HeaterMat); LockCAL(HeaterMat); Guiding Principle: A node does not run until data sits at all its wired inputs. Data Dependency

8 Building an Application: Two parts to make: 1.Front Panel 2.Source Diagram Always start with the front panel. Draw a pencil block diagram of the main functions of the diagram. Make this diagram in G code. Done. Applications are called virtual instruments (VIs)

9 The Front Panel: Each item on the front panel has a corresponding node on the source diagram. Contains both controls and indicators. How the user interacts with G. Many ready made controls means quick and easy construction of simple front panels. There is scope for customisation of the controls but this is mainly cosmetic.

10 Controls are sources for data Indicators are sinks for data Controls and Indicators: Front panel objects are either controls or indicators. The corresponding nodes are identified as shown. Constants are sources for data that do not appear on the front panel Indicator Controls Constant

11 Making the Front Panel: The best way to show this is in LabVIEW: Use tab controls instead of cluttering the panel. Set limits on data entry to save programmatic checking. Keep to a consistent style. Dont go wild with the colours. Add text boxes when explanation is needed. Use schematic representation if a physical system is involved. Remember someone else might need to understand it in your absence! Tips:

12 Building the diagram: Double clicking any control on the front panel will take you to its node on the source diagram and vice-versa. Clicking window, show diagram (Ctrl-E) will also display the source diagram.

13 Building the diagram: Nodes are placed in a similar way to controls on the front panel. An extra tool is used on the source diagram: The Wiring Tool: The most used, and most infuriating tool in LabVIEW. Avoid crossing wires. Click to join nodes together:

14 Types of Node: Types of nodes: Indicators and Controls Functions: Built in Functions User VIs (sub-routines) Structures All have one or more terminals that usually only accept one data type.

15 Types of Wire: Usual data types: 8,16,32 bit Integers (Signed and Unsigned) Single, Double and Extended floating point Complex Boolean String Arrays Clusters (Combination of any above) As terminals accept only defined data types, so wires have defined types. This is indicated by colour and style.

16 Program Control: Run Once: Program executes until all data is sunk. Run Continuously: Run Once occurs repeatedly. Abort Execution: Immediate halt. Pause Execution: Useful for debugging.

17 Lets see some LabVIEW Well start with a simple example to get a feel for programming in LabVIEW:

18 A Closer Look Weve covered most of the basics of the environment. Now lets look at methods and techniques of programming. Structures Built In Functions User Vis Clusters Programming Tips

19 Structures: How you control data flow Case Structure While Loop (with shift registers) For Loop Sequence Formula Node Events Structure Understanding the operation of these is vital.

20 Case: Similar to the Case statement in C Contains one or more frames. The frame that executes depends on what is wired to the selection terminal. Many data types can be wired to the selector. Lets see it in LabVIEW:

21 While: Similar to the While statement in C Contains one frame that is repeated Test for continuance is performed after execution so frame always executes once. i terminal gives number of current iteration (first frame is 0) stop terminal can be continue if true or stop if true selected from context menu.

22 Shift Registers: Selected via right-clicking the frame. Enables the result of an iteration to be passed to the next iteration. Can be used for any data type The results of older iterations can be accessed by making the left terminal larger. The initial value is set by wiring to the left terminal and the final iterations value is output at the right terminal. Results are kept between runs of a vi.

23 For Loop: Similar to the while loop but is executed a set number of times (wired to the N terminal) If 0 is wired to the terminal the frame does not run, do outputs will be invalid. Input arrays can be indexed automatically and if N is not wired the number of iterations will be the size of the largest input array. Shift registers can also be used here.

24 Sequence: Used to order events where no data dependency exists. Can have more than one frame but this should ALWAYS be avoided. (Like goto in C)

25 Formula Node: Used to avoid large numbers of arithmetic functions Has one or more inputs and outputs Uses C type syntax

26 Event Structure: Handles windows events Used for customisation of user interface Allows very fancy tricks! LabVIEW 6.1 only

27 Built in Functions: Over 100 built in functions Use the context help window to find what you need.

28 Built in Functions: Low Level Boolean Logic Arithmetic Comparisons These functions accept different data types and often arrays can be directly wired. Mid Level Array Manipulation (Transpose, interpolate, subset...) String Manipulation (Search, format, replace...) Time and Date

29 High Level File I/O Device communication (GPIB, serial etc…) Network communication (TCP, UDP, IrDA) Waveform manipulation (FFT, Filters, Analysis) Math Sound and Graphics Program Control Advanced: Semaphores, Queues, Occurrences. Built in Functions: So check before you build your own

30 User Vis: For often used routines or to prevent an excess of code on your diagram create a user vi Create the vi as if it were a stand alone program Right click the icon to access the wiring and icon menu. Show connector and select a pattern of terminals and then use the wiring tool to select controls and indicators to be terminals. Edit the icon Place the vi where you need it using select a vi off the function pallet. Lets see that in LabVIEW:

31 Clusters: Collection of one or more items of data Best used as Named Clusters In this way you can carry related data in one wire and extract only the data you need when you need it. Also reduces the need for many terminals in a user vi.

32 The Error Cluster: LabVIEW standard, used in many built in VIs Boolean Int String Passed along to each vi. If status is true the vi does not run as the preceding one gave an error. Lets illustrate this with an example:

33 Programming Tips: Use a left to right layout Use named clusters for both neatness and ease of variable selection. If functions need to happen in a sequence establish a data dependency, so that the functions are connected in a chain. This is easily done using the error cluster. Remember that functions not connected and in the same frame will run in parallel. Make user VIs so that your code is modular. Experiment


Download ppt "LabVIEW for Physicists 24 th October 2002 Ben Jeffery."

Similar presentations


Ads by Google