<< Chapter < Page Chapter >> Page >

After you have made the changes to all eight coefficients, run your new filter and use the oscilloscope to measure thedelay between the raw (input) and filtered (delayed) waveforms.

Take advantage of the "Quick Measure" feature on the oscilloscope!

What happens to the output if you change either the scaling factor or the delay value? How many seconds long is asingle-sample delay? Six-sample delay?

Step 9: test-vector simulation

As a final exercise, you will find the output of the DSP for an input specified by a test vector. Then you will comparethat output with the output of a MATLAB simulation of the same filter processing the same input; if the DSPimplementation is correct, the two outputs should be almost identical. To do this, you will generate a waveform inMATLAB and save it as a test vector. You will then run your DSP filter using the test vector as input and import theresults back into MATLAB for comparison with a MATLAB simulation of the filter.

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

Generate a sinusoidal sweep using sweep.m 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 the filter 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

The main.c file needs to be told to take input from memory on the DSP. Fortunately, the changes have already been made in the files. The test vector is stored in a block of memory on the DSP just like other variables.The memory block that holds the test vector is large enough to hold a vector up to 4,000 elementslong. The test vector stores data for all four channels of input and from four channels of output.

To run your program with test vectors, you will need to modify main.c as well as filtercode.asm . Both are simply text files and can be edited using the editor of your preference, including WordPad, Emacs, and VI. (The changes have already been made, but please visually verify the changes are there.) Within main.c , uncomment the #define FILE_INPUT line so that your program will rewrite input from the A/D with the test vector you specified and then save the output into a block of memory.

In filtercode.asm , uncomment the .copy "testvect.asm" line. Make sure this Matlab generated file is in the same directory as filtercode.asm .

In TI assembly, the semi-colon ; signifies a comment.

These changes will copy in the test vector. After modifying your code, assemble it, then load and run the file using Code Composeras before. After a few seconds, halt the DSP (using the Suspend command under the Run menu). How many seconds do you think it should take?

Saving dsp memory to file

Next, we will save the test output file and load it back into MATLAB. We are interested in the first 500 output samples, starting at address tv_outbuf in Data memory. There are four output channels and the memory is interleaved in time. Therefore, we will have to collect 2000 (4 channels time 500 samples) memory elements.

  • Select View>Memory Browser
  • Click on the "Save" icon, a green square with an angled arrow (top left in the Memory panel)
  • Hit Browse and make sure you are in your U: workspace
  • Name the file output.dat and save filetype as TI data format
  • On the next screen, use the following options:
    • format: 16-Bit Hex - TI Style
    • start address: tv_outbuf
    • memory page: data
    • length: 2000

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,ch3,ch4] = 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 from the DSPsystem's input to its output unchanged.

Because of quantization error introduced in saving the test vector for the 16-bit memory of the DSP, thevector 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 thetwo curves on the same axes; for example:

  • 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(1:length(ch1))-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 computes itsresponse to 16 bits precision, while MATLAB uses 64-bit floating point numbers for its arithmetic. Blocks of output samples may also be missing from the test vector output due to a bug in the test vector core. Nonetheless, the test vector environment allows one to run repeatable experiments using the same known test input for debugging.

Step 10: closing down

Before exiting Code Composer, make sure to disconnect properly from the DSP:

  • Halt any program running on the DSP ( Run>Suspend )
  • Disconnect from the DSP ( Run>Connect will toggle between connecting and disconnecting)

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Ece 420 fall 2013. OpenStax CNX. Sep 26, 2013 Download for free at http://cnx.org/content/col11560/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Ece 420 fall 2013' conversation and receive update notifications?

Ask