Danny Vu



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 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.

• • •

Danny Vu I>> Creating SubVI:

Page 2


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.

Danny Vu 

Page 3 An indicator inside a loop (updated each iteration)


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

Danny Vu 3. Shift Registers: 

Page 4


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: the two loops in the left column show what happens when you run a program that contains an initialized shift register twice. .  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. The right column shows what happens if you run a program containing an uninitialized shift register two times.Danny Vu  Page 5 9/17/2011 You can have many different shift registers storing many different variables on the same loop.

separated by commas. the structure has two cases: FALSE and TRUE. .Danny Vu Page 6 9/17/2011 4. the structure can have from one to almost unlimited cases. 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. If If a numeric or string data type is wired to the selector. You can separate more than one value for a case.

followed by frame 1. The shift register is initialized to the first case.Danny Vu Page 7 9/17/2011 Use this state machine to execute the codes when it needs to run in the order. then frame 2. Only the last frame completes does data leave the structure. until the last frame executes. A second way to implement the sequence-style state machine is to use a shift register to control the case structure. This type of state machine will simply go to the next state in the sequence. There are two Sequence Structure: the Flat Sequence Structure and the Stacked Sequence Structure. . 5. The Sequence Structure Flat or Stacked: A Sequence Structure executes frame 0. shown below. and inside each case the number wired the shift register is incremented by one.

Time Delay: works like wait(ms) except that you specify the time in seconds. Tick Count (ms) : returns the value of your operating system’s internal clock in ms. Design Inputs: Number to Match (control). otherwise.   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. either type of Sequence Structure (Flat or Stacked) executes code exactly in the same manner. and allow enough idle processor time so that loops in your VI don’t race too fast and hog the CPU.    Ex: Build a VI that computes the time it takes to match an input number with a randomly generated number. You can easily convert one into the other by selecting from its pop-up menu. it returns a FALSE. synchronize tasks. it is commonly used to calculate elapsed time. Timing: It’s “time” for another digression. Random Number . Elapsed Time: The Boolean output will return a TRUE if the specified amount of time has elapsed. 6.Danny Vu Page 8 9/17/2011 Regardless of appearance. Timing functions are very important in Labview and help you measure time.

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. 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. 7. . you can directly enter a formula or formulas.Danny Vu Page 9 9/17/2011 Design Outputs: Time to Match (indicator). in lieu of creating complex block diagram subsections. Current Number (indicator). The Formula Node: With the Formula Node.

used to execute work when the user presses a button. The While Loop + Case Structure Combination  We add a Case Structure inside a While Loop. . It’s found in Programming>>Numeric palette 9.  The example shown below uses the formula node to evaluate the equation y=sin(x) and graph the results.Danny Vu  Page 10 9/17/2011 The following example computes the square root of x if x is positive. The Expression Node: The Expression Node is basically just a simplified Formula Node having just one unnamed input and one unnamed output. 8. and assigns the result to y. If x is negative. the code assigns value of 99 to y.

Build Array converts two Booleans into a 1D array of Booleans . III >> ARRAYS: . .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.Danny Vu Page 11 9/17/2011  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.

Array is a collection of data elements that are all the same type. the loop will index off one element from the array each time it iterates. Notice the wire becomes thicker as it changes to an array wire type. An array can have one or more dimensions.  If indexing is enabled as in loop (A).  When you enable auto-indexing on an array entering a For Loop. If indexing is disabled as in loop (B). thus eliminating the need to wire .Danny Vu Page 12 9/17/2011 Scalar type is simply a data type that contains a single value. LabView automatically sets the count to the array size. the entire array passes into the loop at once. each iteration creates the next array element.  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. or “non-array”. and up to 2^31 – 1 elements per dimension (memory permitting. of course).

LabView sets the count to the smallest of the choices if two arrays are enabled at the auto-indexing. Ex: the example shown below is to create a 1D array using a While Loop.  Ex: Creating two dimensional arrays: the For Loop executes a set number of times. You must hit the STOP button to halt the While Loop or it will stop after 101 times.Danny Vu Page 13 9/17/2011 a value to the count terminal. Need to enable indexing to get the array data out of the While Loop. .

 Index Array: use to access a particular element of an array .  Array Size: returns the number of elements in the concatenated array.Danny Vu Page 14 9/17/2011 FUNCTIONS FOR MANIPULATING ARRAYS  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 Subset: returns 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.Danny Vu  Page 15 Example to extract a column and row from a 2D array 9/17/2011  Delete From Array: delete a portion of an array starting at index and containing length elements.

the resulting array will be the smaller of the two. Notes: If you are doing arithmetic on two arrays with different number of elements.Danny Vu Page 16 9/17/2011 Polymorphism: Polymorphism is just a big word for a simple principle: the inputs to these functions can be of different size and representation. An example of a VI that demonstrate the Polymorphism of an array .

The results demonstrate several applications. and XOR are Boolean arithmetic operations. Compound Arithmetic Function:   AND. For example. Array 1 and Array 2 could be incoming waveforms that you wish to scale.Danny Vu Page 17 9/17/2011 The graph will plot each array element against its index for all 4 arrays at once. 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) . OR.

Creating Cluster Controls and Indicators: . Clusters must have the same number of elements and each element must match in both data type and order. depending on the function you choose.Danny Vu Page 18 9/17/2011 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.

