labview for physicists 24 th october 2002 ben jeffery

33
LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Upload: brooke-barrett

Post on 28-Mar-2015

223 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

LabVIEW for Physicists

24th October 2002

Ben Jeffery

Page 2: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 3: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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!

Page 4: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Disadvantages:•Cost £1000 minimum.

•Hard to master advanced techniques.

•Code can become an impenetrable mess if you’re not careful!

•Creating highly customized applications can become time consuming.

Page 5: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

•The Language

•Building an application•Front Panel•Source Diagram

•Programming•Structures•Built-in Functions•User Vi’s•Tips

Overview:

Page 6: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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…

Page 7: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

A New Way of Thinking:

Dataflow

NOT Codeflow

UnlockCAL(HeaterMat);

GetTempCAL(HeaterMat);

SetTempCAL(HeaterMat);

LockCAL(HeaterMat);

Guiding Principle:A node does not run untildata sits at all its wired inputs.

Data Dependency

Page 8: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Building an Application:

•Two parts to make:

1. Front Panel2. 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 (VI’s)

Page 9: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 10: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

•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

Page 11: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.•Don’t 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:

Page 12: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 13: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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:

Page 14: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Types of Node:

Types of nodes:•Indicators and Controls

•Functions:

•Built in Functions

•User VI’s (sub-routines)

•Structures

All have one or more terminals that usually only accept one data type.

Page 15: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 16: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 17: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Lets see some LabVIEW

•We’ll start with a simple example to get a feel for programming in LabVIEW:

Page 18: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

A Closer LookWe’ve covered most of the basics of the environment. Now lets look at methods and techniques of programming.

•Structures•Built In Functions•User Vi’s•Clusters•Programming Tips

Page 19: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 20: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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:

Page 21: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 22: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 23: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 24: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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)

Page 25: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Formula Node:

•Used to avoid large numbers of arithmetic functions•Has one or more inputs and outputs•Uses C type syntax

Page 26: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Event Structure:

•Handles windows events•Used for customisation of user interface•Allows very fancy tricks!•LabVIEW 6.1 only

Page 27: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

Built in Functions:Over 100 built in functions

Use the context help window to find what you need.

Page 28: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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

Page 29: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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

Page 30: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

User Vi’s: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:

Page 31: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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.

Page 32: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

The Error Cluster:•LabVIEW standard, used in many built in VI’s

BooleanIntString

•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:

Page 33: LabVIEW for Physicists 24 th October 2002 Ben Jeffery

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 VI’s so that your code is modular.

•Experiment