labview notebook

45
Danny Vu Page 1 6/7/2022 LABVIEW NOTES Design Guides: Software Development Method: 1. Scenario: define the problem 2. Design: Identify the inputs and outputs 3. Implementation: Apply an algorithm or flowchart 4. Testing: Verify the VI 5. Maintenance: Update the VI To design large Labview projects, begin with a top-down approach: Define the general characteristics and specifications of the project. Define specific tasks for the general specifications After defining the tasks the application must perform, develop VIs You will assemble to form the completed project. This sub VI development represents the bottom-up development period. Test and release final product Process customer feedback. Note: The lead developer gives you the inputs of the VI, the algorithm and the expected outputs. Build and document a VI based on the design given. Remember the following development guidelines: Accurately define the system requirements Clearly determine expectations of the end user Document what the application must accomplish Plan for future modifications and additions General VI Architecture: Parallel Loop VI Architecture: You can not use wires to pass data between loops because doing so prevents the loops

Upload: tvu0244689

Post on 03-Mar-2015

94 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Labview Notebook

Danny Vu Page 1 4/10/2023

LABVIEW NOTESDesign Guides:

Software Development Method:1. Scenario: define the problem

2. Design: Identify the inputs and outputs3. Implementation: Apply an algorithm or flowchart

4. Testing: Verify the VI5. Maintenance: Update the VI

To design large Labview projects, begin with a top-down approach: Define the general characteristics and specifications of the project. Define specific tasks for the general specifications After defining the tasks the application must perform, develop VIs

You will assemble to form the completed project. This sub VI development represents the bottom-up development period.

Test and release final product Process customer feedback.

Note: The lead developer gives you the inputs of the VI, the algorithm and the expected outputs. Build and document a VI based on the design given.

Remember the following development guidelines: Accurately define the system requirements Clearly determine expectations of the end user Document what the application must accomplish Plan for future modifications and additions

General VI Architecture:

Parallel Loop VI Architecture: You can not use wires to pass data between loops because doing so prevents the loops

from running in parallel. Instead, you must use a messaging technique for passing information among

processes.

Multiple Case Structure VI Architecture: Use a single loop that contains separate Case Structures to handle each task. With this architecture you can end up large block diagrams and, consequently hard to

read, edit, and debug. Also, because all case structures are in the same loop, each one is handled serially.

This method reduces the need for using global variables.

I>> Creating SubVI:

Page 2: Labview Notebook

Danny Vu Page 2 4/10/2023

II>> Controlling Program:

1. While Loop:

Stop If True: If the value is FALSE (meaning “no, don’t stop the loop”)

Continue If True: Cont if the condition is True; if the value is FALSE, stop the loop.

Ex: Compare the contents of an array, if it’s false, stop the loop. Cont if it’s true.

An indicator inside a loop (updated each iteration)

Page 3: Labview Notebook

Danny Vu Page 3 4/10/2023

An indicator outside a loop (updated only once, on loop completion)

2. The For Loop:A for loop executes the code inside its borders, called its subdiagram, for a total of count times.

For Example: if N=10, the loop will execute 10 times from iteration i=0 to 9

3. Shift Registers:

Page 4: Labview Notebook

Danny Vu Page 4 4/10/2023

Shift register is a special type of variable used to transfer values from one iteration of a loop to the next.

You can configure the shift register to remember values from several previous iterations, as shown below, a useful feature when you’re averaging data values acquired in different iterations.

Ex:

You can have many different shift registers storing many different variables on the same loop.

Page 5: Labview Notebook

Danny Vu Page 5 4/10/2023

Initializing Shift Registers: to avoid unforeseen and possible nasty behavior, you should always initialize your shift registers unless you have a specific reason not to and make a conscious decision to that effect.

Ex: the two loops in the left column show what happens when you run a program that contains an initialized shift register twice. The right column shows what happens if you run a program containing an uninitialized shift register two times.

Page 6: Labview Notebook

