Labview Physics 3 - It Skills

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Labview Physics 3 - It Skills as PDF for free.

More details

  • Words: 3,813
  • Pages: 67
LabView Physics 3 - IT skills Miles Padgett [email protected]

1

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.

2

LabView - the basics 

All LabView programmes comprise two screen types  The

“front panel” (grey) which acts as the user interface  The “diagram” (white) which contains the “programme”

3

LabView - getting going 

Opening LabView (windows)  



Opening LabView (Linux)  





“Double-click” on LabView Icon LabView start-up appears From within the Linux “Shell” type “labview &” LabView start-up appears

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 4

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 5

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 6

LabView - tools 



Tools (cursor/mouse functions) can be selected from the “tool” window To find tools 



select “show tools palette” from “window” menu

Some issues of LabView give option for auto-tool select TURN IT OFF! 

Auto tools is turn off and on by clicking on the “green” button (Dark green is off)

The tools palette

Click to turn off auto tools

7

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 control

Selecting a digital indicator 8

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 9

Adding two numbers - diagram 

Data terminals automatically appear on diagram

The diagram 10

Adding two numbers - placing the function 



Select and drag the “addition function onto the diagram To find addition   

Selecting a numeric function

Show function panel Click on numeric Select and drag addition onto diagram

Dragging onto the diagram 11

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 12

Useful tips - controls and indicators and terminals 

Do not confuse controls (data inputs) with indicators (data outputs)  





Wiring an indicator to the input of a function will generate an error Wiring a control to the output of a function will generate an error

Double (left) clicking on any terminal on the diagram (white) will highlight the associated control or indicator on the front panel (grey) Double (left) clicking on any control or indicator on the front panel (grey) will highlight the associated terminal on the diagram (white) 13

Adding two numbers - running the program 

Select “arrow” from tools palette 



Running the program 





Run continuously

Cursor now changes function 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 

Stop the program Run once

Use arrow tool to “click” red stop button 14

Adding two numbers operating the program 

Select “finger hand” or “text tool” from tools palette 



Changing the input  



Cursor now changes function Use “finger” on up/down arrows of numeric controls Or use “text tool” to highlight and edit number field (white) within numeric control

Text field

If running continuously then program is interactive

Up/down arrows

15

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!

16

Useful tips - changing the program 

 

When a LabView program is running it IS possible to change the setting of the controls, i.e. change the data inputs When a LabView program is running it IS NOT possible to change to wiring of the program To make changes to the program you need to stop it first!

17

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

Indicator text field

Control text field

18

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 





Selecting data range

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/Increment

19

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 meter

Name of meter

Range of meter

20

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 21

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 subwindow (There may be some problems with HELP under LINUX)

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 22

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

23

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) 24

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

25

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 All unconnected wires (dotted lines) can be removed by selecting “remove broken wires” from the “edit” menu

Broken “run” arrow

error list

26

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 structure sub palette from the functions palette 27

Incorporating a “while loop” 



Select a “while loop” from the structure palette Place while loop on diagram to surround program 



“While loop”

Click top left drag to bottom right and release

While loop will run whilst condition is true

Condition

28

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

29

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

30

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

31

To draw a sine curve in LabView 

Objective  To

plot a sine curve in the range 010π



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 32

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 loop

Terminal for N

Terminal for i 33

Wiring N on a “for loop” 

Show the front panel  



Show diagram 





Select digital control from the controls palette Place control on front panel (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!

34

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

35

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

36

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 multiply function outside loop Wire “10” and “π” into “x” function

Selecting a constant

Selecting π

37

Drawing a sine curve - defining the range (2)   

  

Select and place divide function inside loop Wire “i “into numerator of divide Wire numeric input through wall into denominator of divide Select and place multiply function Wire output of divide into multiply Wire “10 x π” multiply through loop wall into multiply 38

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 sine

39

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 graph

40

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

41

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

42

Drawing a sine curve modifying the program 

To make 10π range variable   

 



Select and place digital control on front panel Show diagram Delete 10π product 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

43

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 function

44

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

45

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

46

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

47

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

48

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

49

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 

50

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

51

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

52

Visualising the “egg box” (1) 

Show front panel 





Select and place intensity graph on front panel N.B. intensity graph is different from intensity chart! Use text tool to rename x-axis, yaxis and name of graph

Selecting an intensity graph

53

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

54

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 The exception to “dimension matching” is that one can add a number to every element in vector or array

Adding numbers

Adding vectors Adding arrays Adding a number to each element of an array 55

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 zscale and select autoscale z

Auto-scaling the z-axis of an intensity graph 56

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 format and precision window as desired NB this only affects the display NOT the precision of the calculations 57

The challenge - diffraction patterns 

To calculate and display the far field diffraction pattern of a circular aperture  





The far field diffraction pattern 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”! i.e. just take the 2D FFT of an array whose numeric values are the transmission of a circular aperture (1’s and 0’s)

Read the next few pages for some hints! 58

Useful functions for challenge (1) 

“Comparison” functions allow logic decisions 



When defining the aperture, you may need  



NB wire carrying logic, i.e. Boolean (0..1) date are green

“select” “less” or “greater”

Use LabView’s help to understand these functions 59

Useful functions for challenge (2) 

“array” functions allow manipulations of array and vectors 



When doing the FFT, you may need  



Wire containing array data appear a two parallel wires. These may be blue (for integer)or orange (for floats)

“transpose” “rotate 1D array”

Use LabView’s help to understand these functions

60

Useful functions for challenge (3) 

If the N terminal is left unwired, “for loops” will selfindex 





vector to element

array to vector

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) 61

Useful functions for challenge (4) 





Standard LabView does not have a function for 2D FFTs Given a 2D array, a 2D FFT can be completed by doing 1D FFTs on each row and each column You may need this when calculating the diffraction pattern - note use of “self-indexing”

Part of a “diagram” for completing a 2D FFT

62

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

63

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)

64

Calculating a diffraction pattern 

One program that works!  Autoscale-z

is

switched off and z-scale is manually set to reveal structure

65

Another useful function (but not needed for challenge) 

Often one uses each loop iteration to modify the value of a number 

 

The new number can be used in the next iteration

In LabView this is called a shift register To add a shift register to a loop 



Right click (windows) on the left edge of the loop and select “add shift register” The shift register looks like a down and up arrow on the left and right sides of the loop

67

Shift-registers at work 

The shift register needs a starting value 



The shift register gives an output when the loop has finished 



Wired to the down arrow on the left side of the loop

“shift register”

Wired from the up arrow on the right side of the loop

For example calculating the factorial of a number

68

Related Documents