. Boolean.)  Bundle Function: assembles individual components into a new cluster or allows you to replace elements in an existing cluster. You can not combine both controls and indicators inside the same cluster. meaning first in first out. The output components are arranged from top to bottom in the same order they have in the cluster..e. 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. etc. Cluster can group data of different type (i. numeric.  Unbundling Clusters: The Unbundle Function splits a cluster into each of its individual components.Danny Vu Page 19 9/17/2011 Like Arrays. all Objects inside a cluster must be all controls or all indicators.

if it’s less than zero. the VI will take the absolute value of all controls and multiply by 0. the VI multiplies all values by 0. Interchangeable Arrays and Clusters: .5 and displays the results in Output Cluster. If it’s ≥ 0.5 of the entire cluster.Danny Vu Page 20 9/17/2011  Bundle By Name Function: The below example checks whether the value of the numeric 1 digital control is ≥ 0.

Danny Vu Page 21 9/17/2011  Error Clusters and Error Handling Functions: .

. 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. charts retain and display previously acquired data. by passing it an array of values.Danny Vu Page 22 9/17/2011 V>> VISUAL DISPLAYS: CHARTS and GRAPHS: • Waveform Charts: Most often used inside loops.

.Danny Vu • Page 23 9/17/2011 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.

Danny Vu • Waveform Graphs: Page 24 9/17/2011 Unlike charts. graphs plot pre-generated arrays of data all at once. Notice that this 2D array has two rows with 100 columns (2x100) . which plot continuously acquired 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. They do not have the ability to append new values to previously generated data.

.Danny Vu Page 25 9/17/2011 • These waveform graphs below show how to plot the graph with system time.

.Danny Vu Page 26 9/17/2011 • XY GRAPHS: XY graph used to plot a math function that has multiple Y values for every X value.

” 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. .Danny Vu Page 27 9/17/2011 • You can also create a single plot from an array of XY cluster “coordinate pairs.

Thermometer.Danny Vu Page 28 9/17/2011 Note: to convert from radian to degree: 180/π x Radian =Degree Ex: build a VI that measures temperature approximately every .vi . After the acquisition is complete. and average temperatures. During the acquisition. the VI displays the measurements in real time on a waveform chart. maximum. the VI plots the data on a graph and calculates the minimum.vi Demo TemperatureRead.25sec for 10 secs.

You specify components by rightclicking and selecting Add Element and creating an indicator. 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. subtracting. Waveforms. .Danny Vu Page 29 9/17/2011 VI>> Time Stamps. • Analog waveform palette are used to perform arithmetic and comparison functions on waveforms. such as adding. finding the max and min points. multiplying. concatenating. and so on.

frequency. and noise signals. The Digital Waveform palette allows you to perform operations on digital waveforms and digital data. This graph is useful for showing true/false states changing over time. Tone Frequency/Amplitude/Phase. and so on. For example. SINAD.Danny Vu Page 30 9/17/2011 • • • • • • • The Analog Waveform>>Waveform Generation palette allows you to generate different types of single and multitone 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. use a mixed signal graph. compressing and uncompressing digital signals. such as searching for digital patterns. 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. The Analog Waveform>>Waveform Measurements palette allows you to perform common time and frequency domain measurements such as DC. RMS. which may be found on the Modern>>Graph palette of the Controls palette. . use the Digital Waveform Graph (from Modern>>Graph). you can generate a sine wave. For displaying digital waveform data. Harmonic Distortion. function generator signals. and Averaged FFT measurements. specifying the amplitude.

If the temperature goes above or below the preset limits. the VI turns on a front panel LED. .Danny Vu Page 31 9/17/2011 • 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.

• Concatenate Strings: concatenates all input strings into a single output string • Format Into String: formats string. Boolean. . time stamp.Danny Vu Page 32 9/17/2011 VII>> STRINGS: • String Length: returns the number of characters in a given string. path. or numeric data as text. enumerated type.

• String Subset: accesses a particular section of a string. and these parsing functions can help you accomplish these tasks. It returns the substring beginning at offset and containing length number of characters.Danny Vu Page 33 9/17/2011 Parsing Functions: is a useful function to take strings apart or convert them into numbers. Match Pattern and Regular Expressions: . • 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.

Danny Vu Page 34 9/17/2011 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.

Ethernet. VISA can control VXI. one byte (8 bits) at a time. .Transfer data in parallel. USB.Danny Vu IX>> SIGNALS: Page 35 9/17/2011 X>> Instrument Control: • Using GPIB Controller: .Several instruments (up to 15) can be strung together on one bus. Almost all instrument drivers for Labview use VISA functions in their block diagrams. GPIB.GPIB controller devices come in many different interface flavors: PCI. and so on. . PC Card. or serial instruments. PXI. Ex: if you had a serial device connected on port 1 (COM1) and you wanted to write a . Using RS-232 Controller: • • VISA Functions: VISA is a standard I/O application programming interface (API) for instrumentation programming. PXI.

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 When the program has stopped. Ex1: we want to end the execution of two independent While Loops with a single Boolean stop control. If the program had an error.Danny Vu Page 36 9/17/2011 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. XII>>ADVANCED FILE I/O(Programming>>File I/O>>Advanced File Functions) . Shared Variables: similar to global variables. 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. • • Ex 2: build a simple data acquisition VI to read the analog input channel. but work across multiple local and networked applications. indicate it. You can set a local variable to either read or write mode by popping up on the local’s terminal.

Danny Vu Page 37 9/17/2011 .

Danny Vu Page 38 9/17/2011 Ex: Reading a text file .

Danny Vu Type Cast: Page 39 9/17/2011 .

Danny Vu Page 40 9/17/2011 .