Danny Vu Page 6 4/10/2023

4. The Case Structure:A Case Structure is sort of like an “if-then-else” statement:

If a Boolean value is wired to the selector terminal, the structure has two cases: FALSE and TRUE. If

If a numeric or string data type is wired to the selector, the structure can have from one to almost unlimited cases.

You can separate more than one value for a case, separated by commas.

Page 7: Labview Notebook

Danny Vu Page 7 4/10/2023

Use this state machine to execute the codes when it needs to run in the order. This type of state machine will simply go to the next state in the sequence.

A second way to implement the sequence-style state machine is to use a shift register to control the case structure. The shift register is initialized to the first case, and inside each case the number wired the shift register is incremented by one.

5. The Sequence Structure Flat or Stacked:

A Sequence Structure executes frame 0, followed by frame 1, then frame 2, until the last frame executes. Only the last frame completes does data leave the structure. There are two Sequence Structure: the Flat Sequence Structure and the Stacked Sequence Structure, shown below.

Page 8: Labview Notebook

Danny Vu Page 8 4/10/2023

Regardless of appearance, either type of Sequence Structure (Flat or Stacked) executes code exactly in the same manner. You can easily convert one into the other by selecting from its pop-up menu.

6. Timing:

It’s “time” for another digression. Timing functions are very important in Labview and help you measure time, synchronize tasks, and allow enough idle processor time so that loops in your VI don’t race too fast and hog the CPU.

Wait(ms) : causes your VI to wait a specified number of ms before it continues execution

Wait Until Next ms Multiple : causes Labview to wait until the internal clock equals or has passed a multiple of the ms multiple input number before continuing VI execution.

Tick Count (ms) : returns the value of your operating system’s internal clock in ms; it is commonly used to calculate elapsed time.

Time Delay: works like wait(ms) except that you specify the time in seconds.

Elapsed Time: The Boolean output will return a TRUE if the specified amount of time has elapsed; otherwise, it returns a FALSE.

Ex: Build a VI that computes the time it takes to match an input number with a randomly generated number.

Page 9: Labview Notebook

Danny Vu Page 9 4/10/2023

Design Inputs: Number to Match (control), Random Number

Design Outputs: Time to Match (indicator), Current Number (indicator), Number of iterations (indicator)

