texas instruments tms 32c5x dsp - auburn universitynelsovp/courses... · operand addressing direct:...
TRANSCRIPT
Texas Instruments TMS 32C5x DSP
TMS320C5x User Manual
Instruction Fetch/Decode Section
TMS320C5x User Manual
ACC
T
P
Address Registers
RAM
TMS320C5x Data Processing Section
Key DSP Instructions MAC pma,dma – multiply/accumulate
ACC + P -> ACCpma x dma -> P(repeatable with pma+1)
MACD pma,dma -multiply/accumulate/delayACC + P -> ACCpma x dma -> Pdma -> dma+1 (move data for delay)(repeatable with pma+1)
ACC = AccumulatorP = Product Registerpma = prog. mem’y addressdma = data mem’y address
Other key operations Operand addressing Direct: ADD pma/dma Immediate: ADD #100 Indirect: ADD * Address in auxiliary register: AR0-AR7 ARP (Auxiliary Register Pointer) selects one of AR0-AR7 *+ increments address after fetch/ *- decrements address after fetch
T register: temporary multiplicand for 16x16 multiplier MPY instruction provides the multiplier LT dma/ind : mem -> TREG0 LTA dma/ind : load T, ACC=ACC+P LTD dma/ind : load T, ACC=ACC+P,move data LTP dma/ind : load T, P->ACC
Low-Pass Filter
IN Xn,PA0 ;read x(n)
ZAP ;A=P=0
MAC B,Yn
MAC C,Xn ;C=1-B
APAC ;A=A+P
SACH Yn ;save LSB
OUT Yn,PA1 ;out y(n)
)()1()1()()()1()()(
1)1()1(
)()()(
1
1
nxbnbynyzXbzYbzzY
bzb
bzzb
zXzYzH
−+−=−+=
−−
=−−
==
−
−
z-1 = “time delay”
Finite Impulse Response (FIR) Filter
LARP AR3 ;AR3 active pointerLAR AR3,#X0 ;point to X(n)ZAP ;A=P=0MAC C0,*- ;c0*x(n)MAC C1,*- ;+c1*x(n-1)MAC C2,*- ;+c2*x(n-2)APAC ;final A=A+PSACH Y ;save LSB
)2()1()()()()()(
210
21
102
−+−+=
++== −−
nxcnxcnxcny
zczcczXzYzH
Prog. Mem Data Mem.C0 X(n)C1 X(n-1)C2 X(n-2)
PID Controller
IN E0,PA0 ;new error e(n)LARP AR3 ;AR3 active pointerLAR AR3,#X0 ;point to e(n-2)ZAP ;A=P=0MAC c2,*- ;c2*e(n-2)MACD c1,*- ;+c1*e(n-1), move eMACD c0,* ;+c0*e(n), move eAPAC ;final A=A+PSACH An ;save LSBOUT An,PA1
)2()1()()1()( 210 −+−++−= necnecnecnana
Prog. Mem Data Mem.C0 e(n)C1 e(n-1)C2 e(n-2)
a(n)=control actione(n) = nth errorc0,c1,c2 constants
Basic sum of products
LARP AR3 ;AR3 active pointer
LAR AR3,#X0 ;point to X0
ZAP ;A=P=0
RPT #N ;repeat next instr. N times
MAC C0,*+ ;sum of products
APAC ;final A=A+P
SACH Y ;save LSB
∑=
=N
kk kxcY
0)(
Prog. Mem Data Mem.C0 X(0)C1 X(1)C2 X(2)….CN X(N)
Both pma and dma autoincrement for each MAC
Constants
Basic sum of products (correlation)
CNFP ;Config B0 as prog memoryLARP AR3 ;AR3 active pointerLAR AR3,#Y ;point to y(0)ZAP ;A=P=0RPT #N MAC X0,*+ ;sum of productsAPAC ;final A=A+PSACH Y ;save LSBCNFD ;B0 back to data memory
∑=
=N
kkykxY
0)()(
B0 RAM B1 RAMx(0) y(0)x(1) y(1)….x(N) y(N)
Temporarily program memory
FIR filter
Computers as Components 4e © 2016 Marilyn Wolf
(Programming Example 5.3)
int fir(int xnew) { /* given a new sample value, update the queue and compute the filter output */ int i; int result; /* holds the filter output */ circ_update(xnew); /* put the new value in */ for (i=0, result=0; i<CMAX; i++)
result += b[i] * circ_get(i); return result;}
Signal processing and circular buffer
Commonly used in signal processing: new data constantly arrives; each datum has a limited lifetime.
Use a circular buffer to hold the data stream.
d1 d2 d3 d4 d5 d6 d7
time t time t+1
Computers as Components 4e © 2016 Marilyn Wolf
Circular buffer
x1 x2 x3 x4 x5 x6
t1 t2 t3Data stream
x1 x2 x3 x4
Circular buffer
x5 x6 x7
Computers as Components 4e © 2016 Marilyn Wolf
Circular buffers
Indexes locate currently used data, current input data:
d1
d2
d3
d4
time t1
use
input d5
d2
d3
d4
time t1+1
useinput
Computers as Components 4e © 2016 Marilyn Wolf
Circular buffer in C#define CMAX 6 /* filter order */ int circ[CMAX]; /* circular buffer */ int pos; /* position of current sample */
void circ_update(int xnew) { /* compute the new head value with wraparound; the pos pointer moves from 0 to CMAX-1 */ pos = ((pos == CMAX-1) ? 0 : (pos+1)); /* insert the new value at the new head */ circ[pos] = xnew; }
void circ_init() { int i; for (i=0; i<CMAX; i++) /* set values to 0 */ circ[i] = 0; pos=CMAX-1; /* start at tail so first element will be at 0 */ }
int circ_get(int i) { int ii; /* compute the buffer position */ ii = (pos - i) % CMAX; return circ[ii]; /* return the value */ }
Computers as Components 4e © 2016 Marilyn Wolf
IIR direct form type II filter
Computers as Components 4e © 2016 Marilyn Wolf
int iir2(int xnew) { int i, aside, bside, result; for (i=0, aside=0; i<ZMAX; i++)
aside += -a[i+1] * circ_get(i); for (i=0, bside=0; i<ZMAX; i++)
bside += b[i+1] * circ_get(i); result = b[0] * (xnew + aside) + bside; circ_update(xnew); /* put the new value in */ return result; }
(Programming Example 5.4)
Other key operations Operand addressing Direct: ADD pma/dma Immediate: ADD #100 Indirect: ADD * Address in auxiliary register: AR0-AR7 ARP (Auxiliary Register Pointer) selects one of AR0-AR7 *+ increments address after fetch/ *- decrements address after fetch
T register: temporary multiplicand for 16x16 multiplier MPY instruction provides the multiplier LT dma/ind : mem -> TREG0 LTA dma/ind : load T, ACC=ACC+P LTD dma/ind : load T, ACC=ACC+P,move data LTP dma/ind : load T, P->ACC
Characteristics of TI ‘C5x DSPs
Switchable between Data & Program memory