l2 - Labview - Introduction - v22

Download as pdf or txt
Download as pdf or txt
You are on page 1of 58

FYS3240- 4240

Data acquisition & control

LabVIEW introduction
Spring 2022– Lecture #2

Note: slides marked with EXTRA is supplemental material,


meaning not relevant for exam questions.

Bekkeng 30.12.2021
Software-Defined Instrumentation

vs.

Can easily change functionality


What is LabVIEW
• LabVIEW is systems engineering software for
applications that require test, measurement, and
control.
– an Application Development Environment (ADE)

• LabVIEW uses a graphical programming approach.


– Dataflow programming.
Dataflow programming

• With a dataflow model, nodes on a block diagram are


connected to one another to express the logical execution flow
• When a block diagram node receives all required inputs, it
produces output data and passes that data to the next
node in the dataflow path. The movement of data through the
nodes determines the execution order of the functions on the
block diagram
LabVIEW advantage

• Compare with the amount of code required to make the similar


program in C/C++ for a console application (without any GUI)…
What is LabVIEW

• LabVIEW contains the same programming concepts found in most


traditional languages
– data types, loops, event handling, variables, recursion, and object-
oriented programming
• LabVIEW is very common for measurement, test, data acquisition
and control systems (both in industry and academia)
• Very easy to make a GUI suitable for test and measurements.
• Provides easy integration with thousands of hardware devices
– Device drivers
• Contains large built-in libraries
• Available for multiple targets and OS (Windows, Mac, Linux and
RTOS), including embedded hardware (FPGA-code and C-code)
• VI = Virtual Instrument.

http://www.ni.com/labview/whatis/
Install LabVIEW on own PC

• See first lecture and Canvas – Kunngjøringer


LabVIEW Hardware targets
• Standard PC
• Real-time PC
• Embedded controller (in a PXI system)
• FPGA
• 8-, 16-, and 32-bit microprocessors
• ARM Microcontrollers
– ARM = Advanced RISC Machine
Combining LabVIEW and Python
• Download version 3.6.8 from:
https://www.python.org/downloads/release/python-368/

• See Help – Find Examples..


Use MATLAB code in LabVIEW
• MATLAB is a programming platform designed specifically for
engineers and scientists.
• Very suitable for algorithm development.

• See Help – Find Examples..


• Can also call functions in separate Matlab m-script files!

Figure from: https://forums.ni.com/t5/Example-Code/Moving-to-MATLAB-Script-Nodes-from-MathScript-Nodes-in-LabVIEW/ta-p/3980734?profile.language=en


LabVIEW – Start up
• File – New VI
LabVIEW – Blank VI (Untitled)
Two windows appear – ‘Block Diagram’ & ‘Front Panel’

The block diagram contains the


graphical source code

The front panel is the user


interface (GUI) of a VI. You build
the front panel by using controls
and indicators

Select window to show:


LabVIEW – Front Panel (the GUI)
Right mouse click to open important ‘Controls’ palette:
LabVIEW– Block Diagram
Right mouse click to open ‘Functions’ palette:
Relationship between Block Diagram
and Front Panel

The block diagram contains


Icons (objects) and wires

GUI (Front Panel)


Tools palette
• Used on Block Diagram & Front Panel

Wiring tool to wire icons


together on the block diagram

Write Text
Express VI

LabVIEW Express VIs


• LabVIEW includes configuration-based Express VIs
• With Express VIs for e.g. signal processing you can interactively
explore the various analysis algorithms, while immediately seeing
the results on the configuration dialog.
• The complexity associated with adding analysis and signal
processing algorithms into your measurement and
automation applications is significantly reduced by using
Express VIs.
• You configure them with dialog boxes (instead of programming).
• The Express VIs encompass the most common functions
• However, there is some overhead involved when choosing to
use ExpressVIs instead of using lower level VIs
– The Express VIs can degrade performance (speed). Specially the
“Write to Measurement File” Express VI should not be used for high
speed data streaming in DAQ applications
Standard VIs vs. Express VIs - FFT

Easy, but less flexible and typically slower


Example with Express VIs
Tutorial Name: ‘Generate, Analyze, and Display’
(from File – New)
Example with Express VIs II
Block Diagram:
Indicators and controls
Front Panel:

Indicators

Control
LabVIEW - Indicators Front Panel

• Select the wiring tool


• Right-click the VIs I/O connections
Front Panel
LabVIEW - Controls

Right-click the
While Loop’s
“stop symbol”
LabVIEW Data Type examples
• Color coding of terminals and block Right-click
diagram wires
Floating-point numbers

Integer

String

Dynamic

Boolean

The dynamic data type is a special type for use with Express
VIs. Because dynamic data undergoes an automatic
conversion to match the indicator to which it is wired, Express
VIs can slow down the block diagram execution speed
LabVIEW Express VI – Simulate Signal

Double-click
for properties
LabVIEW Express VI – Amplitude and
Level Measurements

Double-click
for properties
LabVIEW Express VI – Write to File
LabVIEW – FFT Express VI
LabVIEW – Digital Filter Express VI
While Loop:
Loops
Functions – Programming
– Structures:

For Loop:
LabVIEW timing functions
Software Timing
• To make a while loop run at nice regular intervals add the Wait
Until Next ms Multiple
– always use the Wait Until Next ms Multiple (or another
timer) in a loop to avoid using unnecessary CPU power.
– without any “wait” a while loop will run as fast as possible ...
• Two loops can be software synchronized using the Wait Until
Next ms Multiple in both loops.