Algorithm: Get Initial Time Enter number to match (round to the nearest decimal

If random number (round to the nearest decimal) ≠ Number to match True Loops.

If random number (round to the nearest decimal) ≠ Number to match False

Tick Count (ms) – Tick Count (initial time) convert from ms to sec display Time to match.

7. The Formula Node:

With the Formula Node, you can directly enter a formula or formulas, in lieu of creating complex block diagram subsections.

Page 10: Labview Notebook

Danny Vu Page 10 4/10/2023

The following example computes the square root of x if x is positive, and assigns the result to y. If x is negative, the code assigns value of 99 to y.

The example shown below uses the formula node to evaluate the equation y=sin(x) and graph the results.

8. The Expression Node:

The Expression Node is basically just a simplified Formula Node having just one unnamed input and one unnamed output. It’s found in Programming>>Numeric palette

9. The While Loop + Case Structure Combination

We add a Case Structure inside a While Loop, used to execute work when the user presses a button.

Page 11: Labview Notebook

Danny Vu Page 11 4/10/2023

To handle multiple work items in our While Loop + Case Structure, we will need to build a Boolean array of button values and search for the index of the element that is TRUE. - Build Array converts two Booleans into a 1D array of Booleans - Search 1D Array tells us which button number was pressed -1: No button was pressed 0: Say something was pressed 1: Play a sound was pressed.

III >> ARRAYS:

Page 12: Labview Notebook

Danny Vu Page 12 4/10/2023

Scalar type is simply a data type that contains a single value, or “non-array”. Array is a collection of data elements that are all the same type. An array can have one or more dimensions, and up to 2^31 – 1 elements per dimension (memory permitting, of course).

Front Panel showing an empty array shell(A) and three populated shells (B)

The example below shows a For Loop auto-indexing an array at its boundary. each iteration creates the next array element. Notice the wire becomes thicker as it changes to an array wire type.

If indexing is enabled as in loop (A), the loop will index off one element from the array each time it iterates. If indexing is disabled as in loop (B), the entire array passes into the loop at once.

When you enable auto-indexing on an array entering a For Loop, LabView automatically sets the count to the array size, thus eliminating the need to wire a value to the count terminal. LabView sets the count to the smallest of the choices if two arrays are enabled at the auto-indexing.

Page 13: Labview Notebook

Danny Vu Page 13 4/10/2023

Creating two dimensional arrays: the For Loop executes a set number of times.

Ex:

Ex: the example shown below is to create a 1D array using a While Loop. You must hit the STOP button to halt the While Loop or it will stop after 101 times. Need to enable indexing to get the array data out of the While Loop.

FUNCTIONS FOR MANIPULATING ARRAYS

Page 14: Labview Notebook

Danny Vu Page 14 4/10/2023

Initialize Array: this function is useful for allocating memory for arrays of a certain size or for initializing shift registers with array type data.

Array Size: returns the number of elements in the concatenated array.

Array Subset: returns a portion of an array starting at index and containing length elements.

Index Array: use to access a particular element of an array

Page 15: Labview Notebook

Danny Vu Page 15 4/10/2023

Example to extract a column and row from a 2D array

Delete From Array: delete a portion of an array starting at index and containing length elements.

Build Array Function: to concatenate the input data to create a new array in the following sequence: Initial Array + Element 1 + Element 2 + Terminal Array.

Page 16: Labview Notebook

Danny Vu Page 16 4/10/2023

Polymorphism:

Polymorphism is just a big word for a simple principle: the inputs to these functions can be of different size and representation.

Notes: If you are doing arithmetic on two arrays with different number of elements, the resulting array will be the smaller of the two.

An example of a VI that demonstrate the Polymorphism of an array

Page 17: Labview Notebook

Danny Vu Page 17 4/10/2023

The graph will plot each array element against its index for all 4 arrays at once. The results demonstrate several applications. For example, Array 1 and Array 2 could be incoming waveforms that you wish to scale.

Compound Arithmetic Function:

AND, OR, and XOR are Boolean arithmetic operations. Select the Invert pop-up option to invert the sign of numeric inputs and outputs or

the value of Booleans (from FALSE to TRUE or vice versa)

Page 18: Labview Notebook

Danny Vu Page 18 4/10/2023

The two equivalent operations on the left show how you can use the compound arithmetic node for combined addition and subtraction. The two operations on the right show how you can use the compound function for combined multiplication and division

IV>> ALL ABOUT CLUSTERS:

You can access cluster elements by unbundling them all at once or by indexing one at a time, depending on the function you choose. Clusters must have the same number of elements and each element must match in both data type and order.

Creating Cluster Controls and Indicators:

Page 19: Labview Notebook

Danny Vu Page 19 4/10/2023

Like Arrays, all Objects inside a cluster must be all controls or all indicators. You can not combine both controls and indicators inside the same cluster. Cluster can group data of different type (i.e., numeric, Boolean, etc.)

Bundle Function: assembles individual components into a new cluster or allows you to replace elements in an existing cluster.

Unbundling Clusters: The Unbundle Function splits a cluster into each of its individual components. The output components are arranged from top to bottom in the same order they have in the cluster, meaning first in first out.

Ex: Boolean 2 unbundled before Boolean 1 since Boolean 2 deposit into the cluster before Boolean 1

Unbundle by Name: returns elements whose name(s) you specify so that we don’t have to worry about the cluster order or correct unbundled function size.

Page 20: Labview Notebook

Danny Vu Page 20 4/10/2023

Bundle By Name Function:

The below example checks whether the value of the numeric 1 digital control is ≥ 0; if it’s less than zero, the VI will take the absolute value of all controls and multiply by 0.5 of the entire cluster. If it’s ≥ 0, the VI multiplies all values by 0.5 and displays the results in Output Cluster.

Interchangeable Arrays and Clusters:

Page 21: Labview Notebook

Danny Vu Page 21 4/10/2023

Error Clusters and Error Handling Functions:

Page 22: Labview Notebook

Danny Vu Page 22 4/10/2023

V>> VISUAL DISPLAYS: CHARTS and GRAPHS:

Waveform Charts: Most often used inside loops, charts retain and display previously acquired data, appending new data as they become available in a continuously updating display.

You can also update a single-plot chart with multiple points at a time, by passing it an array of values.

Page 23: Labview Notebook

Danny Vu Page 23 4/10/2023

Waveform charts can also accommodate more than one plot, using the Bundle function to group the outputs of 3 different VIs into a cluster so they can be plotted on the waveform chart.

Page 24: Labview Notebook

Danny Vu Page 24 4/10/2023

Waveform Graphs:

Unlike charts, which plot continuously acquired data, graphs plot pre-generated arrays of data all at once. They do not have the ability to append new values to previously generated data.

Sometimes you will want the flexibility to change the time base for the graph.

Multi-Plot Waveform Graphs: use the Build Array Function to create a 2D array out of two 1D arrays. Notice that this 2D array has two rows with 100 columns (2x100)

Page 25: Labview Notebook

Danny Vu Page 25 4/10/2023

These waveform graphs below show how to plot the graph with system time.

Page 26: Labview Notebook

Danny Vu Page 26 4/10/2023

XY GRAPHS: XY graph used to plot a math function that has multiple Y values for every X value.

Page 27: Labview Notebook

Danny Vu Page 27 4/10/2023

You can also create a single plot from an array of XY cluster “coordinate pairs,” as shown below. The only downside of this single plot format is that you can not create a multi-plot by building an array of this type of single plots.

Page 28: Labview Notebook

Danny Vu Page 28 4/10/2023

Note: to convert from radian to degree: 180/π x Radian =Degree

Ex: build a VI that measures temperature approximately every .25sec for 10 secs. During the acquisition, the VI displays the measurements in real time on a waveform chart. After the acquisition is complete, the VI plots the data on a graph and calculates the minimum, maximum, and average temperatures.

Thermometer.vi

Demo TemperatureRead.vi

Page 29: Labview Notebook

Danny Vu Page 29 4/10/2023

VI>> Time Stamps, Waveforms, and Dynamic Data:

Get Date/Time In Seconds function: return a timestamp of a current time

Ex: Calculates the time required to execute the code in the center frame of a Flat Sequence Structure

Waveforms Palette:

returns the waveform components you specify. You specify components by right-clicking and selecting Add Element and creating an indicator.

Analog waveform palette are used to perform arithmetic and comparison functions on waveforms, such as adding, subtracting, multiplying, finding the max and min points, concatenating, and so on.

Page 30: Labview Notebook

Danny Vu Page 30 4/10/2023

The Analog Waveform>>Waveform Generation palette allows you to generate different types of single and multitone signals, function generator signals, and noise signals. For example, you can generate a sine wave, specifying the amplitude, frequency, and so on.

The Analog Waveform>>Waveform Measurements palette allows you to perform common time and frequency domain measurements such as DC, RMS, Tone Frequency/Amplitude/Phase, Harmonic Distortion, SINAD, and Averaged FFT measurements.

The Digital Waveform palette allows you to perform operations on digital waveforms and digital data, such as searching for digital patterns, compressing and uncompressing digital signals.

The Digital Waveform>>Digital Conversion palette allows you to convert to and from digital data

The functions in Waveform File I/O allow you to write waveform data to and read waveform data from files.

For displaying digital waveform data, use the Digital Waveform Graph (from Modern>>Graph). This graph is useful for showing true/false states changing over time.

When you have both analog and digital signals that you wish to display together in a way that shows the timing relationships between the two, use a mixed signal graph, which may be found on the Modern>>Graph palette of the Controls palette.

Page 31: Labview Notebook

Danny Vu Page 31 4/10/2023

Exporting Images of charts and graphs: right-click on your graph or chart and select Data Operations>>Export Simplified Image dialog and choose to save the image in one of several file formats.

Ex: Build a VI that continuously measures the temperature once per second and displays the temperature on a chart in scope mode. If the temperature goes above or below the preset limits, the VI turns on a front panel LED.

Page 32: Labview Notebook

Danny Vu Page 32 4/10/2023

VII>> STRINGS:

String Length: returns the number of characters in a given string.

Concatenate Strings: concatenates all input strings into a single output string

Format Into String: formats string, path, enumerated type, time stamp, Boolean, or numeric data as text.

Page 33: Labview Notebook

Danny Vu Page 33 4/10/2023

Parsing Functions: is a useful function to take strings apart or convert them into numbers, and these parsing functions can help you accomplish these tasks.

String Subset: accesses a particular section of a string. It returns the substring beginning at offset and containing length number of characters.

Scan From String: converts the string to the number. The function starts scanning the input string at initial search location and converts the data according to the format string.

Match Pattern and Regular Expressions:

Page 34: Labview Notebook

Danny Vu Page 34 4/10/2023

VIII>> FILE INPUT/OUTPUT:

All functions are located in the Programming>>File I/O subpalette of the Functions palette.

Write to Measurement File Read from Measurement File

Write to Text File

Read from Text File

Write to Binary File

Read from Binary File

To specify how a file will be formatted, selecting Properties from the pop-up menu.

Page 35: Labview Notebook

Danny Vu Page 35 4/10/2023

IX>> SIGNALS:

X>> Instrument Control:

Using GPIB Controller: - Transfer data in parallel, one byte (8 bits) at a time.

- Several instruments (up to 15) can be strung together on one bus.

- GPIB controller devices come in many different interface flavors: PCI, PC Card, Ethernet, USB, PXI, and so on.

Using RS-232 Controller:

Page 36: Labview Notebook

Danny Vu Page 36 4/10/2023

VISA Functions:

VISA is a standard I/O application programming interface (API) for instrumentation programming. Almost all instrument drivers for Labview use VISA functions in their block diagrams. VISA can control VXI, GPIB, PXI, or serial instruments.

Ex: if you had a serial device connected on port 1 (COM1) and you wanted to write a command specific to that device and read the 10 bytes that it returns, your block diagram might look like

XI>> Advanced Labview Functions:

Local Variables: provide a way to access front panel objects from several places in the block diagram of a VI in instances where you can’t or don’t want to connect a wire to the object’s terminal. You can set a local variable to either read or write mode by popping up on the local’s terminal.

Global Variables: allow you to access values of any data type (or several types at the same time if you wish) between several VIs in cases where you can’t wire the subVI nodes or where several VIs are running simultaneously.

Shared Variables: similar to global variables, but work across multiple local and networked applications.

Ex1: we want to end the execution of two independent While Loops with a single Boolean stop control.

Ex 2: build a simple data acquisition VI to read the analog input channel, but modify it to have a string indicator that tells the user: When the program is waiting for input When the program is acquiring data

Page 37: Labview Notebook

Danny Vu Page 37 4/10/2023

When the program has stopped. If the program had an error, indicate it.

XII>>ADVANCED FILE I/O ( Programming>>File I/O>>Advanced File Functions)

Page 38: Labview Notebook

Danny Vu Page 38 4/10/2023

Ex: Reading a text file

Page 39: Labview Notebook

Danny Vu Page 39 4/10/2023

Type Cast:

Page 40: Labview Notebook

Danny Vu Page 40 4/10/2023