eet-241: programming for electronicsspot.pcc.edu/~wlara/eet241/eet241-lect-slides.pdf · a...

26
EET-241: Programming For Electronics PCC Walter Lara

Upload: others

Post on 28-Jan-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

EET-241: Programming For Electronics

PCC

Walter Lara

Page 2: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

A Graphical Programming Language

• Allows to create programs with graphical symbols instead of text code like traditional programming languages (C, C++, Java, etc.)• Performs many of the same functions requiring less time and programming

experience

• LabView programs are called Virtual Instruments (VI)

• Because of their appearance and operation VI imitate actual instruments• However, they are analogous to main programs, functions and subroutines

from traditional languages

Page 3: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Why LabView?

• Ideal for experimental lab simulations because the VI actually imitate real-world instruments.

• Replacing actual instruments with virtual instruments allows flexibility and reduced project cost avoiding to purchase expensive laboratory hardware to perform their functions.

Page 4: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

VI Architecture

• A VI consist of two main part which appear as two major windows on the development environment:• The Front Panel

• The Block Diagram

Page 5: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

The Front Panel

• The Front Panel is a window where you create your virtual instruments.

• This is where the user interacts with the program by entering data and viewing results. It is called the Front Panel because it is supposed to look like the front panel of an instrument or a group of instruments.

• The Front Panel virtual instruments generally come in two forms: user inputs called controls and the program outputs called indicators.

Page 6: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Front Panel Example

Page 7: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

The Block Diagram

• The Block Diagram is a window where the graphical code is created. This is the "programming" that replaces text syntax in traditional programming languages.

• What you see in this window are icons called nodes which are classified as:• Terminals - represent the controls and indicators on the Front Panel.

• Functions – operations like add, subtract, compare or constant

• Structures – program flow constructs such as while loops, for loops and case and sequence structures

• Nodes are wired together for logical functioning of the program• Have one or more input and/or output terminals called connectors to wire to and

from.

Page 8: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Block Diagram Example

Page 9: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

A Dataflow Programming Language

• Labview uses dataflow:• A node executes its function only after it has received data from a previous

node.

• After the node is through with its function, the processed data is transferred via the wire to the next node.

• Traditional text-based languages (C, C++, Java, etc.) use control flow• Code executes sequentially in the order in which is written

Page 10: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Waveform Chart

• The Waveform Chart acts as a real-time data plotter

• As each new data point is generated on the block diagram, this single value is passed to the Waveform Chart’s terminal and immediately displayed on the front-panel plot

• Found on front panel under Controls->Modern->Graph->Waveform Chart

Page 11: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Waveform Graph

• The Waveform Graph accepts an entire block of data that has been generated previously

• The Waveform Graph’s terminal accepts data as a one-dimensional array:• Numerical value is y-value of the plot

• Index is x-value

• Found on front panel under Controls->Modern->Graph->Waveform Graph

Page 12: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

The While Loop

• A Structure used to control repetitive operations

• Executes the subprogram (called subdiagram) within its borders until a specified Boolean value is no longer FALSE

• Equivalent Pseudo-code:Do

Execute subprogram (which sets condition)While condition is FALSE

• Iteration terminal (i) initialized to zero and incremented at the end of each iteration if condition is FALSE.

• Found under Functions->Programming->Structures->While Loop

Page 13: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

The For Loop

• Another Structure used to control repetitive operations

• Executes the subprogram (called subdiagram) within its borders the number of times specified by the count terminal (N)

• Equivalent Pseudo-code:For i = 0 to N -1

Execute subprogram (which sets condition)

• Found under Functions->Programming->Structures->For Loop

Page 14: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Wire Colors

Page 15: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

MathScript & Formula Nodes

• Encoding mathematical relations using graphical programming can be more cumbersome than using text-based languages

• LabView solution: MathScript Node• Resizable box that allows entering text-based math formulas directly onto

Block Diagram• C-like syntax• Supports common math operations (+, -, x …), trigonometric & logarithm

functions, Boolean algebra, comparison and conditional branching• Arrays and iteration capabilities• Available from Functions->Programming->Structures

• Formula Node supports subset of MathScript Node

Page 16: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

XY Graph

• Produces Cartesian-style plots.• Each point located at its x, y value

• The XY Graph’s terminal accepts a cluster of two one-dimensional arrays:• Array of X values

• Array of Y values

• Found on front panel under Controls->Modern->Graph->XY Graph

Page 17: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

USB-6008 Device

• Low-cost, multifunction data acquisition device (DAQ)

• USB interface

• Eight analog input (AI) channels (differential or single-ended):• Range: ±20 V• Resolution: 12-bit differential or 11-bit single-ended• Maximum Sample Rate: 10 KS/s• On-demand or buffered hardware-timed support

• Two analog output (AO) channels• Range: 0 to +5 V• Resolution: 12-bit• Maximum Update Rate: 150 S/s

Page 18: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

USB-6008 Device (Cont’d)

• Twelve digital input/output channels (open-collector)

• One configurable input (PFI 0)that can be use as:• Digital trigger input

• Event counter input

Page 19: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

USB-6008 Pinout

Page 20: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

DAQmx Simulated Device

• Replica of any device

• Allows to develop/operate any program without hardware

• Behave similar to a real device

• Analog input is limited to a noisy sine wave

• Analog output only verify data against valid limits

• Created via MAX

Page 21: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Shift Registers

• Allows values created on a previous iteration of a loop to be used on the current iteration

• A set of terminals on the loop behave as a First-In, First-Out (FIFO) digital shift register

Page 22: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

The Case Structure

• Allows conditional branching in LabView• Analogous to if-else statement in text-based languages

• Found under Function-Programming->Structures

• Argument can be Boolean, Numeric, Enum or String depending on value wired to its terminal

Page 23: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

State Machines• State Machines can be created with a while loop, a shift register and a

case structure• While loop execute state cases

• Shift register keeps next state

• Case structure define per-state actions, next state and when to stop

Page 24: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Object Oriented Programming (OOP)• An Object is a collection of data and methods that interact with that

data

• A class is the data type of an Object

• Object oriented languages have features to make OOP easier• C++, C#, Java, Python and LabView

• Main benefit is that code is:• Easier to write

• More stable

• Easier to maintain

Page 25: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

Basic Object-Oriented Concepts• Encapsulation: consolidation of data and methods into an object with

restricted access to data• Use of accessor methods

• Inheritance: technique to allow reusing a class a start point for another one by sub-typing

• Subtypes inherit method implementations from supertype

• Polymorphism: technique that allows for a variable, method or object to take on multiple forms• Subtypes override method implementations from supertype

Page 26: EET-241: Programming For Electronicsspot.pcc.edu/~wlara/eet241/EET241-Lect-Slides.pdf · A Graphical Programming Language ... •Ideal for experimental lab simulations because the

OOP in Labview• An Object is like a very smart cluster

• Composite of other data types

• Uses bundle and unbundle

• A class is an user-defined data type implemented as a library (.lvclassfile)

• Each Labview class consists of:• A data control (defines the cluster)

• Additional VI to access data (read/write)

• Additional VI to implement methods

• Properties