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
Assigned: 19 Mar 97, Checkoff: 2 Apr 97, Writeup Due: 4 Apr 97

Introduction

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.

Implementing Difference Equations

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.

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?

Addressing Modes

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 Mode

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:

LAR = Load Auxiliary Register:
The contents of the specified data memory address or an 8-bit or 16-bit constant are loaded into the designated auxiliary register(AR).

MAR = Modify Auxiliary Register:
The AR and the Auxiliary Register Pointer (ARP) are modified.

Circular Buffer Control

Circular buffer controls provides efficient means for the DSP to read through a circular sequence of information. The relevent registers are:

CBCR = Circular Buffer Control Register
BitNameFunction
0-2CAR1Identities which auxiliary register is mapped to circular buffer 1.
3CENB1Circular buffer 1 enable=1/disable=0. Set to 0 upon reset.
4-6CAR2Identities which auxiliary register is mapped to circular buffer 2.
7CENB2Circular buffer 2 enable=1/disable=0. Set to 0 upon reset.

CBSR1/2 = Circular Buffer Start Address 1/2

CBER1/2 = Circular Buffer End Address 1/2

Some instructions that streamline the register setting process:

SPLK = Store Parallel Long Immediate
The SPLK instruction allows a full 16-bit pattern to be written into any memory location. The parallel logic unit (PLU) supports this bit manipulation independently of the ALU so that the ACC is unaffected.

SAMM = Store Accumulator in Memory-Mapped Register
The low word of the accumulator is copied to the addressed memory-mapped register. The upper 9 bits of the data address are set to zero, regardless of the current value of DP or the upper 9bits of AR(ARP).

Example

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".

Writeup

  1. Generate a 700 Hz sinusoidal waveform on the DSK. Use the difference equation method. Watch out for the overflow! Complete this incomplete program and output the tone to an earphone or an oscilloscope. You might want to read about the instruction 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.

  2. Repeat the previous problem. This time, use the circular buffer to store a set of the pre-calculated sample values.


Glossary

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


Tze-yau William Ng Huang
Sun Feb 20 00:00:00 PST 1996