Lab view introduction-threehour

50
Virtual Instrumentation With LabVIEW

Transcript of Lab view introduction-threehour

Page 1: Lab view introduction-threehour

Virtual Instrumentation With LabVIEW

Page 2: Lab view introduction-threehour

Course GoalsCourse Goals

• Understand the components of a Virtual InstrumentUnderstand the components of a Virtual Instrument• Introduce LabVIEW and common LabVIEW functions • Build a simple data acquisition application• Create a subroutine in LabVIEWCreate a subroutine in LabVIEW

Page 3: Lab view introduction-threehour

Section ISection I

• LabVIEW termsLabVIEW terms• Components of a LabVIEW application• LabVIEW programming tools• Creating an application in LabVIEWCreating an application in LabVIEW

Page 4: Lab view introduction-threehour

LabVIEW Programs Are Called Virtual Instruments (VIs)

Front Panel• Controls = Inputs

O• Indicators = Outputs

Block Diagram• Accompanying “program”Accompanying program

for front panel• Components “wired”

together

Page 5: Lab view introduction-threehour

VI Front PanelVI Front PanelFront Panel Toolbar

IconToolbar

G hBooleanControl Graph

LegendControl

WaveformWaveformGraph

PlotL d

ScaleL dLegend Legend

Page 6: Lab view introduction-threehour

VI Block DiagramgBlock Diagram

SubVI

Toolbar DivideFunction

GraphTerminal

SubVI

Wire Data

Terminal

Data

While LoopStructure

Numeric Constant

Timing Function

Boolean Control Terminal

Page 7: Lab view introduction-threehour

Express VIs, VIs and FunctionsExpress VIs, VIs and Functions• Express VIs: interactive VIs with configurable dialog page• Standard VIs: modularized VIs customized by wiring• Functions: fundamental operating elements of p g

LabVIEW; no front panel or block diagramFunctionFunction

Express VIExpress VI Standard VIStandard VI

Page 8: Lab view introduction-threehour

Controls and Functions PalettesControls and Functions Palettes

Controls Palette(Front Panel Window)

Functions Palette(Block Diagram Window)

Page 9: Lab view introduction-threehour

Tools Palette• Floating Palette• Used to operate and modify• Used to operate and modify

front panel and block diagram objects.j

Automatic Selection Tool

Operating Tool

Positioning/Resizing Tool

Scrolling Tool

Breakpoint Tool

Labeling Tool

Wiring Tool

Probe Tool

Color Copy ToolWiring Tool

Shortcut Menu Tool

Color Copy Tool

Coloring Tool

Page 10: Lab view introduction-threehour

Status Toolbar

R B tt

Status Toolbar

Run Button

Continuous Run Button Additional Buttons on the Diagram Toolbar

Abort Execution

Pause/Continue Button Execution Highlighting Button

g

Text Settings

Align ObjectsStep Into Button

Step Over ButtonDistribute Objects

Reorder

Step Over Button

Step Out Button

Resize front panel objects

Page 11: Lab view introduction-threehour

Open and Run a Virtual InstrumentOpen and Run a Virtual InstrumentExample finder

Page 12: Lab view introduction-threehour

Creating a VIFront Panel Window

Creating a VI

Block Diagram WindowBlock Diagram Window

ControlTerminals

Indicator Terminals

Page 13: Lab view introduction-threehour

Creating a VI – Block Diagramg g

Page 14: Lab view introduction-threehour

Wiring Tips – Block DiagramWiring Tips Block DiagramWiring “Hot Spot” Click To Select Wires

Clean Up WiringUse Automatic Wire Routing

Page 15: Lab view introduction-threehour

Dataflow Programming• Block diagram executes

dependent on the flo of data

g g

dependent on the flow of data; block diagram does NOT execute left to rightexecute left to right

N d t h d t i • Node executes when data is available to ALL input terminals

• Nodes supply data to all output t i l h dterminals when done

Page 16: Lab view introduction-threehour

Help OptionsHelp Options

C t t H lContext Help• Online help• Lock helpLock help• Simple/Complex Diagram help• Ctrl + H

Online reference• All menus online• Pop up on functions in diagram to access online info directly

