labview physics 3 - it skills miles padgett [email protected]
TRANSCRIPT
Objectives To acquire familiarity with the LabView
Programming language To be able to write LabView programmes
incorporating pre written and new VI’s To use LabView in the study of 2-D
diffraction patterns You get exercise marks for completion of
each milestone.
LabView - the basics
All LabView programmes comprise of two screen types The “front panel” (grey) which acts as
the user interface The “diagram” (white) which contains
the “programme”
LabView - getting going Like most programs,
LabView can be launched by double clicking on the LabView icon
Programs themselves are called “vi” (virtual instruments)
To start a new “vi”, select “new vi” from the LabView start up screen
The LabView icon
The LabView start up screen
LabView - front Panel Controls (data input) and indicators
(data output) can be selected from the “controls” window and placed on the front panel.
To find controls select “show panel” from “window” menu select “show controls palette” from
“window” menu
The controls palette
LabView - diagram Functions (program operations)
can be selected from the “functions” window and placed on the diagram.
To find functions select “show diagram” from
“window” menu select “show functions palette”
from “window” menu
The functions palette
LabView - tools Tools (cursor/mouse
functions) can be selected from the “tool” window
To find tools select “show tools palette” from
“window” menu
The tools palette
Using LabView to add two numbers Create new program
Select “new VI” from the file menu
Select a digital control from the controls palette and place it on the front panel (grey)
Do the same again Select a digital indicator
from the controls palette and place it on the front panel
Selecting a digital controlSelecting a digital control
Selecting a digital indicatorSelecting a digital indicator
Adding two numbers - front panel
Controls and indicator placed on front panel
N.B. software automatically numbers controls of the same type in sequence
The front panel
Adding two numbers - diagram
Data terminals automatically appear on diagram
The diagram
Adding two numbers - placing the function
Select and drag the “addition function onto the diagram
To find addition Show function panel Click on numeric Select and drag
addition onto diagram
Selecting a numeric functionSelecting a numeric function
Dragging onto the diagramDragging onto the diagram
Adding two numbers - wiring the function
Select “wiring tool” from tools palette Cursor now changes
function “click” on wire start point
“drag” to end point then “release”
Use wiring tool to connect Digital controls to
function inputs Function output to digital
indicator
Adding two numbers - running the program
Select “arrow” from tools palette Cursor now changes
function Running the program
Use arrow tool to “click” single arrow on front panel to run once
Or “click” looped arrow on front panel to run continuously
Stopping the program Use arrow tool to “click” red
stop button
Run onceRun once
Run continuouslyRun continuously
Stop the programStop the program
Adding two numbers - operating the program
Select “finger hand” or “text tool” from tools palette
Cursor now changes function
Changing the input Use “finger” on up/down
arrows of numeric controls Or use “text tool” to
highlight and edit number field (white) within numeric control
If running continuously then program is interactive
Up/down arrowsUp/down arrows
Text fieldText field
Adding two numbers - saving the program
Select “save” from within the file menu When prompted enter filename Note in windows LabView files have a
***.vi file extension Vi - stands for virtual instrument
DO IT NOW AND KEEP DOING IT!
Customising the program (text)
Select “text tool” from tools palette
Cursor now changes function
Changing the name of the input
Use “text tool” to highlight and edit the names (grey) numeric control
Use “text tool” to highlight and edit the name (grey) numeric indicator
Control text fieldControl text field
Indicator text fieldIndicator text field
Customising the program (data)
Select “arrow tool” from tools palette
Cursor now changes function
Changing the allowed range and up/down increment of the controls
Right click (windows) on the numeric control to generate menu then select “Data range…”
Within data range can set upper limit/lower limit and increment
Now run the program again
Max/Min/IncrementMax/Min/Increment
Selecting data rangeSelecting data range
Customising the program (display) -1
Select the front panel Show “controls panel from
window menu” Use “arrow tool” to select
numeric control Use “arrow tool” to select
“meter” and “drag” it onto front panel
Use “text tool” to optionally edit name of meter
Use “text tool” to optionally highlight and edit the range of the meter
Selecting a digital meterSelecting a digital meter
Range of meterRange of meter
Name of meterName of meter
Customising the program (display) -2
Select the diagram Select “wiring tool” from tool
palette Use wiring tool to connect
meter terminal to existing output wire of the “addition” function or equivalently to the existing numeric indicator terminal
I.e. click on start, drag to end then release
Run the program again, note meter display matches indicator
Accessing LabView’s help To get help on a function
Select the diagram Select “arrow tool” from tool
palette Use arrow tool to right click
(windows) on function Select help from pop up menu Function help appears in sub-
window More general help can be
obtained through the “help menu”
“Content and index” is good for specific questions
LabView comes with a “learn by activities package”
Also a great set of example programs
Useful tips - indicators, controls and terminal Every indicator on the front
panel has a terminal on the diagram
Every control on the front panel has a terminal on the diagram
Right clicking(windows) on any terminal, control /indicator gives the option of highlighting the corresponding control /indicator or terminal
Useful tips - switching between tools Rather than picking your tool from the “tools palette” pressing
the “tab” key toggles the tool between On the diagram
Arrow (allows selection and/or movement of terminals and functions around diagram
Text (allow text edit of terminal and addition of extra text comments)
Wiring (allows wiring connection of functions and terminals) Finger (allows selection of terminals)
On the panel Arrow (allows movement of controls around panel Text (allows text edit of control/indicator and addition of extra
text comments) Paint (allows colour change of control or indicator) Finger (allows adjustment of controls)
Useful tips - showing various windows Any window or tool panel can be made
active by selecting it from the window menu
Alternatively “clicking” on a window will make it active This is a quick way of switching between the
diagram and the front panel
Useful tips - finding errors If the current LabView
programme is non executable the “run” arrow on the front panel appears broken
Activating the arrow results in an error list contain the faults
Selecting any fault highlight the offending part of the diagram
Broken “run” arrowBroken “run” arrow
error listerror list
Looping programs Computers become
power when you make them do something many times!
LabView loops are examples of structures and placed on the diagram Show diagram Shows functions palette Select structure
Selecting the Selecting the structure sub palette structure sub palette from the functions from the functions palettepalette
Incorporating a “while loop” Select a “while loop”
from the structure palette
Place while loop on diagram to surround program Click top left drag to
bottom right and release While loop will run whilst
condition is true
““While loop”While loop”
ConditionCondition
Setting the condition of a “while loop” Need Boolean (true/false)
control to set state of while loop Show front panel Show controls palette Select “boolean” Select “push button” and
drag and place (release) on front panel
Optionally use “text tool” to highlight and edit name (grey) of new control
Wiring the condition of a “while loop” Need to wire the Boolean
terminal to the condition of the while loop Use arrow tool to move (if
necessary) the terminal of the Boolean control to the inside of the while loop
Use the wiring tool to connect the boolean terminal to the condition terminal
Running a “while loop” Running/stopping the
program within a while loop Use finger tool to toggle
Boolean control to true (dull green arrow becomes bright green)
Use finger or arrow tool to “run” program (NB not continuously run)
Program will now run continuously
Use finger or text tool to change/edit numeric controls
Use finger tool to toggle boolean control to stop program
Using LabView to draw a sine curve
Objective To plot a sine curve in the range 0-
10 Start a new program
Select “new VI” from the file menu Save it now
Select “save” from the file menu and when prompted provide name
Using a “for loop” Show the diagram Select a “for loop” from
the structure palette Place the “for loop” on
the diagram “click” “drag” “release”
A “for-loop” will run N times then stop
i increments from 0 to N-1
For loopFor loop
Terminal for NTerminal for N
Terminal for iTerminal for i
Wiring N on a “for loop” Show the front panel
Select digital control from the controls palette
Place control on front panel
Show diagram (If necessary) move
terminal of digital control to outside of loop
Wire digital control terminal to N terminal of for loop
NB one terminal is blue the other orange!
Understanding data types
Computers store number in different forms, e.g. Integers, 8 bit, 16bit, 32 bit - BLUE in
LabView Floats single precision, double precision -
Orange in LabView
Converting Data type Show either diagram or
front panel Right click (window) on
control or terminal and select “representation”
“click” on data type of choice to convert numeric
Do this to change numeric control to I32 integer
Edit numeric value to 100
Drawing a sine curve - defining the range (1) To define the 0-10
range Show diagram Select and place constant
outside loop - edit to 10 Select and place
outside loop Select and place multiple
function outside loop Wire “10” and “”””””“ into
“x” function
Selecting a constantSelecting a constant
Selecting Selecting
Drawing a sine curve - defining the range (2)
Select and place divide function inside loop
Wire “i “into quotient of divide
Wire numeric input through wall into denominator of divide
Select and place multiple function
Wire output of divide into multiply
Wire “10 x ””“ product through loop wall into multiply
Drawing a sine curve - calculating the value To calculate the sine
value Select and place sine
function inside loop Wire output of
multiply to input of sine
Wire output of sine to loop wall
Selecting sineSelecting sine
Drawing a sine curve - displaying the curve Show front panel
Select and place “waveform graph” on front panel
Show diagram (if necessary) move
waveform graph terminal outside loop
Wire wall of loop to waveform graph terminal
Selecting waveform graphSelecting waveform graph
Drawing a sine curve - displaying the curve (2) Show diagram
(if necessary) move waveform graph terminal outside loop
Wire wall of loop to waveform graph terminal
NB orange wire on outside of loop is thicker than inside Indicates wire carries
an array of numbers
Drawing a sine curve - running the program Use arrow tool to “run
continuously the program Adjust numeric control to
change number of points calculated
Use arrow tool to “stop” program when finished
Use text edit tool to rename x-axis of graph (angle), name of numeric control (number of data points) and name of waveform graph
Drawing a sine curve - modifying the program To make 10 range variable
Select and place digital control on front panel
Show diagram Delete 10product structure
and wire from outside loop to leave unwired loop entry
Move new numeric terminal to similar position
Wire in terminal to loop entry Run continuously and
experiment with changing the range
Drawing a sine curve - extending the program FFT (1) To obtain an FFT of the sine
wave Select and place FFT function
on diagram near existing waveform graph terminal - the route to FFT is
• Functions• Analyse• Signal processing• Frequency domain
Wire waveform graph (or neighbouring wire to Input of FFT function
Selecting FFT functionSelecting FFT function
Drawing a sine curve - extending the program FFT (2)
Wire waveform graph (or neighbouring wire to Input of FFT function
On front panel place additional waveform graph
On diagram wire output of FFT function to terminal of waveform graph
Use text tool to edit name of waveform graph and x axis of graph on front panel
Drawing a sine curve - seeing the FFT
Run program continuously
Update range control Examine FFT of sine
wave Note the FFT has two
peaks Note FFT peaks have
+ve and -ve values
Drawing a sine curve - seeing the power spectrum (1) More usual to consider the
power spectrum Need to take modulus squared
of each FFT component Delete wire between FFT and
waveform graph terminal (if necessary) move terminal of
waveform graph away from FFT Select and place modulus
function after FFT Select and place multiply
function after modulus Wire FFT to modulus Wire modulus to both inputs of
multiply Wire multiply to waveform
graph terminal
Drawing a sine curve - seeing the power spectrum (2) Power spectrum is +ve Still twin peaked Run program
Note that a higher “frequencies” of sine wave power spectrum peaks move towards centre
Double peaks can be through to represent +ve and -ve frequency
Using LabView to draw a 2D function
Objective To plot an “egg box” type pattern
Start a new program Select “new VI” from the file menu
Save it now Select “save” from the file menu
and when prompted provide name
Double nested “for loop” A single for
loop will create a vector of N elements
To create an array use a for loop within a for loop
Useful tips - copying and moving items on the diagram To move a selection of functions and wires on a
diagram Use arrow tool to define rectangle of interest, i.e. click
upper left and drag to lower right Use cursor keys to move selected region
To copy a selected section of the program Use arrow tool to define rectangle of interest, I.e. click
upper left and drag to lower right Use standard copy and paste functions to replicate
program
Calculating the “egg box” Assume an egg box is
generated by taking the product of two sine functions (one in the x-direction and one in the y)
Use double nested loop and repeat logic of previous program, note Both N terminals of loop wired
to control i indices of loops wired to form
x and y axis Out wired through inner loop to
form output from outer loop
Visualising the “egg box” (1) Show front panel
Select and place intensity graph on front panel
Use text tool to rename x-axis, y-axis and name of graph
Selecting an intensity graphSelecting an intensity graph
Visualising the “egg box” (2) Show diagram
(if necessary) move terminal of intensity graph to outside of nested loop
Wire output from outer loop to terminal of intensity graph
NB note orange wire becomes “double wire” which indicates it is an array
Useful tips - Polymorphic In LabView, most
functions are polymorphic. e.g.. the same addition
function will add two numbers or two vectors or two arrays (vectors or arrays must have the same dimensions
Adding numbersAdding numbers
Adding vectorsAdding vectors
Adding arraysAdding arrays
Running the “egg box” Show front panel
Use finger or text tool to set numeric controls to ≈100 loop iterations and a plot range of ≈30
Run or run continuously the program
Need to set z-axis of graph to autoscale
• “right click” (window) on graph, select z-scale and select autoscale z
Auto-scaling the z-axis of an intensity graphAuto-scaling the z-axis of an intensity graph
Useful tips - changing the number format Previously we have seen how
to change the range over which a numeric control can be varied
To change the way it is displayed Show front panel “rick click” (windows) on
control Select “format and precision” Edit forma and precision
window as desired NB this only affects the
display NOT the precision of the calculations
The challenge - diffraction patterns To calculate and display the far field
diffraction pattern of a circular aperture The far field diffraction pattern of a circular
aperture is the same form as the Fourier-transform (but in 2D)
In the first instance “forget” about the wavelength (which sets the scaling between the aperture and the diffraction pattern) - just concentrate on the “shape”!
Useful functions for challenge (1) “Comparison” functions
allow logic decisions NB wire carrying logic, i.e.
Boolean (0..1) date are green
When defining the aperture, you may need “select” “less” or “greater”
Use LabView’s help to understand these functions
Useful functions for challenge (2) “array” functions allow
manipulations of array and vectors Wire containing array data
appear a two parallel wires. These may be blue (for integer)or orange (for floats)
When doing the FFT, you may need “transpose” “rotate 1D array”
Use LabView’s help to understand these functions
Useful functions for challenge (3) If the N terminal is left unwired,
“for loops” will self-index When a vector is wired into a
“for loop” the loop will split the array and run it on each element
When an array is wired into a “for loop” the loop will split the array and run it on each row
To switch off “self-indexing” right click (windows) on wire entry to loop and select “disable indexing” (not needed in challenge)
vector to elementvector to element array to vectorarray to vector
Useful functions for challenge (4) Standard LabView does
not have a function for 2D FFT
Given a 2D array, a 2D FFT can be completed by doing 1D FFT’s on each row and each column
You may need this when calculating the diffraction pattern - note use of “self-indexing”
A component of a “diagram” for completing a 2D FFT
Diffraction pattern Run your programme
Do you get a diffraction pattern centred in the four corners?
This is a issue with most FFT algorithms - where should the zero “frequency” be located? At the centre or the edges?
We need to centre our zero in the middle of the image
2D FFT with zero at centre Can use “1D rotate
function to move zero to centre (NB need to rotate by N/2)
Note also modulus squared added to output of FT to give power spectrum (i.e. light intensity)
Calculating a diffraction pattern
One program that works! Autoscale-z
switched off and z-scale set to reveal structure
Calculating a diffraction pattern
One program that works