EECS20: Introduction to Real-Time Digital Systems
Lab07: Tones: Table Lookup and Difference Equations
EECS20: Introduction to Real-Time Digital Systems
©1996 Regents of the University of California.
By K. H. Chiang, William T. Huang, Brian L. Evans.
URL: http://www-inst.eecs.berkeley.edu/~ee20
News: ucb.class.ee20
In this lab, we will study the implementation of difference equations on the DSP and the indirect addressing mode with circular buffer control. Both techniques will enable us to generate sinusoidal waveforms from the DSP.
For the implementation of difference equations, please review the lecture on FIR and IIR filters, and the Matlab help file on the function "filter".
For the indirect addressing mode, please browse through the following parts of the TMS320C5x User's Guide: 3.4.3 (pp. 3-16 - 3 - 20, on Auxiliary Registers), 4.1.6 (pp. 4-12 - 4-13, on Circular Addressing), and Table 4-5. Instruction Set Summary (pp.4-17 - 4-21)
For the writeup, please browse through Chapter 5 Assembler Directives of the TMS320C5x DSP Starter Kit User's Guide.
Difference equations can be used represent FIR and IIR
filters. For a FIR filter, we can write
y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)For a IIR filter, we can write
y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb) - a(2)*y(n-1) - ... - a(na+1)*y(n-na)We can also use difference equations to generate sequences of some waveforms. For example, the M-file
digitosc.m
generates a sinusoidal waveform by passing an impulse
through a IIR filter described by
y(n) = bs*x(n) + 2*ac*y(n-1) - y(n-2)where
bs = sin(2*pi/N) ac = cos(2*pi/N)The period of the sinusoidal waveform, then, is N samples. Convince yourself that this scheme works well for N sufficiently large.
Consider the implementation of the following difference equation on the C50.
y(n) = b(1)*x(n) + b(2)*x(n-1) + b(3)*x(n-2)
Let x(n) be the current input and x(n-1) and x(n-2) are previous inputs. We do not need earlier inputs to compute current output y(n), so we can keep on using the same three data memory addresses to store the inputs by shifting contents from address to the other.
Data Memory | n=3 | n=4 |
1000h | x(3) | x(4) |
1001h | x(2) | x(3) |
1002h | x(1) | x(2) |
In C50, such shifting can be achieved through the instruction
DMOV
(Data Move in Data Memory) which copies contents
of the specified data memory address into the contents of the next
higher address. Our code may look like this:
* Parentheses are used here for readability. * Do not use them for symbols in your codes. ZAP ; Zero Accumulator and Product Register LT b(3) MPY x(n-2) APAC LT b(2) DMOV x(n-1) MPY x(n-1) APAC LT b(1) DMOV x(n) MPY x(n) APAC
But, another C50 instruction, MACD
(Multiply and Accumulate
With Data Move), enables us to write a more efficient code:
ZAP MACD b(3),x(n-2) MACD b(2),x(n-1) MACD b(1),x(n) APAC
A MACD
instruction combines the tasks of APAC, LT,
DMOV,
and MPY
. This saves execution time and
program memory space. Now, can you implement a difference equation
that depends on past outputs also?
We had learned about immediate addressing mode and direct addressing mode in Lab 05. In this section, we are going to talk about indirect addressing mode and circular buffer control. Please read 3.4.3 Auxiliary Registers (pp. 3-16 - 3-20) in the TMS320C5x User's Guide.
Indirect addressing is an efficient way for the DSP to read through a sequence of information like {b(1), b(2), b(3)} or {x(n), x(n-1), x(n-2)} mentioned above. The relevent instructions are:
Circular buffer controls provides efficient means for the DSP to read through a circular sequence of information. The relevent registers are:
Bit | Name | Function |
0-2 | CAR1 | Identities which auxiliary register is mapped to circular buffer 1. |
3 | CENB1 | Circular buffer 1 enable=1/disable=0. Set to 0 upon reset. |
4-6 | CAR2 | Identities which auxiliary register is mapped to circular buffer 2. |
7 | CENB2 | Circular buffer 2 enable=1/disable=0. Set to 0 upon reset. |
Some instructions that streamline the register setting process:
In this example, we modify the main loop
of the sawtooth.asm
, so the
sample values are stored to a small circular buffer rather than the
data transmit register (DXR).
Please run the code on the DSK Debugger and single step through the code. Pay attention to the interaction between the content of register AR0 and the modification of data memory. If your Data Memory Window does not display contents of address between 1000h and 1006h, try press D(isplay)/M(emory)/A(ddr) and enter "1000".
NEG
.In your writeup, please explain your design, e.g. please state the reasons why you choose certain amount for shift in storing certain value. Do your best.
ACC Accumulator register that stores intermediate results ADD Add to ACC, a C50 instruction AIC Analog Interface Circuit that allows analog devices to be connected to the C50 DSK board ALU Arithmetic Logic Unit that adds, shifts, and performs logical operations. APAC Add PREG to ACC, a C50 instruction AR Auxiliary register that stores indirect pointer to addresses ARn Auxiliary register number n(0-7) ARP Auxiliary register pointer that points to currently used AR C50 Texas Instruments TMS 320C50 DSP processor (16-bit, 28.6/20 MIPS) CBCR Circular buffer control register that selects ARn and enable/disable the buffers n(1,2) CBERn Circular buffer end register that stores the last address in the circular buffer n(1,2) CBSRn Circular buffer start register that stores the first address in the circular buffer DP Data memory page pointer that points to the current 128-byte page of data memory DSK DSP Starter Kit, a C50 development package DSP Digital Signal Processor, a special-purpose microprocessor DXR Data transmit register that stores samples to be transmitted to AIC I/O Input/output LAR Load ARn, a C50 instruction MACD Multiply and Accumulate with Data Move, a C50 instruction MAR Modify ARn and ARP, a C50 instruction NEG Negate ACC, a C50 instruction PLU Parallel logic unit that performs logical operations in parallel to ALU PREG Product register that stores multiplication results RCA A connector standard SACH Shift Accumulator and Store High Word Result, a C50 instruction SACL Shift Accumulator and Store Low Word Result, a C50 instruction SAMM Store ACC to memory-mapped register, a C50 instruction SPLK Store long immediate to data memory location, a C50 instruction ZAC Zero ACC, a C50 instruction ZAP Zero ACC and PREG, a C50 instruction