LabVIEW for Physicists - PowerPoint PPT Presentation

1 / 33
About This Presentation
Title:

LabVIEW for Physicists

Description:

The results of older iterations can be accessed by making the left terminal larger. ... Make user VI's so that your code is modular. Experiment ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 34
Provided by: benje
Category:

less

Transcript and Presenter's Notes

Title: LabVIEW for Physicists


1
LabVIEW for Physicists
Ben Jeffery
24th October 2002
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
Overview
  • The Language
  • Building an application
  • Front Panel
  • Source Diagram
  • Programming
  • Structures
  • Built-in Functions
  • User Vis
  • Tips

6
The G Language
  • Completely graphical programming language.
  • Source code is a diagram of nodes and wires.
  • Data travels along 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
Dataflow
NOT
Codeflow
UnlockCAL(HeaterMat) GetTempCAL(HeaterMat) Set
TempCAL(HeaterMat) LockCAL(HeaterMat)
Guiding Principle A node does not run until data
sits at all its wired inputs. Data
Dependency
8
Building an Application
  • Applications are called virtual instruments (VIs)
  • Two parts to make
  • Front Panel
  • 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.

9
The Front Panel
  • How the user interacts with G.
  • Contains both controls and indicators.
  • Each item on the front panel has a corresponding
    node on the source diagram.
  • 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 and Indicators
  • Front panel objects are either controls or
    indicators.
  • The corresponding nodes are identified as shown.
  • Controls are sources for data
  • Indicators are sinks for data

Controls
  • Constants are sources for data that do not
    appear on the front panel

Indicator
Constant
11
Making the Front Panel
The best way to show this is in LabVIEW
Tips
  • 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!

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
As terminals accept only defined data types, so
wires have defined types. This is indicated by
colour and style.
  • 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)

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
Built in Functions
  • 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.

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
Write a Comment
User Comments (0)
About PowerShow.com