Page 17: Lab view introduction-threehour

Exercise 1 - Convert °C to °FExercise 1 Convert C to F

Page 18: Lab view introduction-threehour

Debugging TechniquesDebugging Techniques• Finding Errors

• Execution Highlighting

Click on broken Run buttonWindow showing error appears

• Execution HighlightingClick on Execution Highlighting button; data flow is animated using bubbles. Values are

• Probe

gdisplayed on wires.

Ri ht li k i t di l b d itRight-click on wire to display probe and it shows data as it flows through wire segment

You can also select Probe tool from Tools palette and click on wire

Page 19: Lab view introduction-threehour

Section II – SubVIsSection II SubVIs

• What is a subVI?• Making an icon and • Making an icon and

connector for a subVIUsing a VI as a s bVI• Using a VI as a subVI

Page 20: Lab view introduction-threehour

Block Diagram NodesBlock Diagram Nodes

Icon Expandable Node Expanded Node Icon Expandable Node Expanded Node

• Function Generator VI• Same VI, viewed three different waysSame VI, viewed three different ways• Yellow field designates a standard VI

Blue field designates an Express VI• Blue field designates an Express VI

Page 21: Lab view introduction-threehour

SubVIsSubVIs• A SubVI is a VI that can be used within another VI• Similar to a subroutine• Advantagesg

– Modular– Easier to debugas e to debug– Don’t have to recreate code– Require less memoryRequire less memory

Page 22: Lab view introduction-threehour

Icon and Connector

• An icon represents a VI in other block di

Icondiagrams

• A connector shows available Terminals

A connector shows available terminals for data transfer

ConnectorConnector

Page 23: Lab view introduction-threehour

SubVIs S b VIS b VISubVIs Sub VIsSub VIs

Page 24: Lab view introduction-threehour

Steps to Create a SubVISteps to Create a SubVI

• Create the IconCreate the Icon• Create the Connector• Assign Terminals• Save the VISave the VI• Insert the VI into a Top Level VI

Page 25: Lab view introduction-threehour

Create the IconCreate the Icon• Right-click on the icon in the block diagram or front panel

Page 26: Lab view introduction-threehour

Create the ConnectorCreate the ConnectorRight click on the icon pane (front panel only)

Page 27: Lab view introduction-threehour

Assign TerminalsAssign Terminals

Page 28: Lab view introduction-threehour

Save The VISave The VI

• Choose an Easy to Remember Locationy• Organize by Functionality

– Save Similar VIs into one directory (e g Math Utilities)– Save Similar VIs into one directory (e.g. Math Utilities)• Organize by Application

S ll VI U d f S ifi A li ti i t– Save all VIs Used for a Specific Application into one directory or library file (e.g. Lab 1 – Frequency Response)Response)

• Library Files (.llbs) combine many VI’s into a single file, ideal for transferring entire applications across computers

Page 29: Lab view introduction-threehour

Insert the SubVI into a Top Level VIInsert the SubVI into a Top Level VIAccessing user-made subVIs

Functions >>All Functions >> Select a VIOr

D i diDrag icon onto target diagram

Page 30: Lab view introduction-threehour

Tips for Working in LabVIEWTips for Working in LabVIEW

• Keystroke Shortcutsy– <Ctrl-H> – Activate/Deactivate Context Help Window– <Ctrl-B> – Remove Broken Wires From Block DiagramCtrl B Remove Broken Wires From Block Diagram– <Ctrl-E> – Toggle Between Front Panel and Block

Diagramg– <Ctrl-Z> – Undo (Also in Edit Menu)

• Tools » Options… – Set Preferences in LabVIEWTools » Options… Set Preferences in LabVIEW• VI Properties – Configure VI Appearance, Documentation etcDocumentation, etc.

Page 31: Lab view introduction-threehour

Section III – Data AcquisitionSection III Data Acquisition

DAQ Device• Data acquisition (DAQ) basics• Connecting Signals• Simple DAQ application

Computer

Sensors

Terminal Block

Cable

Page 32: Lab view introduction-threehour

DAQ – Data AcquisitionDAQ Data AcquisitionTemperature Acquisition using the DAQ Assistant