• To prioritize execution of different parallel loops use Wait


functions to slow down lower priority loops in the application.
Loop Communication mechanisms

• Variables
• Occurrences
• Notifier
• Queues
• Semaphores
• Rendezvous

communication Local variable


Queues
• Used for synchronization and data transfer between loops
• Data are stored in a FIFO buffer, and the useful queue depth is limited
(only) by the computer’s memory (RAM).
– No data are lost
• A read (dequeue) from the queue is destructive
– Data can only be read by one consumer loop (without a new enqueue)
• Different queues must have unique names!
Adding Elements to the Queue

Select the data


type the queue will hold

Reference to existing queue in memory

Dequeueing Elements

Dequeue will wait for data or time-out


Program Start, Abort execution and Error
indication

• Aborting a VI that uses external


resources, such as external
hardware, might leave the
resources in an unknown state by
not resetting or releasing them
properly. Design the VIs you
create with a stop button and use
Start (RUN) program button it to avoid this problem.

Program Running indicator

Broken arrow – error in program

Abort Execution button


Extra

How VIs are compiled


• When you push the Run button, LabVIEW (the G- compiler)
translates the block diagram into clumps of machine code for
your platform
• LabVIEW will automatically compile your VI during load,
run or save (if necessary). In general, any change that is non
cosmetic will set a flag indicating that the VI needs to be
recompiled. When this flag is set the VI will automatically
compile when you run or save.
• Beginning with LabVIEW 2009 and continuing in LabVIEW
2010 many optimizations were added to the LabVIEW compiler
to speed up run-time performance of both VIs and executables

Start (RUN) program button


LabVIEW debugging techniques

• Execution highlighting

• Single-stepping

• Probe

Right-click wire

• Breakpoints
Extra

Projects in LabVIEW

• Projects in LabVIEW consist of VIs, files necessary for those VIs to run
properly, and supplemental files such as documentation or related
links. Use the Project Explorer window to manage projects in
LabVIEW

• File – New Project

• Adding files to the project:


– Right-click “My Computer”, and select Add – File ..
Extra

Creating Executables (EXE-file)


• Create a stand-alone windows application (*.exe file)
– You must have a project open and saved to configure a
build specification.
– The LabVIEW Run-Time Engine must be installed on any
computer on which users run the application or shared
library.
– You can include the LabVIEW Run-Time Engine in an
installer
• Create the EXE-file first
• Then, add the EXE file to the installer
Do and don't
• Avoid “spaghetti code”!
•  Select a suitable architecture

• Document your code.

• Limit the use of local variables


– They create copies!

• Try to avoid using global variables


– They destroy the dataflow programming, and can create race conditions.

https://blog.digilentinc.com/4-rookie-labview-mistakes-and-how-to-prevent-them/#comments
Sample projects
• File – Create project

A very god starting point


for advanced (parallel and
scalable) DAQ programs!
Extra

Some GUI tricks


• Nice new buttons found under Silver – Boolean - Buttons

• Checkbox
– Under System
Extra

Make a nice SubVI icon


• Right click and Select Edit icon

• Edit-clear
• Draw a black frame around the icon
• Select suitable Glyphs and Icon text
LabVIEW – Help I
• Right-click an icon (VI), and select Help.
LabVIEW – Help II
• Select Help»Show Context Help from the front panel or the block
diagram
• Move the cursor over to the graphical symbol to see the help
information
• Very useful when looking at functions in the ‘Functions’ palette:
LabVIEW Help III

Can use existing Examples as a


starting point!
NI Example Finder
• Search or browse through example programs
• Modify an existing example program to fit your application
• Copy and paste from an example into your own program
LabVIEW Help III - www.ni.com
• Make a search for solution to problems or to find source
code!
Building an application …
• Chose a design architecture
(design pattern)
• Start with a paper design ….
– draw block diagrams
– draw flow charts/state
diagrams
• Prototype the user interface
– helps defining necessary
controls and indicators
• Divide-and-conqure
– break the problem(s) into
manageable blocks
– make SubVIs for each
function
– put the entire design together
Additional “advanced” information
Extra

Event Structure
• To limit the CPU usage while waiting
for user interface events (mouse
clicks, key pressed etc.)
– Avoids polling!
• Detects all events!
• Do minimal processing inside event
structures!
• How it works:
– Operating system broadcasts
system events (mouse click,
keyboard, etc.) to applications
– Registered events are captured by
event structure and executes
appropriate case
– Event structure enqueues events
that occur while it’s busy
Extra

How LabVIEW Implements Multithreading


• Parallel code paths (not dependent on other) on a block
diagram can execute in unique threads
• LabVIEW automatically divides each application into multiple
execution threads (originally introduced in 1998 with LabVIEW
5.0)
Extra

How LabVIEW Implements Multithreading


Extra

Connectivity – Using DLLs in LabVIEW


• Call Library Function
– To use DLLs in LabVIEW
– Almost any compiler can generate a DLL
Extra

State machines - background

Static Sequence
Known order of execution

Dynamic Sequence
Distinct states can operate
in a programmatically
determined sequence
Extra

State machine design


1. Draw the state diagram
2. Translate the state diagram into LabVIEW code

1 2
Extra

Visualization
• Displaying data can require
considerable computer
resources
• Improving display performance:
– using smaller graphs and
images
– display fewer data points
(down sampling)
– less frequent display updates

You might also like