<< Chapter < Page Chapter >> Page >

Now that you understand how your assembly routine is called from C, modify it to return the value of the filter output, instead of writing it to outBuffer directly in assembly. Modify main.c with the following:

  1. Replace the function declaration extern void filter(void) with extern int filter(void) .
  2. Create an output variable called outval to store the value returned from filter() .
  3. Store outval into output channels 1 and 3, and your unfiltered input sample from channel 1 into output channels 2 and 4.
Use typecasting, bitshifting, and bitwise operations to pack the output variables accordingly.

Now that the C code has been changed, you must modify the assembly code to actually return the value. To do this, there is an established convention for how to pass and return values between C and assembly. The rules for this convention are given in Section 6.4 of the TMS320C55x Optimizing C/C++ Compiler User's Guide .

Please read and understand this section in the manual before proceeding!

Currently, the filter output and raw input are copied to the output buffers:

MOV HI(AC0), *AR7+
MOV HI(AC1), *AR7+
MOV HI(AC0), *AR7+
MOV HI(AC1), *AR7+

Replace these commands with a single command to return only the filter output. Hint: you will need register T0 .

Now after compiling, loading, and running your code, your filter should behave just as in Part 1. In this second part of the lab, you have learned how to make a call to an assemblyroutine much more modular as you should know how to pass and return values between C and assembly. This will become valuable in later labs, when you may want to cascade multiple assembly subroutines together.

Part 3: alternative single-channel fir implementation

An alternative method of implementing symmetric FIR filters uses the firsadd instruction. First, make a copy of filtercode.asm , as you will have to demo this part separately from the previous two. Modify your code to implement the filter with a 4 kHz to 8 kHz passband using the firsadd .

Two differences in implementation between your code from Part 1 and the code you will write for this part are that firsadd requires the states to be broken up into two separate circular buffers. Refer tothe firsadd instruction on page 5-152 in the Mnemonic Instruction Set manual.


1 mov *AR1, *AR2- ; write x(-N/2) over x(-N) 2 mov HI(AC0), *AR1 ; write x(0) over x(-N/2)3 add *AR1-, *AR2-, AC0 ; add x(0) and x(-(N-1)) 4 ; (prepare for first multiply)5 rpt #(FIR_len1/2-1) 6 firsadd *AR1-, *AR2-, *CDP+, AC0, AC17 round AC1 8 amar ???????????????? ; Fill in these two instructions9 amar ????? ; They modify AR1 and AR2 1011 ; note that the result is now in the 12 ; AC1 accumulator

Because states and coefficients are now treated differently than in your previous FIR implementation, you will need tomodify the pointer initializations to

1 bset AR1LC ; sets circular addressing for AR1 2 bset AR2LC ; sets circular addressing for AR23 45 mov #firState1, AR1 6 mov #firState1Index, AR47 mov mmap(AR1), BSA01 8 mov *AR4, AR1 ; get pointer to oldest delayBuf in AR19 10 mov #firState2, AR211 mov #firState2Index, AR5 12 mov mmap(AR2), BSA2313 mov *AR5, AR2 1415 16 mov #(FIR_len1/2), BKC17 mov #(FIR_len1/2), BK03 ; initialize circular buffer length for register 0-3 18 mov #coef1, CDP ; CDP contains address of coefficients19 mov *AR6<<#16, AC0 ; copy input into AC0

There are also a couple other changes that need to be made before the code will compile successfully. Read the comments carefully and understand how the firsadd instruction works to make the necessary changes. Hint: Make sure accumulator usage (AC0, AC1, AC2) and what is sent to output is correct.

Using the techniques introduced in Lab 0: DSP Hardware Introduction , generate an appropriate test vector and find the expected output in MATLAB. In MATLAB, plot the expected and actual outputs of the filter, and the difference between the expected and actual outputs. Why is the output from the DSP system not exactly the same as the output from MATLAB?

Next, compare the output of this code against the output of the same filter implemented using the mac instruction. Are the results the same? Why or why not? Ensure that the filtered output is sent to output channel 1, and that the unmodified output is still sent to output channel 2.

You will lose credit if the unmodified output is not present or if the channels are reversed!

Quiz information

The points for Lab 1 are broken down as follows:

  • 1 point: Prelab (must be ready to show the TA the week before the quiz)
  • 3 points: Working code from Parts 2 and 3: you must demonstrate that your code works using input from the function generator and that it works using input from appropriate test vectors. Have an .asm file ready to demonstrate each.
  • 4 points: Quiz score.

The quiz may cover signal processing material relating to fixed point processing fundamentals, convolution, and the differences between ideal FIR filters and realizable FIR filters. You may also be asked questions about digital sampling theory, including, but not limited to, the Nyquist sampling theorem and the relationship between the analog frequency spectrum and the digital frequency spectrum of a continuous-time signal that has been sampled.

The quiz will cover the code that you have written during the lab. You are expected to understand, in detail, all of the code in the files you have worked on, even if your partner wrote it. The quiz may cover various key lines of code, 2's complement fractional arithmetic, circular buffers, alignment, typecasting and bit manipulation in C, function calling conventions between C and assembly, and the mechanics of either of the two FIR filter implementations.

Use the TI documentation, specifically the Mnemonic Instruction Set manual. Also, feel free to ask the TAs to help explain the code that you have been given.

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