Professional Documents
Culture Documents
DSP PROCESSOR
Exp. No. :
Date:
GENERATION OF SIGNALS
AIM:
To perform the following programs using TMS320C50 processor:
Square wave generation
Sine wave generation
Sawtooth wave generation
Triangular wave generation
COMPONENTS REQUIRED:
1. C50 processor kit
2. CRO
3. Function generator
4. Power cable and probes
PROCEDURE:
1.
2.
3.
4.
5.
6.
7.
CODING:
SQUARE WAVE GENERATION:
.mmregs
.text
start:
ldp #100h
lacc #0fffh ;change this value for amplitude.
loop: sacl 0
rpt #0ffh ;change this value for frequency.
out 0,04
;address for dac.
cmpl
b
loop
.end;
OUTPUT:
SACL TEMP
;store it
OUT TEMP1,4
;send sine data to DAC
MAR *,AR2
BANZ CONT,*b
START
DELAY:
lar ar7,#delay
mar *,ar7
back: banz back,*ret;
TABLE
.word
XXX
OUTPUT:
.mmregs
.text
start:
ldp #120h
lacc #0h ;change lower amplitude
sacl 0
loop: lacc 0
out 0,04h
add #05h ;change frequency
sacl 0
sub #0fffh ;change upper amplitude
bcnd loop,leq
b
start
.end;
OUTPUT:
OUTPUT:
RESULT:
Thus fundamental waveform generations are performed using DSP
processor.
Exp. No. :
Date:
CONVOLUTION
AIM:
To perform the following programs using TMS320C50 processor:
Linear convolution
Circular convolution
COMPONENTS REQUIRED:
1.
2.
3.
4.
THEORY:
In general, convolution operations is of 2 types. They are:
1. Linear convolution
2. Circular convolution
Linear convolution is a complex operation and this can be carried out
using MAC and MACD instructions. It is given by:
y(n)=x(n)*h(n)
where y(n) is the output sequence and x(n) & h(n) are the input sequences
Convolution in frequency domain is calculated by process of multiplication and
accumulation with proper shifting of sequences. MAC and MACD instructions
are used in TMS processor for this purpose of performing linear convolution.
Differences between MAC and MACD:
MAC
MACD
MAC pma,dma
Data shift is not automatically produced
MACD pma,{ind},[nextARP]
It provides shifting automatically
CIRCULAR CONVOLUTION:
Consider two finite duration sequence of length N namely x(n) and y(n). Their
respective N-point DFTs are
N 1
X ( k ) = x(n)e
( j *2* *n*k ) / N
n =0
N 1
( j *2**n*k ) / N
Y ( k ) = y(n)e
n =0
, k = 0,1,2,3.......... .( N 1)
, k = 0,1,2,3.......... .( N 1)
Multiplying the DFTs together ,the result is a DFT, say Z(k) of a sequence z(n) of length N.
Z(k) = x(k).Y(k), k=0,1,2,3,(N-1)
The IDFT of Z(k) is given as
( N ) z ( k ) e (
N 1
Z ( n) = 1
j * 2* * n * k ) / N
k =0
Substituting the values and rearranging the above equation we get the following term,
( N ) x( n ) y( n ) e (
z( n) = 1
N 1
N 1
n=0
i =0
j *2* *( m n 1 ) *k ) N
The inner sum in the brackets of the above equation is of the form
N 1
= N , a = 1 and
= 1 a / (1 a )
k =0
where a is defined as
e ( j*2**( m n 1)*k ) N .
we observe that a=1 when m-n-1 is a multiple of N. On the other hand aN =1 for any value a=0.
Consequently the above equation reduces to
N 1
a
k =0
= N , l = ( m n + pN ) = ( m n ) N ,
p is an integer
= 0, otherwise
Substituting this result in Z(n), we get
( N ) x( n ) y ( m n )
z( n) = 1
N 1
This expression has the form of a convolution sum. It is not the linear
convolution which relates the output sequences of linear system to the input
sequence of x(n) and the impulse response h(n). Instead, the convolution sum
involves the index (m-n)N and is called the CIRCULAR CONVOLUTION.
Thus we conclude that multiplication of the DFTs of two sequences is
equivalent to the circular convolution of two sequences in time domain.
PROCEDURE:
1. Open the C50 debugger software.
2. In Menu bar, choose Serial => Port settings => Set to Com1.
3. Go to Project => New Project and save it as .dpj file.
4. Go to File => New => Assembly file, then type the program and save it.
5. In Assembly folder, choose the option Add file to Project and save it.
6. Similarly in .cmd file, Add file to project and save it.
7. Now go to Project in Menu bar and choose the option Buuld and in Serial
=> Load program.
8. Now the program will be loaded in the kit.
9. In Communication window, type input and view the output.
10.Close the window.
LINEAR CONVOLUTION:
CODING:
;-------------------------------------------------------------------;
LINEAR CONVOLUTION
" y(n) = x(n)*h(n)"
;-------------------------------------------------------------------.mmregs
.text
START:
LDP
#100H
LAR
AR1,#(8100H+4H)
; x(n) Input Location
(8100h)
ZAC
MAR
*,AR1
RPT
#2H
SACL*+
LAR
AR1,#(8200H+4H)
ZAC
MAR
*,AR1
RPT
#2H
SACL*+
AR3,#(8300H+6H)
AR4,#06H
LAR
LAR
AR1,#8100H
AR2,#(8200H+6H)
AR0,#06H
MPY
LTP
ADD
SACL0H
BANZ
0H
MAR
SACL*-
*-,AR1
*+,AR0
0H
*,AR1
*+,AR2
Loop_MAC:
LACC
Loop_MAC,*-,AR2
*,AR3
; Store O/P Data "y(n)"
AR1,#(8100H+6H)
LAR
AR2,#5H
AR0,#2H
MAR
*,AR1
LACC
*SACL1H
; x(n)
; Shift Count-1
; Index Value 2H
Shift_XN:
LACC
*+
SACL*0-,AR2
BANZ
Shift_XN,*-,AR1
MAR
*+
LACC
1H
SACL*,AR4
BANZ
Next_YN,*NOP
H1:
B
H1
;-------------------------------------------------------------------OUTPUT :
;INPUT ( x(n) )
;
;
;
;
8100
8101
8102
8103
-1
-3
-1
-3
;INPUT ( h(n) )
;
;
;
;
8200
8201
8202
8203
-1
-2
-1
-0
;OUTPUT (y(n) )
;
8300 - 1
;
8301 - 5
;
8302 - 8
;
8303 - 8
;
8304 - 7
;
8305 - 3
;
8306 - 0
;----------------------------------------------------------------
CIRCULAR CONVOLUTION
Mnemonic
Comments
LDP #0100H
LACC #00H
SUB #01H
LAR AR0,1H
LAR AR1,#8060H
LAR AR2,#8100H
COPYX2:MAR *,AR1
LACC *+
MAR *,AR2
SACL *+
MAR *,AR0
BANZ COPYX2,*
LAR AR0,1H
LAR AR2,#8010H
LOOP3:LAR AR1,#8060
LAR AR3,#8050
LAR AR4,1H
ZAP
LOOP:MAR *,AR3
LT*+
MAR *,AR1
MPY *+
SPL 5H
ADD 5H
MAR *,AR4
SACL *+
CALL ROTATE
LOOP2:MAR *,AR0
BANZ LOOP3,*H: B H
ROTATE :LDP # 0100H
LACC 01H
SUB 02H
LACC 0050H
SACB
LAR AR3,#8051
LAR AR5,#8070
LAR AR6,2H
LOOP1:MAR *,AR3
LACC *+
MAR *,5
SACL *+
MAR *,6
BANZ LOOP1,*LACB
MAR *,AR5
SACL *+
LACC #8070H
SAMM BMAR
LAR AR3,#8050H
MAR *,AR3
RPT #3H
BLDD BMAR,*+
RET
Return
SAMPLE INPUT:
x(n):
h(n):
Memory
location
Data
8050
Memory location
Data
0001
8060
0005
8051
0002
8061
0006
8052
0003
8062
0007
8053
0004
8063
0008
SAMPLE OUTPUT:
Memory
location
Data
8010
0046
8011
0040
8012
003E
8013
0040
RESULT:
Thus the linear and circular convolution of two entered
sequence is performed using DSP processor.
Exp. No.:
Date:
0 <= k
0 <= k
<= 3
When X(e^jw) is sampled with sampling period 2*pi/4 the
corresponding discrete time sequence x(n) becomes periodic in
time with period 4.
3
ALGORITHM:
1. Initially set value of
N=4,Pi=180,k=6,I=8,CON=5,temp=4,count=2,input=8000,real=8010,i
mg=8020,cossin=8030
2. Load data page of 0100H.store a long immediate value of 2 in the
memory location of 800A.
3. Load auxiliary register pointer AR0 with a value of
count,AR6=1,AR3=cossin. Modify ARP to AR3 .Repeat next
instruction 9 times.
INITIALISATION SEQUENCE:
.MMREGS
.TEXT
N
.set
4H
PI
.set
180
.set
06H
.set
08H
CON
.set
05H
TEMP
.set
04H
COUNT .set
3H
INPUT
.set
8000H
REAL
.set
8010H
IMG
.set
COSSIN
.set
8020H
8030H
PROGRAM:
Mnemonic
Comments
LDP #100H
SPLK #2,000A
LAR AR0,#COUNT
LAR AR6,#1
count
Load the AR6 with value of 01 in memory pointed by
LAR AR3=cossin
AR6
Load the AR3 with value of cossin in memory pointed
MAR *,AR3
RPT #9
BPLD #TABLE,*+
by AR3
Modify ARP to AR3
Repeat the next instruction 9 times
Block move from program memory to data memory of
LT 000A
MPY #PI
SPL CON
Loop4:
LAR AR0,#COUNT
Loop3:
flat register
Load the Ar0 with the count value
Load TREG with value of constant as 2 and with PI
LT CON(2*PI)
MPY K
SPL 0007
CALL MUL
LACC TEMP
MAR *,AR2
SACL *+
LACC K,0
ADD #1H
SACL K
MAR *,AR0
1
Load acc with k as 0
Add1 with acc and result is stored in acc
Store acc lower with value of k as 1
Modify ARP to AR0
SACL I
LT 0007
MPY I
PAC
RPT #15
SUBC 0009H
result in acc
Product pregister value is stored in acc
Repeat the next instruction 15 times
Subtract the acc content and CREG and the result is
SACL 000B
Loop2:
LACC 000BH
SUB 000C
stored in acc
Store the acc lower content in 800B
Load the acc value in memory location 800B
Subtract the acc content and CREG and the result is
stored in acc
BCND Loop1,EQ
ADD #90
SACL 000C
MAR *,AR3
ADRK #1H
BLOOP2
Loop1:
LACC TEMP
MAR *,AR3
MPY *+
APAC
LACB
ADD #1
SACB
MAR *,AR1
BANZ Loop,*RET
REALT:
A RP by 1
Add product register and accumulator
Load the acc buffer to acc
Add the acc value with 1 and result is stored in acc
Store the acc buffer from acc
Modify ARP to AR1
Branch on no zero to loop. Then decrement ARP by 1
Return to main program
Load acc with value of imaginary
LACC #IMG
SAMM BMAR
LAR AR3,#REAL
MAR *,AR5
RPT #3
BLDD BAMR,*+
RET
TABLE(COS VALUES)
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
00001H
00000H
0FFFFH
00000H
00001H
00000H
0FFFFH
00000H
.WORD
.WORD
00001H
00000H
TABLE(SIN VALUES)
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
.WORD
00000H
00001H
00000H
0FFFFH
00000H
00001H
00000H
0FFFFH
00001H
00001H
SAMPLE INPUT:
Memory
location
Data
8000
0001
8001
0001
8002
0000
8004
0000
SAMPLE OUTPUT:
Memory
location
Data
8010
0002
8011
0001
8012
0000
8013
0001
Memory
Data
IMAGINARY:
location
8020
0000
8021
FFFF
8022
0000
8023
0001
FIR LOWPASS:
CODING :
* Approximation type: Window design - Blackmann Window
* Filter type: Lowpass filter
* Filter Order: 52
* Cutoff frequency in KHz = 3.000000
.mmregs
.text
B
START
CTABLE:
.word 0FFE7H
;Filter coefficients n=0
.word 0FFD3H
.word 0FFC6H
.word 0FFC4H
.word 0FFD0H
.word 0FFECH
.word 018H
.word 051H
.word 08CH
.word 0B9H
.word 0C2H
.word 092H
.word 01AH
.word 0FF5FH
.word 0FE78H
.word 0FD9AH
.word 0FD10H
.word 0FD30H
.word 0FE42H
.word 071H
.word 03B5H
.word 07CAH
.word 0C34H
.word 01054H
.word 01387H
.word 01547H
.word 01547H
.word 01387H
.word 01054H
.word 0C34H
.word 07CAH
.word 03B5H
.word 071H
.word 0FE42H
.word 0FD30H
.word 0FD10H
.word 0FD9AH
.word 0FE78H
.word 0FF5FH
.word 01AH
.word 092H
.word 0C2H
.word 0B9H
.word 08CH
.word 051H
.word 018H
.word 0FFECH
.word 0FFD0H
.word 0FFC4H
.word 0FFC6H
.word 0FFD3H
.word 0FFE7H
;Filter coefficients n=52
*
Move the Filter coefficients
*
from program memory to data memory
START:
MAR *,AR0
;This block moves the
filter coefficient from pgm memory to data memory.
LAR AR0,#0200H
RPT #33H
BLKPCTABLE,*+
SETC CNF
* Input data and perform convolution
ISR: LDP #0AH
LACC
#0
SACL0
OUT 0,05
IN
0,06H
LAR AR7,#0
MAR *,AR7
BACK:
BANZ
BACK,*IN
0,4
NOP
NOP
NOP
NOP
MAR *,AR1
LAR AR1,#0300H
LACC
0
AND #0FFFH
SUB #800H
SACL*
LAR AR1,#333H
MPY #0
ZAC
RPT #33H
MACD
0FF00H,*OPERATION
APAC
LAR AR1,#0300H
SACH
*
LACC
*
ADD #800h
SACL*
OUT *,4
LACC
#0FFH
SACL0
OUT 0,05
NOP
B
ISR
.end
FIR BANDPASS:
;CONVOLUTION
CODING:
* Approximation type: Window design - Blackmann Window
* Filter type: bandpass filter
* Filter Order: 52
* lower Cutoff frequency in KHz = 3.000000Hz
* upper Cutoff frequency in KHz = 5.000000Hz
.mmregs
.text
B
START
CTABLE:
.word 024AH
.word 010FH
.word 0FH
.word 0FFECH
.word 0C6H
.word 0220H
.word 0312H
.word
02D3H
.word 012FH
.word 0FEBDH
.word 0FC97H
.word 0FBCBH
.word 0FCB0H
.word 0FE9EH
.word 029H
.word 0FFDCH
.word 0FD11H
.word 0F884H
.word 0F436H
.word 0F2A0H
.word 0F58AH
.word 0FD12H
.word 075FH
.word 01135H
.word 01732H
.word
01732H
.word 01135H
.word 075FH
.word 0FD12H
.word 0F58AH
.word 0F2A0H
.word 0F436H
.word 0F884H
.word 0FD11H
.word 0FFDCH
.word 029H
.word 0FE9EH
.word 0FCB0H
.word 0FBCBH
.word 0FC97H
.word 0FEBDH
.word 012FH
.word 02D3H
.word 0312H
.word 0220H
.word 0C6H
.word 0FFECH
.word 0FH
.word 010FH
.word 024AH
*
Move the Filter coefficients from program memory to
data memory
START:
MAR
*,AR0
LAR
AR0,#0200H
RPT
#33H
BLKP
CTABLE,*+
SETC
CNF
LDP #0AH
LACC
#0
SACL
OUT
0,05
IN
0,06H
LAR
AR7,#0
MAR
*,AR7
BACK:
BANZ
IN
0,4
BACK,*-
NOP
NOP
NOP
NOP
MAR
*,AR1
LAR
AR1,#0300H
LACC
AND
#0FFFH
SUB
#800H
SACL
LAR
AR1,#333H
MPY
#0
ZAC
RPT
#33H
MACD
0FF00H,*-
APAC
LAR
AR1,#0300H
SACH
LACC
ADD
#800H
SACL
OUT
*,4
LACC
#0FFH
SACL
OUT
0,05
NOP
B
ISR
.end
OBSERVATION:
Amplitude ( V )
( dB )
OUTPUT:
FIR LOW PASS FILTER
Amplitude ( V )
( dB )
RESULT:
Thus FIR filters have been implemented using DSP
processor.
Exp. No. :
Date:
IIR LOWPASS:
CODING:
.MMREGS
.TEXT
TEMP .SET 0
INPUT .SET 1
T1
.SET 2
T2
.SET 3
T3
.SET 4;
K
.SET 315eh
M
.SET 4e9fh
;cut-off freq is 1Khz. = Fc
;sampling frequency is 100 hz (ie) 0.1ms.
; a = 2 * (355/113) * 1000 = 6283.18/1000 = 6.28 ;; divide by
1000 for secs
; K = aT/(1+aT) = 6.28*0.1 / (6.28*0.1+1) = 0.3857
; M = 1/(1+aT) = 1 / (6.28*0.1+1) = 0.61425
;convert to Q15 format
; K = K * 32767 = 12638.23 = 315Eh
; M = M * 32767 = 20127.12 = 4E9Fh
;Sampling Rate is 100 s & Cut off Frequency is 1 Khz
LDP #100H
LACC #0
SACL T1
SACL T2
SACL TEMP
OUT TEMP,4
;CLEAR DAC BEFORE START TO
WORK
LOOP:
LACC #0
SACL TEMP
OUT TEMP,5
;OUTPUT LOW TO DAC2 TO
CALCULATE TIMING;
IN
TEMP,06
;SOC;
LAR AR7,#30h
;CHANGE VALUE TO MODIFY
SAMPLING FREQ.
; sampling rate 100 sec.
MAR *,AR7
BACK:
BANZ
BACK,*;
IN
INPUT,4
;INPUT DATA FROM ADC1
NOP
NOP
; LACC INPUT
AND #0FFFH
SUB #800h
SACL INPUT
; LT
INPUT
MPY #K
PAC
SACH T1,1
;;;CALL MULT ----MULTIPLICATION TO BE DONE WITH
K
;;RESULT OF MULT IN T1
;
LT
T2
;PREVIOUS RESULT IN T2
MPY #M
PAC
SACH T3 ,1
;;;CALL MULT ----MULTIPLICATION TO BE DONE WITH
M
;;RESULT OF MULT IN T3+
;
LACC T1
ADD T3
SACL T2
ADD #800h
SACL TEMP
OUT TEMP,4
;OUTPUT FILTER DATA TO
DAC1
;
LACC #0FFH
SACL TEMP
OUT TEMP,5
;OUTPUT HIGH TO DAC2 TO
CALCULATE TIMING
;
B
LOOP
IIR BANDSTOP:
CODING:
.MMREGS
.TEXT
START:
LDP #100H
NOP
NOP
NOP
LACC #00H
LAR AR0,#00FFH
LAR AR1,#8000H
MAR *,AR1
LOOP:
SACL *+,AR0
BANZ LOOP,AR1
LOOP1:
LACC #00H
SACL 00H
IN 0,06H
LAR AR7,#30H
MAR *,AR7
BACK:
BANZ BACK,*IN 0,04H
NOP
NOP
NOP
NOP
LT 04H
MPY #2FC4H
;
MPY #05F8H
PAC
SACH 24H,0
;
SACH 24H,4
LT 03H
MPY #99B2H
;
MPY #1336H
PAC
SACH 23H,0
;
SACH 23H,4
LT 02H
MPY #0DB29H
;
MPY #1B65H
PAC
SACH 22H,0
;
SACH 22H,4
LT 01H
MPY #99B2H
;
MPY #1336H
PAC
SACH 21H,0
;
SACH 21H,4;
LACC 03H
SACL 04H
LACC 02H
SACL 03H
LACC 01H
LACC 02H;
LACC 00H
AND #0FFFH
XOR #800H
SUB #800H
SACL 00H
SACL 01H
ZAP
;
DMOV 03H
;
DMOV 02H
;
DMOV 01H
LT 00H
MPY #2FC4H
;
MPY #05F8H
PAC
SACH 20H,0
;
SACH 20H,4
;
LT 73H
MPY #2A22H
;
MPY #0544H
PAC
SACH 63H,0
;
SACH 63H,4
LT 72H
MPY #6761H
;
MPY #0CECH
PAC
SACH 62H,0
;
SACH 62H,4
LT 71H
MPY #0B6E8H
;
MPY #16DDH
PAC
SACH 61H,0
;
SACH 61H,4
;
LACC 72H
SACL 73H
LACC 71H
SACL 72H
LACC 70H
SACL 71H
;
DMOV 72H
;
DMOV 71H
;
LTD 70H
LT 70H
MPY #0F184H
;
MPY #1E30H
PAC
SACH 60H,0;
LACC 20H
SUB 21H
ADD 22H
SUB 23H
ADD 24H
ADD 60H
SUB 61H
ADD 62H
SUB 63H
SACL 70H
ADD #800H
SACL 00H
;
OUT 00H,1AH
IN 0,04H
B LOOP1
NOP
;
H:B H
SACH 60H,4
NOP
OBSERVATION:
IIR LOW PASS FILTER
Vin=
Gain= 20 log ( Vo/ Vin)
Frequency ( Hz )
Amplitude ( V )
( dB )
OUTPUT:
IIR LOWPASS FILTER
Amplitude ( V )
( dB )
RESULT:
Thus IIR filters have been implemented using DSP
processor.