Configure selected applications quickly with Express VIs and LabVIEW.
Anyone familiar with National Instruments (NI) LabVIEW knows it is a graphical software language used to develop a wide variety of test and measurement applications. In fact, most of the topics regularly covered by EE-Evaluation Engineering are areas that LabVIEW addresses, including data acquisition, environmental test, and wireless.
Last year, a major upgrade to the program was released as version 7.0 LabVIEW Express. This article provides a detailed discussion of some of the aspects of the software as well as the user-friendly Express virtual instruments (VIs).
Second-generation LabVIEW versions increased functionality and the range of applications by providing such features as real-time operation and factory-automation initiatives. However, version 7.0, the first third-generation release, changes how the user interacts with the language.
A good example of this is the extensive use of polymorphic VIs. For instance, with the DAQ Assistant VI, one of several Express VIs, you only have to learn how to accomplish one function such as analog read. The other choices, analog write, digital I/O, and counter-based operations, present you with very similar interfaces.
Another example, the Simulate Signal express VI, is a versatile function generator controlled from a single configuration panel. You can select the waveform type, frequency, phase, amplitude, offset, and, for square waves, the duty cycle. You also control the sampling rate and whether the simulation runs as fast as possible or more realistically as it would when part of a larger application.
That�s probably enough detail for most people, but not everybody. How about adding noise to the signal? What about controlling how the simulation is reset so that the waveform starts over from zero or in a phase-continuous manner?
These kinds of considerations are part of the control panel because of another architectural change. No longer are there several similar VIs with easy, intermediate, and advanced levels of difficulty. All the sub-VIs making up a higher level VI are arranged in a wide, flat structure so there is one comprehensive panel from which you choose the features you require.
Of course, to make such large changes to the way the language appears to a user implies major philosophical changes. A good place to start is with virtual channels. A virtual channel is a collection of settings that can include a name, a physical channel, input terminal connections, the type of measurement or generation, and scaling information. In contrast, a physical channel is a terminal or pin at which you can measure or generate an analog or digital signal.
In traditional NI-DAQ, the user-hardware configuration utility available in earlier versions of LabVIEW, configuring virtual channels was an option to record which physical channels were being used for different measurements. In the new NI-DAQ measurement services (NI-DAQmx), virtual channels are integral to every measurement.
A task, an important new concept for NI-DAQmx, is a collection of one or more virtual channels with timing, triggering, and other properties. Conceptually, a task represents a measurement or generation you want to perform. You can set up and save all of the configuration information in a task and use the task in an application.
Trying It Out
As interesting as a computer science major might find LabVIEW 7.0 under the hood, hands-on experience was the best way to decide if the promised benefits actually were delivered. NI generously provided a system for our evaluation. It comprised a laptop computer with LabVIEW 7.0, a separate hardware chassis of the type used for demonstrations at seminars and trade shows, a thermocouple, and connecting cables.
The initial intention was to talk me through a few examples via a conference call. But, once I began working with LabVIEW, I realized that there was a great deal to learn before I would even know what questions to ask. Being presented with hundreds of strange icons on a series of seemingly unrelated palettes was initially overwhelming.
I was experiencing the large learning �hump� that must be overcome with a software language before you can accomplish anything meaningful. It�s painful, but the only way I found to gain a basic understanding was to stick with it, uninterruptedly, for a few hours at a time. Eventually, a few things become clear, but proficiency is not an option for the casual user.
I worked through the canned examples with few problems. They were an obvious place to start. But equally obvious, the examples only did what they were designed to do. When I tried to extend them, by adding a numerical indicator instead of the graph that had been provided, frustration prevailed. And then I remembered to look at the examples.
Often, the most useful LabVIEW documentation is the large number of example VIs included with the program or downloadable from the NI website. In this case, I had not realized that the term DATA in an Express VI meant dynamic data, an abstract data type that comprised more than a simple value. After I connected a translation VI between the Express VI DATA pin and the numeric indicator input pin, I could read the value of a thermocouple�s temperature as well as see trends on the graph.
Much like Visual Basic (VB), LabVIEW presents both a front panel and a separate panel where the underlying code appears. In the case of LabVIEW, the code is in the form of VIs that you wire together to form a block diagram.
From the front panel, you can display the control and tool palettes. From the block diagram, the tool palette and the functions palette are accessible. The division of palettes in itself was confusing until I thoroughly learned that controls were both controls and indicators like meters and knobs that could be used on the front panel. Functions generate, analyze, or in some other way manipulate signals and take the form of VIs�actually icons�that belong on the block diagram.
More confusion was caused by having Express VIs and conventional sub-VIs simultaneously present. There is no large switch to throw to select Express VIs and NI-DAQmxNI-DAQ and the measurement and automation explorer (MAX) of the same vintage. Instead, all the functionality is available, and you use what you need. This approach supports legacy second-generation programs and does not restrict the applicability of the limited number of Express VIs. You always can extend them to apply to your application by combining with conventional sub-VIs. or choose traditional
I decided that it was best for me to use the new Express VIs as much as possible to take advantage of their comprehensiveness. So, I explored several of them via examples. This decision avoided having to deal with the hundreds of sub-VIs unless one was important to me.
Analog Analog In Measure Acceleration Measure Current Measure Frequency Measure Linear position Measure Rotary position Measure Slow varying signal Measure Strain Measure Temperature Measure Voltage Analog Out Generate Voltage Generate CurrentCounter
Count Digital Events
Generate Pulse
Measure 2-Edge Separation
Measure Digital Frequency
Measure Period or Pulse Width
Measure Position
Digital
Generate Values
Read Values
Switches
Connect Multiple Channels
Connect Two Channels
Switch Scanning SW-Trigger
Table 1. DAQ Assistant Supported Actions
Analog input and output and digital I/O were simple concepts, and as shown in Table 1, each of these actions is further subdivided into specific activities directly supported by the DAQ Assistant express VI. But what about counting? I wanted to count transitions from the Simulate Signal express VI, although an easy way to do this without a hardware counter wasn�t apparent.
An Example
I spent some time searching through descriptions of VIs related to counting. Eventually, I realized that they actually weren�t counters at all but subroutines needed when working with a real hardware counter. For example, one sub-VI controlled one or more counters, another started a counter, and another stopped a counter. But none of them was in itself a counter.
Instead of continuing to search for a counter VI, I looked for an example VI with count in its description. The one I found, Trigger Counter.vi, counts the number of times a noisy waveform crosses a threshold. It placed the Simulate Signal express VI within a While loop to continuously generate a sine wave with noise added to it. Signal generation was followed by a nested While loop that contained the Trigger and Gate express VI and the Statistics express VIFigure 1). (
Figure 1. Trigger Counter.vi Block Diagram
Actually, the output of the Simulate Signal VI is an array of sampled values as large as the Number of SamplesSimulate Signal VI configuration panel. The filled array will be analyzed by the VIs within the inner loop. So, even though the Simulate Signal VI was set to generate a phase-continuous sine wave, the output is produced and analyzed in batches, not continuously. entered on the
Because of the noisy nature of the waveform, the width of any portion that crosses the threshold isn�t well defined. It could be one, two, five, or 10 or more samples wide. The purpose of the Trigger and Gate VI, as it was configured, is to differentiate the edge of the signal, producing a single output pulse for each threshold crossing.
The Triggered Signals output from this VI contains the waveform segments between the start trigger and stop trigger events: in this case, one sample for each trigger within the array output from the Simulate Signal VI. However, the actual Triggered Signals output is not a pulse but rather an array of the values of the samples that caused triggers.
Because the generated signal is a noisy sine wave, there may be many trigger events within each array of new data from the Simulate Signal VI. The values of these events are the entries in the Triggered Signals output array.
Obviously, a simple counter can�t directly count the Triggered Signals output. Instead, summation is performed in the following Statistics VI. The Total Samples output of this VI returns the total number of samples in the Triggered Signals array, regardless of amplitude.
A Translate from Dynamic Data VI follows next, which changes the data type from dynamic data to a one-dimensional array. This is the type of input expected by the Index Array VI, which outputs the scalar value of only the first array element. Counting, the part of the example in which I was interested, is accomplished by combining an adder with a shift register in its feedback loop. In effect, each time a value is output from the Index Array VI, it is added to the adder�s output.
A Simplified Example
I didn�t know if the Trigger Counter.vi example was designed with a more complicated goal in mind or if its complexity really was required. Because I didn�t know in detail how it worked, I started from scratch to develop a new TOMs COUNTER.vi to see the effect of simplifying the structure.
As shown in Figure 2, I used the same idea of signal generation and differentiation, but within only one While loop. I had noticed during my earlier VI exploration that the Translate from Dynamic Data VI can have a scalar output, so rather than work with the array nature of the Trigger and Gate VI output, I immediately translated the single sample output to a single scalar value. The counter is the same fedback adder type used in the canned example.
Figure 2. TOMs COUNTER.vi Block Diagram
Did it work? Yes, if the amplitude of the pulse was 1.0, and if only one pulse was output at a time. Without the inner loop, the Trigger and Gate VI only outputs one sample no matter how many threshold crossings are within the Simulate Signal VI output array. Also, without the Statistics VI to do the summation, the fedback adder counter is adding sample amplitudes, not the quantity of samples.
The use of the Index Array VI doesn�t appear to be necessary, but it is a very general solution. For example, if elements of a two-dimensional array were to be counted, then the Index Array VI would be the way to go. In the case of the Trigger Counter.vi, where the Statistics VI outputs a one-dimensional array, the desired element can be obtained by configuring the Translate from Dynamic Data VI to return a single scalar�the number of threshold crossings found by the inner While loop. I�ve tried it as an alternative, and the overall Trigger Counter.vi appeared to work as it did with the Index Array VI.
Summary
As I continued to dig into the details of the canned Trigger Count.vi, it became more apparent that during this evaluation I had reached only a small flat spot along a rather steep learning curve. I just didn�t have the detailed knowledge about the VIs and the behavior of their signal inputs and outputs to go far beyond the functionality of an Express VI. The detailed analysis of the Trigger Counter.vi operation was provided by NI in response to my request for help.
I understand how to develop a VI and how to use several of the Express VIs. It�s also clear that a tremendous amount of detail is hidden beneath the user-friendly Express VI control panels. Depending on what it is you wish to accomplish, you may run into some of that detail, as I did, which may require much deeper understanding before you can proceed.
I assume seasoned LabVIEW users will not have these problems, because they already have coped with the language�s underlying details. Express VI�s make their work much easier because most of the commonly occurring requirements are dealt with very concisely. Also, because they do understand the details, extending the functionality of an Express VI by adding a few standard sub-VIs is a simple job. I don�t think this will be the case for most first-time users.
However, Express VIs and the associated NI-DAQmx developments are certainly attractive features of LabVIEW 7.0. New users no doubt will find the language useful for their applications. My advice is to attend hands-on seminars and devote as much time as possible to mastering the language�s nuances. It�s a very powerful and fast method of writing test routines, but successfully venturing beyond the Express VIs will require time and determination.
Acknowledgements
Thanks to NI�s Malcolm Borgendale, product manager for measurement software, and Jon Pafk, media relations coordinator, for their help with this article.
FOR MORE INFORMATION
on Express VIs
enter this URL
www.rsleads.com/405ee-235
on NI-DAQmx features
enter this URL
www.rsleads.com/405ee-236
Return to EE Home Page
Published by EE-Evaluation Engineering
All contents � 2004 Nelson Publishing Inc.
No reprint, distribution, or reuse in any medium is permitted
without the express written consent of the publisher.
May 2004