Page 33: Lab view introduction-threehour

Data Acquisition TerminologyData Acquisition Terminology

• Resolution - Determines How Many Different Voltage Resolution Determines How Many Different Voltage Changes Can Be Measured

Larger Resolution More Precise Representation of Signal– Larger Resolution More Precise Representation of Signal• Range - Minimum and Maximum Voltages

– Smaller range More Precise Representation of Signal• Gain Amplifies or Attenuates Signal for Best Fit in • Gain - Amplifies or Attenuates Signal for Best Fit in Range

Page 34: Lab view introduction-threehour

Hardware ConnectionsHardware Connections

SC-2075BNC-2120

SC 2075

SCB-68

NI-ELVIS

SCB-68

Page 35: Lab view introduction-threehour

Exercise 2 – Simple Data AcquisitionExercise 2 Simple Data AcquisitionComplete Convert C to F.vi, then create Thermometer.vi.

Page 36: Lab view introduction-threehour

Section IV – Loops and ChartsSection IV Loops and Charts

• For Loopp• While Loop• Charts• Charts• Multiplots

Page 37: Lab view introduction-threehour

LoopsLoops

• While Loopsp– Have Iteration Terminal– Always Run at least Once– Run According to Conditional

Terminal

• For LoopsHave Iteration Terminal– Have Iteration Terminal

– Run According to input N of Count Terminal

Page 38: Lab view introduction-threehour

Loops (cont.)p ( )1. Select the loop 2. Enclose code to be repeated

3. Drop or drag additional nodes and then wire

Page 39: Lab view introduction-threehour

ChartsCharts

Waveform chart – special numeric indicator that can display a history of values

Controls >> Graph Indicators >> Waveform Chart

Page 40: Lab view introduction-threehour

Wiring Data into ChartsWiring Data into Charts

Single Plot Charts Multiplot Chartsg p

Page 41: Lab view introduction-threehour

Exercise 3 – Using loops Exercise 3 Using loops Students build Use a loop.vi.

Page 42: Lab view introduction-threehour

Section V – Arrays & File I/OSection V Arrays & File I/O• Build arrays manually• Have LabVIEW build arrays automatically• Write to a spreadsheet filep• Read from a spreadsheet file

Page 43: Lab view introduction-threehour

Adding an Array to the Front PanelAdding an Array to the Front PanelFrom the Controls >> All Controls >> Array and Cl t b l tt l t th A Sh llCluster subpalette, select the Array Shell

Drop it on the screen.

Page 44: Lab view introduction-threehour

Adding an Array (cont.)Adding an Array (cont.)

Place data object into shell (i.e. Numeric Control)j ( )

Page 45: Lab view introduction-threehour

Creating an Array with a LoopCreating an Array with a Loop

• Loops accumulate arrays at their boundariesp y

Page 46: Lab view introduction-threehour

Creating 2D ArraysCreating 2D Arrays

Page 47: Lab view introduction-threehour

File I/OFile I/OFile I/O – passing data to and from files- Files can be binary, text, or spreadsheet- Write/Read LabVIEW Measurements file (*.lvm)( )

Writing to LVM fileWriting to LVM file Reading from LVM fileReading from LVM file

Page 48: Lab view introduction-threehour

Write LabVIEW Measurement FileWrite LabVIEW Measurement File• Includes the open, write, close and error handling functions

f• Handles formatting the string with either a tab or comma delimiter

• Merge Signals function is used to combine data into the dynamic data type

Page 49: Lab view introduction-threehour

Exercise 4 – Analyzing and Logging DataExercise 4 Analyzing and Logging DataStudents build Temperature Logger.vi

Page 50: Lab view introduction-threehour

Where Do I Go From Here?Where Do I Go From Here?

• Example programs (Help» Find Examples…)Example programs (Help» Find Examples…)• LabVIEW Student Edition (www.ni.com/labviewse)• Web resources (ni.com)

– NI Developer Zone (zone.ni.com)NI Developer Zone (zone.ni.com)– Application Notes

Info labview newsgroup (www info labview org/)– Info-labview newsgroup (www.info-labview.org/)– Instrument Driver Library (www.ni.com/idnet)