<< Chapter < Page Chapter >> Page >

The first step in using test vectors is to generate an appropriate input signal. One way to do this is to usethe MATLAB function sweep (available as sweep.m ) to generate a sinusoid that sweeps across a range of frequencies. The MATLAB function save_test_vector (available as save_test_vector.m can then save the sinusoidal sweep to a file you will later include in the DSP code.

Generate a sinusoidal sweep and save it to a DSP test-vector file using the following MATLAB commands:

>>t=sweep(0.1*pi,0.9*pi,0.25,500); % Generate a frequency sweep>>save_test_vector('testvect.asm',t); % Save the test vector

Next, use the MATLAB conv command to generate a simulated response by filtering the sweep with thefilter h you generated using gen_filt above. Note that this operation will yield a vector of length 507 (which is n m 1 , where n is the length of the filter and m is the length of the input). You should keep only the first 500 elements of the resulting vector.

>>out=conv(h,t) % Filter t with FIR filter h>>out=out(1:500) % Keep first 500 elements of out

Now, modify the file filter.asm to use the alternative "test vector" core file, vectcore.asm . Rather than accepting input from the A/D converters and sending outputto the D/A, this core file takes its input from, and saves its output to, memory on the DSP. The test vector isstored in a block of memory on the DSP evaluation board that will not interfere with your program code or data.

The test vector is stored in the .etext section. See Core File: Introduction to Six-Channel Board for TI EVM320C54 for more information on the DSP memory sections, including a memory map.
The memory block that holds the test vector is large enough tohold a vector up to 4,000 elements long. The test vector stores data for both channels of input and from all sixchannels of output.

To run your program with test vectors, you will need to modify filter.asm . The assembly source is simply a text file and can be edited using the editor of yourpreference, including WordPad, Emacs, and VI. Replace the first line of the file with two lines. Instead of:

.copy "core.asm"

use:

.copy "testvect.asm".copy "vectcore.asm"

Note that, as usual, the whitespace in front of the .copy directive is required.

These changes will copy in the test vector you created and use the alternative core file. After modifying your code,assemble it, then load and run the file using Code Composer as before. After a few seconds, halt the DSP(using the Halt command under the Debug menu) and verify that the DSP has halted at a branch statement that branches to itself. Inthe disassembly window, the following line should be highlighted: 0000:611F F073 B 611fh .

Next, save the test output file and load it back into MATLAB. This can be done by first saving 3,000 memoryelements (six channels times 500 samples) starting with location 0x8000 in program memory. Do this by choosing File->Data->Save... in Code Composer Studio, then entering the filename output.dat and pressing Enter . Next, enter 0x8000 in the Address field of the dialog box that pops up, 3000 in the Length field, and choose Program from the drop-down menu next to Page . Always make sure that you use the correct length (six times the length ofthe test vector) when you save your results.

Last, use the read_vector (available as read_vector.m ) function to read the saved result into MATLAB. Do this using the followingMATLAB command:

>>[ch1, ch2] = read_vector('output.dat');

Now, the MATLAB vector ch1 corresponds to the filtered version of the test signal you generated. TheMATLAB vector ch2 should be nearly identical to the test vector you generated, as it was passed fromthe DSP system's input to its output unchanged.

Because of quantization error introduced in saving the test vector for the 16-bit memory of the DSP,the vector ch2 will not be identical to the MATLAB generated test vector.

After loading the output of the filter into MATLAB, compare the expected output (calculated as out above) and the output of the filter (in ch1 from above). This can be done graphically by simply plotting the two curves on the same axes; forexample:

>>plot(out,'r'); % Plot the expected curve in red>>hold on % Plot the next plot on top of this one>>plot(ch1,'g'); % Plot the expected curve in green>>hold off

You should also ensure that the difference between the two outputs is near zero. This can be done by plotting thedifference between the two vectors:

>>plot(out-ch1); % Plot error signal

You will observe that the two sequences are not exactly the same; this is due to the fact that the DSP computesits response to 16 bits precision, while MATLAB uses 64-bit floating point numbers for its arithmetic.

Note that to compare two vectors in this way, the two vectors must be exactly the same length, which is ensuredafter using the MATLAB command out=out(1:500) above.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Dsp laboratory with ti tms320c54x. OpenStax CNX. Jan 22, 2004 Download for free at http://cnx.org/content/col10078/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Dsp laboratory with ti tms320c54x' conversation and receive update notifications?

Ask