How Can I Be Successful With Arrays In the LabVIEW DSP Module? Primary Software: LabVIEW Modules>>DSP ModulePrimary Software Version: 1.0 Primary Software Fixed Version: N/A Secondary Software: N/A
Problem: Why do uninitialized arrays break the build when I compile VIs for a LabVIEW DSP Module target? Solution: LabVIEW DSP Module targets do not support dynamic memory allocation so you must keep this in mind when programming a DSP target to handle array data. This article describes the difference between how a desktop computer and DSP target allocate memory, options for initializing arrays, and how to populate the array if you do not know the amount of array data you will be storing before execution begins. DSP targets handle memory allocation differently than operating systems such as Windows. When you write a VI to run on a desktop computer, you use the Build Array VI in a While Loop to append new data to old data. Each time the While Loop calls the Build Array VI, the processor in the desktop computer creates a new memory buffer, copies the old data and new data into the buffer, and then discards the data in the original buffer. This process is too slow for DSP processors, like the SPEEDY-33, that process data quickly. Because targets that the LabVIEW DSP Module supports do not have dynamic memory allocation capabilities, the DSP compiler must have a finite size for all arrays in your VI. This means that you must initialize all arrays to a specific size and that size cannot change during the execution of your VI. The easiest way to initialize an array is to create a control or constant, then click the increment/decrement button to select the number of elements for the array. Because LabVIEW uses 0-based indexing for arrays, you should set the number of elements to one less than the number of elements in the array. Then click in the control or constant and enter a value. This value is the initial value for all elements in the array. The following figure shows an initialized array.
For applications that run on a desktop computer, you can use the Build Array VI to combine several values into an array, or use the Build Array VI in a While Loop. For VIs that run on a DSP target, however, you must use the Replace Array Subset VI to copy data into your pre-allocated array. Populating Arrays When You Do Not Know the Number of Initialized Elements You can use index variables if you do not know how many initialized elements are in the array. For example, use the Replace Array Subset VI in a For Loop and increment an integer variable by one every time you replace new data into the array. This integer variable therefore tracks the number of elements of real data in the array. You can enable auto-indexing on the input tunnel of a loop when targeting a DSP. You also can enable indexing for output if you can specify the number of iterations of the loop before the execution of the program such as with a For Loop. You cannot use a While Loop because the number of times the loop iterates depends on conditions in the loop. The following figure illustrates successful and unsuccessful uses of loops with a DSP target. Working with Wave Signals and String Data Types Wave signals and string data types also use an array framework that might need special consideration in an application targeted to a DSP. When generating signals such as a sine wave or triangle wave, you must wire a constant to the samples parameter of the Sine Wave VI or Triangle Wave VI. You must treat the string data type as an array of unknown size because a string is an array of bytes with each byte representing one character. Since the DSP compiler does not know how long the string input is, you cannot use string controls or indicators with DSP targets. If you have a specific set of strings for input or output, you can use a ring or enumerated data type control or indicator to display words to the user. These are the differences between using arrays with DSP targets and desktop computer targets. These differences arise from the fact that companies create DSP chips to acquire, process, and output data as rapidly as possible. The techniques you learn from programming a fast DSP application are also good practice for keeping desktop computer applications speedy and trim. Related Links: Why Do I Receive an Error When I Expand a Shift Register In My DSP Program? Attachments:
Report Date: 05/27/2005 Last Updated: 11/07/2005 Document ID: 3LQCIVXL |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

