Vous êtes sur la page 1sur 50

# www.jprnotes.blogspot.

com1

## RAJALAKSHMI ENGINEERING COLLEGE

THANDALAM, CHENNAI- 602105

## EC2306 - DIGITAL SIGNAL PROCESSING LABORATORY MANUAL

www.jprnotes.blogspot.com2

EC2306

## DIGITAL SIGNAL PROCESSING LAB

USING TMS320C5X/TMS320C 67XX/ADSP 218X/219X/BS531/532/561 1. Study of various addressing modes of DSP using simple programming examples 2. Implementation of Linear and Circular Convolution 3. Sampling of input signal and display 4. Waveform generation 5. Implementation of FIR filter

USING MATLAB 1. 2. sequences 3. 4. 5. 6. 7. Sampling and effect of aliasing Design of FIR filters Design of IIR filters Calculation of FFT of a signal Decimation by polyphase decomposition. Generation of Signals Linear and circular convolution of two

www.jprnotes.blogspot.com3

1. MATLAB PROGRAMS
1. LINEAR CONVOLUTION clc;clear all;close all; x=input('ENTER THE FIRST SEQUENCE '); h=input('ENTER THE SECOND SEQUENCE '); y=conv(x,h); stem(y); xlabel('Amplitude---->'); ylabel('time----->'); title('LINEAR CONVOLUTION'); 2. Program illustrates the design of a Butterworth bandstop filter. % Program P7_1 % Design of a Butterworth Bandstop Digital Filter Ws = [0.4 0.6]; Wp = [0.3 0.7]; Rp = 0.4; Rs = 50; % Estimate the Filter Order [N1, Wn1] = buttord(Wp, Ws, Rp, Rs); % Design the Filter [num,den] = butter(N1,Wn1,stop); % Display the transfer function disp(Numerator coefficients are );disp(num); disp(Denominator coefficients are );disp(den); % Compute the gain response [g,w] = gain(num,den); % Plot the gain response plot(w/pi,g);grid axis([0 1 -60 5]); xlabel(\omega /\pi); ylabel(Gain, dB); title(Gain Response of a Butterworth Bandstop Filter);

3. To implement a causal IIR filter implemented in the Direct Form II structure, the function direct2 given below can be employed. function [y,sf] = direct2(p,d,x,si); % Y = DIRECT2(P,D,X) filters input data vector X with % the filter described by vectors P and D to create the % filtered data Y. The filter is a "Direct Form II" % implementation of the difference equation: % y(n) = p(1)*x(n) + p(2)*x(n-1) + ... + p(np+1)*x(n-np)

www.jprnotes.blogspot.com4 % - d(2)*y(n-1) - ... - d(nd+1)*y(n-nd) % [Y,SF] = DIRECT2(P,D,X,SI) gives access to initial and % final conditions, SI and SF, of the delays. dlen = length(d); plen = length(p); N = max(dlen,plen); M = length(x); sf = zeros(1,N-1); y = zeros(1,M); if nargin ~= 3, sf = si; end if dlen < plen, d = [d zeros(1,plen - dlen)]; else p = [p zeros(1, dlen - plen)]; end p = p/d(1); d = d/d(1); for n = 1:M; wnew = [1 -d(2:N)]*[x(n) sf]; K = [wnew sf]; y(n) = K*p; sf = [wnew sf(1:N-2)]; end

4. Program illustrates the design of a causal IIR filter, its simulation in transposed Direct Form II, and its application in filtering a signal. % Program P8_3 % Illustration of Filtering by an IIR Filter % clf; % Generate the input sequence k = 0:50; w2 = 0.7*pi;w1 = 0.2*pi; x1 = 1.5*cos(w1*k); x2 = 2*cos(w2*k); x = x1+x2; % Determine the filter transfer function [N, Wn] = ellipord(0.25, 0.55, 0.5, 50); [num, den] = ellip(N,0.5, 50,Wn); % Generate the output sequence y = filter(num,den,x); % Plot the input and the output sequences subplot(2,1,1); stem(k,x); axis([0 50 -4 4]); xlabel(Time index n); ylabel(Amplitude); title(Input Sequence); subplot(2,1,2);

www.jprnotes.blogspot.com5 stem(k,y); axis([0 50 -4 4]); xlabel(Time index n); ylabel(Amplitude); title(Output Sequence);

5. Program up-sampler. % Illustration of Up-Sampling by an Integer Factor % clf; n = 0:50; x = sin(2*pi*0.12*n); y = zeros(1, 3*length(x)); y([1: 3: length(y)]) = x; subplot(2,1,1) stem(n,x); title(Input Sequence); xlabel(Time index n);ylabel(Amplitude); subplot(2,1,2) stem(n,y(1:length(x))); title(Output Sequence); xlabel(Time index n);ylabel(Amplitude);

6. Illustration of Down-Sampling by an Integer Factor clf; n = 0: 49; m = 0: 50*3 - 1; x = sin(2*pi*0.042*m); y = x([1: 3: length(x)]); subplot(2,1,1) stem(n, x(1:50)); axis([0 50 -1.2 1.2]); title(Input Sequence); xlabel(Time index n); ylabel(Amplitude); subplot(2,1,2) stem(n, y); axis([0 50 -1.2 1.2]); title(Output Sequence); xlabel(Time index n); ylabel(Amplitude);

www.jprnotes.blogspot.com6

7. Use fir2 to create a bandlimited input sequence clf; freq = [0 0.45 0.5 1]; mag = [0 1 0 0]; x = fir2(99, freq, mag); % Evaluate and plot the input spectrum [Xz, w] = freqz(x, 1, 512, whole); subplot(2,1,1); plot(w/pi, abs(Xz)); axis([0 1 0 1]); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Input Spectrum); subplot(2,1,2); % Generate the up-sampled sequence L = input(Type in the up-sampling factor = ); y = zeros(1, L*length(x)); y([1: L: length(y)]) = x; % Evaluate and plot the output spectrum [Yz, w] = freqz(y, 1, 512, whole); plot(w/pi, abs(Yz)); axis([0 1 0 1]); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Output Spectrum);

8. Program P10 4 can be employed to study the frequency-domain properties of the downsampler. % Program P10_4 % Effect of Down-sampling in the Frequency Domain % Use fir2 to create a bandlimited input sequence clf; freq = [0 0.42 0.48 1]; mag = [0 1 0 0]; x = fir2(101, freq, mag); % Evaluate and plot the input spectrum [Xz, w] = freqz(x, 1, 512); subplot(2,1,1); plot(w/pi, abs(Xz)); grid xlabel(\omega/\pi); ylabel(Magnitude); title(Input Spectrum); % Generate the down-sampled sequence M = input(Type in the down-sampling factor = ); y = x([1: M: length(x)]); % Evaluate and plot the output spectrum [Yz, w] = freqz(y, 1, 512); subplot(2,1,2);

## 9. FIR FILTER USING RECTANGULAR WINDOW

clc;close all;clear all; rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); fp=input('enter the passband ripple'); fs=input('enter the stopband ripple'); f=input('enter the sampling frequency'); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rs*rp))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); if(rem(n,2)~=0) n=n1; n=n-1; end y=RECTWIN(n1); %bandpass filter wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10*(abs(h)); an=angle(h); subplot(2,1,1); plot(o/pi,m); xlabel('normalised freq-->'); ylabel('gain in db-->'); subplot(2,1,2); plot(0/pi,an); xlabel('normalised freq-->'); ylabel('phase in radians-->');

www.jprnotes.blogspot.com8

10. FIR FILTER USING HAMMING WINDOW clc; clear all; close all rp=input('enter the passband ripple'); rs=input('enter the stopband ripple'); fp=input('enter the passband freq'); fs=input('enter the stopband freq'); f=input('enter the sampling freq'); wp=2*fp/f;ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if(rem(n,2)~=0); n1=n; n=n-1; end y=hamming(n1); %LOW -PASS FILTER b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,1);plot(o/pi,m); ylabel('gain in db-->'); xlabel('(a)normalised frequency-->'); title('LOW-PASS FILTER'); %BAND PASS FILTER wn=[wp ws]; b=fir1(n,wn,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); subplot(2,2,3);plot(o/pi,m); ylabel('gain in db-->'); xlabel('(c)normalised frequency-->'); title('BAND PASS FILTER'); 11. CIRCULAR CONVOLUTION clc; clear all;

www.jprnotes.blogspot.com9 close all; g=input('1 sequence'); h=input('2 sequence'); N1=length(g); N2=length(h); N=max(N1,N2); N3=N1-N2; if(N3>=0) h=[h,zeros(1,N3)]; else g=[g,zeros(1,-N3)]; end for n=1:N y(n)=0; for i=1:N j=n-i+1; if(j<=0) j=N+j; end end y(n)=[y(n)+g(i)*h(j)]; stem(y) end 12. IIR FILTER DESIGN clc; close all; clear all; rp=input('enter the pass band ripple'); rs=input('enter the stop band ripple'); wp=input('enter the pass band freq'); ws=input('enter the stop band freq'); fs=input('enter the sampling feq'); w1=2*wp/fs; w2=2*ws/fs; [h,wn]=buttord(w1,w2,rp,rs); [b,a]=butter(h,wn); w=0:.01:pi; [h,om]=freqz(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,1,1); plot(om/pi,m); ylabel('gain in db....>');

www.jprnotes.blogspot.com10 xlabel('(a) normalised frequency>'); subplot(2,1,2); plot(om/pi,an); xlabel('(b) normalised frequency'); ylabel('phase in radian');

DSP PROGRAMS 1.
Sine Waveform generation

;Starting address :1000h ;Output address (DSPIK) : 2000h .include "5416_iv.asm" .def start .data .word 0555h ;1/3! .word 0044h ;1/5! .word 0001h ;1/7! .word 0fffh ;1/2! .word 0155h ;1/4! .word 000bh ;1/6! .word 7d00h .word 07cfh .word 0c8ch .word 0 .word 0 .word 256 .text LD #con1,DP RSBX INTM LD #022Bh,0,A STLM A,PMST

## con1 con2 con3 con4 con5 con6 fs fm pi ms mx CNT

start

;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD ;SPCR1 reset

www.jprnotes.blogspot.com11

NOP NOP STM STM STM STM STM STM SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD ;SPCR2 reset

## PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD ;RCR1 ;32 BITS WORDSIZE

STM RCR2,McBSP0_SPSA ;RCR2 STM #0001h,McBSP0_SPSD STM STM STM STM XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD ;XCR1 ;32 BITS WORDSIZE ;XCR2

STM SRGR1,McBSP0_SPSA ;SRGR1 STM #000Bh,McBSP0_SPSD ;--17 STM STM STM STM STM STM STM STM STM STM STM STM STM STM SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD XCERB,McBSP0_SPSA #0001h,McBSP0_SPSD XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB

;XCERA

www.jprnotes.blogspot.com12

## STM STM NOP NOP STM STM

SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD

## ;Take 'em out of reset

SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD

;--------------------------McBSP1 Initializations-----------------------------STM STM NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP1_SPSA #0020h,McBSP1_SPSD ;SPCR2 reset SPCR1,McBSP1_SPSA #0090h,McBSP1_SPSD ;SPCR1 reset

PCR,McBSP1_SPSA ;PCR #0A00h,McBSP1_SPSD RCR1,McBSP1_SPSA #00A0h,McBSP1_SPSD RCR2,McBSP1_SPSA #0000h,McBSP1_SPSD XCR1,McBSP1_SPSA #00A0h,McBSP1_SPSD XCR2,McBSP1_SPSA #0000h,McBSP1_SPSD SRGR1,McBSP1_SPSA #0002h,McBSP1_SPSD SRGR2,McBSP1_SPSA #303Bh,McBSP1_SPSD MCR1,McBSP1_SPSA #0001h,McBSP1_SPSD MCR2,McBSP1_SPSA ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2

## www.jprnotes.blogspot.com13 STM STM STM #0000h,McBSP1_SPSD RCERB,McBSP1_SPSA #0001h,McBSP1_SPSD ;RCERB ;RCERA

STM RCERA,McBSP1_SPSA STM #0001h,McBSP1_SPSD STM STM STM STM STM STM NOP NOP STM STM SPCR2,McBSP1_SPSA #00A1h,McBSP1_SPSD XCERB,McBSP1_SPSA #0001h,McBSP1_SPSD XCERA,McBSP1_SPSA #0001h,McBSP1_SPSD SPCR1,McBSP1_SPSA #0091h,McBSP1_SPSD

;XCERB ;XCERA

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

LD #02Fh,0,A STLM A,IMR STM STM STM STM STM STM NOP STM #0h,McBSP0_DXR1 #0h,McBSP0_DXR2 #0007h,GPIOCR #0003h,GPIOSR #SPCR2,McBSP1_SPSA #00E1h,McBSP1_SPSD #0007h,GPIOSR ;Mclk

WAIT

## NOP NOP LD CNT,A BC WAVE,AEQ NOP B WAIT

_XINT0_ISR LD STLM STLM *AR5+%,A A,McBSP0_DXR1 A,McBSP0_DXR2 ;o/p for R Channel ;o/p for L Channel

LD CNT,A SUB #1,A STL A,CNT RETE WAVE LD #0,A STLM A,IMR LD #con1,DP STM #1508h,AR2 LD fm,T MPY *AR2,A STM #1506h,AR2 RPT #15 SUBC *AR2,A STL A,ms ;COSINE APPROX

www.jprnotes.blogspot.com15

LD ms,T ;X STM #1509h,AR2 MPY *AR2+,A SFTA A,-5 STL A,*AR2 ;X^2 STM #150Ah,AR2 MPY *AR2+,A ;X^3 SFTA A,-9 STL A,*AR2 STM #150Bh,AR2 MPY *AR2+,A ;X^4 SFTA A,-9 STL A,*AR2 STM #150Ch,AR2 MPY *AR2+,A ;X^5 SFTA A,-9 STL A,*AR2 STM #150Dh,AR2 MPY *AR2+,A ;X^6 SFTA A,-9 STL A,*AR2 STM #150Eh,AR2 MPY *AR2+,A ;X^7 SFTA A,-9 STL A,*AR2 ;cos x = 1 - x ^2 / 2! + x^4 / 4! - x^6 / 6! + .... STM #150Ah,AR2 LD con4,T MPY *AR2,A SFTA A,-13 LD #1FFFh,B SUB A,B STM #150ch,AR2 LD con5,T MPY *AR2,A

www.jprnotes.blogspot.com16 SFTA A,-13 ADD A,B STM #150eh,AR2 LD con6,T MPY *AR2,A SFTA A,-13 SUB A,B STM #1600h,AR1 STL B,*AR1+ LD #0,A RPT #1 STL A,*AR1+ ;sin x = x - x ^3 / 3! + x^5 / 5! - x^7 / 7! + .... STM #150Bh,AR2 LD con1,T MPY *AR2,A SFTA A,-13 STM #1509h,AR2 LD *AR2,4,B SUB A,B STM #150Dh,AR2 LD con2,T MPY *AR2,A SFTA A,-13 ADD A,B STM #150Fh,AR2 LD con3,T MPY *AR2,A SFTA A,-13 SUB A,B STL B,*AR1 ;WAVE GENERATION STM #2000h,AR7 STM #256,BRC RPTB wave1 STM #1602h,AR2

www.jprnotes.blogspot.com17 STM #1600h,AR3 MPY *AR2,*AR3,A SFTA A,-12 STM #1602h,AR4 STM #1601h,AR5 MVDD *AR4,*AR5 STM #1603h,AR6 LD *AR6,B SUB B,A STL A,*AR7+ STM #1602h,AR6 STL A,*AR6 STM #1601h,AR4 STM #1603h,AR5 MVDD *AR4,*AR5 NOP NOP STM #2000h,AR5 NOP NOP LD #256,A STL A,CNT NOP NOP LD #02Fh,0,A STLM A,IMR NOP NOP B WAIT

wave1

## 2. Square wave generation

www.jprnotes.blogspot.com18 .def start .data .word 30 .word 30 .word 0 .word 0 .word 07fffh,08001h .word 128 .word 45h .text LD ; #POS,DP Data Page Pointer RSBX INTM LD #022Bh,0,A STLM A,PMST

## POS NEG P N CNT E start

;Positive Count value ;Negative Count Value ;Dummy 1 ;Dummy 2 ;Maximum Positive and Negative Values ;Total No.of Samples ;Display Character 'E'

;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP NOP STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD ;SPCR2 reset ;SPCR1 reset

PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE

## STM XCR2,McBSP0_SPSA ;XCR2 STM #0001h,McBSP0_SPSD

www.jprnotes.blogspot.com19 STM SRGR1,McBSP0_SPSA ;SRGR1 STM #0017h,McBSP0_SPSD ;--17 STM STM STM STM STM STM STM STM STM STM SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB

STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM STM STM NOP NOP STM STM SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD

;XCERA

## ;Take 'em out of reset

;--------------------------McBSP2 Initializations-----------------------------STM STM NOP NOP STM STM STM SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD PCR,McBSP2_SPSA ;SPCR2 reset ;PCR SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD ;SPCR1 reset

www.jprnotes.blogspot.com20 STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM NOP NOP STM STM SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD #0A00h,McBSP2_SPSD RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB ;XCERA

## ;Take 'em out of reset

www.jprnotes.blogspot.com21

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

LD #027h,0,A STLM A,IMR STM #0h,McBSP0_DXR1 STM #0h,McBSP0_DXR2 STM STM #0007h,GPIOCR #0003h,GPIOSR #SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD #0007h,GPIOSR #SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD ;Sclk & Fs ;Mclk

## STM STM NOP STM STM STM

;---------------------------------------------------------------------------;--------------------------Square Wave Generation Program------------------;--------------------------Initialisation------------------------------------------------------STM #128,BK SSBX SXM STM STM STM #1504h,AR2 ;Memory location of 7fffh #1505h,AR3 ;Memory location of 8001h #2000h,AR4 ;Square Wave Output

WAIT

## NOP NOP LD CNT,B BC WAVE,BEQ NOP B WAIT

www.jprnotes.blogspot.com22

_XINT0_ISR NOP NOP LD CODEC STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 LD CNT,B SUB #1h,B STL B,CNT RETE ;Count=Count-1

*AR4+%,A

## ;Transmitting Square Wave Output to

WAVE

LD #128,A STL A,CNT NOP NOP PORTW E,0 LD #0h,A STLM A,IMR

## ;Disable All the Interrupts (Interrupt Mask Register)

STM #1504h,AR2 STM #1505h,AR3 STM #2000h,AR4 STM #6,BRC RPTB L1 LD STL LD STL L2 POS,A A,P NEG,B B,N ;Positive Loop (30 Samples) ;Loop for 128 Samples

## LD *AR2,A STL A,*AR4+

www.jprnotes.blogspot.com23 LD P,B SUB #1h,B STL B,P BC L2,BNEQ L3 LD *AR3,A STL A,*AR4+ LD N,B SUB #1,B STL B,N BC L3,BNEQ L1 NOP NOP ;Negative Loop (30 Samples)

## LD #027h,A STLM A,IMR STM #2000h,AR4 B WAIT

;Initialization of Interrupts ;Interrupt Mask Register ;Output Memory ;Branch to Wait Loop

## 3. FIR application Program

;Filter order 9 ;Cutoff Frequency 1KHz ;-------------------------------------------------------------------------------;Starting address :1000h ;Input address : 1600h ;Output address : 1700h .include "5416_IV.asm" .data COEFF .word 086eh,0b9eh,0e5fh,1064h,1176h,1064h,0e5fh,0b9eh,086eh ;Filter Co-efficients in data ; memory .text start LD #COEFF,DP RSBX INTM ;Variable Declaration

www.jprnotes.blogspot.com24 LD #022Bh,0,A STLM A,PMST ;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD ;SPCR2 reset ;SPCR1 reset

PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD SRGR1,McBSP0_SPSA #000Bh,McBSP0_SPSD SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--17 ;SRGR2 ;MCR1 ;MCR2 ;RCERB

www.jprnotes.blogspot.com25

STM STM STM STM STM STM STM STM NOP NOP STM STM

;RCERA ;XCERB

;XCERA

## ;Take 'em out of reset

SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD

;--------------------------McBSP2 Initializations-----------------------------STM STM NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD ;SPCR2 reset SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD ;SPCR1 reset

PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2

www.jprnotes.blogspot.com26 STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM NOP NOP STM STM SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD SRGR1,McBSP2_SPSA #0002h,McBSP2_SPSD SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB ;XCERA

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

LD #02Fh,0,A STLM A,IMR STM STM STM STM #0h,McBSP0_DXR1 #0h,McBSP0_DXR2 #0007h,GPIOCR #0003h,GPIOSR

www.jprnotes.blogspot.com27 STM STM NOP STM STM STM #SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD #0007h,GPIOSR #SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD ;Sclk & Fs

;Mclk

;---------------------------------------------------------------------------;----------------Program Starts ----------------------------------------;------------------------Algorithm------------------------------------;-----FIR filter needs three buffers for Implementation ;-----One Buffer stores Input samples (128) ;-----Second Buffer is an Temporary buffer (Initially zero) (Size should be equal to the order of the filter) ;-----Third Buffer Stores the output ;------Implementation------------------------------------------------;------First the Input sample from the CODEC is loaded to an accumulator. ;------The accumulator value is loaded to an Input Buffer (1600h Memory Location). ;------Initialize the temporary buffer. ;------Move the first Input sample to the Temporary buffer from Input buffer. ;------Modify the Temporary buffer to point out the last location (In this example the modifier is 8 which is the order of ;the filter) ;-----Implementation of FIR filter is done by Using MACD Instruction ;-----Finally the output will be in Higher order. So Shift the output by -15. ;-----Store the Lower order value in Output buffer and transmit the output to CODEC.

SSBX SXM RSBX FRCT RSBX OVM STM #150,BK STM #1600h,AR5 STM #1700h,AR6 LD STM RPT STL STM #0h,A #1900h,AR3 #10 A,*AR3+ #1900h,AR3 ;Circular Buffer for Input and Output ;Input Buffer Starts at 1600h ;Output Buffer Starts at 1700h ;Temporary Buffer Initialization

www.jprnotes.blogspot.com28

WAIT

## NOP NOP B WAIT

_XINT0_ISR LDM CODEC) STL (1600h) STM #1900h,AR3 MVDD *AR5,*AR3 to Temporary Buffer RPT #7 MAR *AR3+ RPT #8 y(n)=x(k)*h(n-k) MACD *AR3-,COEFF,A SFTA A,-15 STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 STL MAR RETE A,0,*AR6+% *AR5+% ;Initialization of Temporary Buffer ;Moving Input Sample from Input buffer ;Modify Temporary buffer ;Implementation of FIR Filter A,0,*AR5 ;Loading Input Sample to an Input Buffer McBSP0_DRR1,A ;R Channel (Input Sample From

;Shifting the output to Lower order ;o/p for R Channel ;o/p for L Channel ;Output is stored at 1700h ;Modify the Input Buffer

## 4. FIR FILTER DESIGN

;Starting address : 0700h ;Input address :1600h ;Output address :1700h .include "5416_IV.asm" .def start .data .word 97e3h,154fh .word 0b4ch,1698h,0b4ch

bpole azero

## ;IIR Filter Co-efficients

www.jprnotes.blogspot.com29 xin xout yin S1 E .word .word .word .word .word .text start LD #bpole,DP RSBX INTM LD #022Bh,0,A STLM A,PMST ;Variable Declaration 0,0 0 0 00 45h

;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD ;SPCR2 reset ;SPCR1 reset

PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD SRGR1,McBSP0_SPSA #000Bh,McBSP0_SPSD SRGR2,McBSP0_SPSA ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--17 ;SRGR2

www.jprnotes.blogspot.com30 STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM NOP NOP STM STM SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD XCERB,McBSP0_SPSA #0001h,McBSP0_SPSD XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB

;XCERA

## ;Take 'em out of reset

;--------------------------McBSP2 Initializations-----------------------------STM STM NOP NOP STM STM STM STM STM STM SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD ;SPCR2 reset SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD ;SPCR1 reset

## PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD ;RCR1 ;32 BITS WORDSIZE

www.jprnotes.blogspot.com31

STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM NOP NOP STM STM

RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD SRGR1,McBSP2_SPSA #0002h,McBSP2_SPSD SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD

;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB ;XCERA

## ;Take 'em out of reset

SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

www.jprnotes.blogspot.com32

LD #02Fh,0,A STLM A,IMR STM STM STM STM STM STM NOP STM STM STM #0h,McBSP0_DXR1 #0h,McBSP0_DXR2 #0007h,GPIOCR #0003h,GPIOSR #SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD #0007h,GPIOSR #SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD ;Sclk & Fs ;Mclk

SSBX SXM RSBX FRCT RSBX OVM STM STM STM STM STM #128,BK #1600h,AR4 #1700h,AR1 #1400h,AR5 #1500h,AR6 ;Circular Buffer for Input and Output ;Input Buffer Starts at 1600h ;Output Buffer Starts at 1700h ;IIR Filter Output ;Zero Output Buffer

WAIT

## NOP NOP NOP NOP NOP B WAIT

_XINT0_ISR

www.jprnotes.blogspot.com33 LDM LDM STM STM STL NOP NOP LD STL NOP NOP STM McBSP0_DRR1,A McBSP0_DRR2,A #1800h,AR3 #1300h,AR7 A,0,xin xin,A A,0,*AR4+% ;R Channel (Input Sample From CODEC) ;R Channel (Input Sample From CODEC) ;Pole Temporary Buffer ;Pole Output Buffer

## xout,AR2 ;Multiplication of Input with zeros

RPT #02h MACD *AR2-,azero,A SFTA A,-15 STL A,0,*AR6 MVDD *AR5,*AR3+ LD #bpole,DP RPT #01h MACD *AR3-,bpole,A SFTA STL NOP NOP LD LD SUB STL STL A,-15 A,0,*AR7 *AR6,A *AR7,B B,0,A A,0,*AR5 A,0,*AR1+%

;Pole Output

## ;o/p for R Channel ;o/p for L Channel

www.jprnotes.blogspot.com34

;Starting address: 0700h ;Input address: 1000h ;Output address: 1800h .include "twi.asm" .include "twr.asm" .include "cos.asm" .include "5416_iv.asm" .def start .data .word 0h ;Variables .word 0h .word 7h .word 64 .word 0h .word 1h .word 0h .word 0h .word 0h .word 0h .word 40h .word 80h .word 40h .word 7Fh .word 128 .word 45h .text LD #R1,DP RSBX INTM LD #022Bh,0,A STLM A,PMST

R1 I1 stages grp grp1 but but1 R I A1 sizetw sizein bitr shi CNT E start

;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP NOP STM SPCR2,McBSP0_SPSA ;SPCR2 reset ;SPCR1 reset

www.jprnotes.blogspot.com35 STM STM STM STM STM STM STM STM STM #0020h,McBSP0_SPSD PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE

STM XCR2,McBSP0_SPSA ;XCR2 STM #0001h,McBSP0_SPSD STM SRGR1,McBSP0_SPSA ;SRGR1 STM #0017h,McBSP0_SPSD ;--17 STM STM STM STM STM STM STM STM STM STM SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB

STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM STM STM NOP XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD

;XCERA

## www.jprnotes.blogspot.com36 NOP STM STM SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD

;--------------------------McBSP2 Initializations-----------------------------STM STM NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD ;SPCR2 reset SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD ;SPCR1 reset

PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2 ;RCERB

www.jprnotes.blogspot.com37 STM STM STM STM STM STM STM STM NOP NOP STM STM SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD ;RCERA ;XCERB ;XCERA

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

LD #017h,0,A STLM A,IMR STM #0h,McBSP0_DXR1 STM #0h,McBSP0_DXR2 STM STM #0007h,GPIOCR #0003h,GPIOSR #SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD #0007h,GPIOSR #SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD ;Sclk & Fs ;Mclk

## www.jprnotes.blogspot.com38 STM #1800h,AR1 ;FFT O/p

SSBX SXM RSBX OVM LD #0h,0,A RPT #127 STL A,*AR1+ STM #1800h,AR1 STM #3500h,AR7

WAIT

## NOP NOP LD CNT,B BC FFT,BEQ NOP NOP B WAIT

_RINT0_ISR PSHM AL PSHM AH PSHM AG PSHM BL PSHM BH PSHM BG LD *AR6+,0,A STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 LD CNT,B SUB #1h,0,B STL B,0,CNT POPM BG POPM BH POPM BL POPM AG POPM AH ;o/p for R Channel ;o/p for L Channel

## www.jprnotes.blogspot.com39 POPM AL RETE

FFT

NOP NOP LD #0,A STLM A,IMR STM STM STM STM #1000h,AR6 #1800h,AR1 #2000h,AR4 #1000h,AR3

RPT #127 MVDD *AR4+,*AR3+ LD NOP LD STL NOP #R1,DP #80h,A A,CNT

PORTW E,0 ;------------Bit Reversal----------------------;------------For 128 pt FFT The Index value is 128/2=64(40H)------------------STM STM NOP NOP #0040h,AR0 ;Index #2400h,AR4 ;Bit reversed o/p

## RPT #127 MVPD #2000h,*AR4+0B NOP

;Bit Reversal

www.jprnotes.blogspot.com40 NOP STM #2400h,AR5 LD #0h,0,A STM #2800h,AR3 RPT #127 STL A,0,*AR3+ STM #3000h,AR3 STM #3400h,AR4 STM #40h,BK ;TWIDDLE REAL ;TWIDDLE IMAG

;--------------------------Butterfly Loop Begins-----------------------------------SU LD stages,0,A LD grp,0,B STL B,grp1 LD but,0,A STM #2400h,AR5 STM #2800h,AR2 GU LD #40h,B STLM B,BK LD but,0,A STL A,but1 LD #0h,0,B SUB A,0,B STL B,A1 STM #3000h,AR3 STM #3400h,AR4

BU

## LD #80h,B STLM B,BK LD *AR5,0,A LD *AR2,0,B STL A,0,R

www.jprnotes.blogspot.com41 STL B,0,I LD but,0,A STLM A,AR0 NOP NOP MAR *AR5+0% MAR *AR2+0% MPY MPY SUB STH MPY MPY ADD STH LD LD SUB STL *AR3,*AR5,A *AR4,*AR2,B B,0,A A,R1 *AR3,*AR2,A *AR4,*AR5,B A,0,B B,I1 R,-1,A R1,0,B B,0,A A,*AR5

LD I,-1,A LD I1,0,B SUB B,0,A STL A,*AR2 NOP NOP NOP LD A1,0,B STLM B,AR0 NOP NOP MAR *AR5+0% MAR *AR2+0% LD R,-1,A LD R1,0,B ADD B,0,A STL A,*AR5+

www.jprnotes.blogspot.com42 LD I,-1,A LD I1,0,B ADD B,0,A STL A,*AR2+ ;BUT NOP LD #40h,0,B STLM B,BK LD grp,0,A STLM A,AR0 NOP NOP NOP NOP MAR *AR3+0% MAR *AR4+0% LD SUB STL BC but1,0,B #1h,0,B B,0,but1 BU,BNEQ

;;;;;Butterfly End

LD #80h,B STLM B,BK NOP NOP NOP LD but,0,B STLM B,AR0 NOP NOP MAR *AR5+0% MAR *AR2+0% LD SUB STL BC NOP grp1,0,B #1h,0,B B,grp1 GU,BNEQ

;;;;;;;;Group End

## LD but,0,B SFTA B,1 STL B,but STL B,but1

www.jprnotes.blogspot.com43 LD grp,0,B SFTA B,-1 STL B,grp STL B,grp1 LD stages,0,A SUB #1h,0,A STL A,stages BC SU,ANEQ

;;;;;;;;;STAGES

LD LD

#0h,0,A #0h,0,B

;-------------------Initialization of Variables----------------------LD #7h,0,B STL B,stages LD #40h,0,A STL A,grp LD #1h,0,B STL B,but STM #2400h,AR3 STM #1800h,AR6 STM #7Fh,BRC RPTB VE LD *AR3+,A ABS A STL A,*AR6+ NOP NOP NOP STM #1800h,AR6

VE

## LD #0017h,A STLM A,IMR NOP NOP B WAIT 6. FSK DESIGN

www.jprnotes.blogspot.com44

;PROGRAM STARTING ADDRESS 001000 ;GRAPH STARTING ADDRESS 001700 ;This program is to generate a sine wave from a look-up-table ;There are 16 sine wave samples that represent the 360 degrees of the sine wave starting from S1 .include "5416_IV.asm" .data .word 40h .word 0h .word 0h .include "1000.asm" .include "2000.asm" .text start RSBX INTM LD #022Bh,0,A STLM A,PMST ;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP NOP STM STM STM STM STM STM SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD ;SPCR2 reset ;SPCR1 reset

## PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD ;RCR1 ;32 BITS WORDSIZE

www.jprnotes.blogspot.com45 STM STM STM STM RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD ;RCR2 ;XCR1 ;32 BITS WORDSIZE

STM XCR2,McBSP0_SPSA ;XCR2 STM #0001h,McBSP0_SPSD STM SRGR1,McBSP0_SPSA ;SRGR1 STM #0017h,McBSP0_SPSD ;--17 STM STM STM STM STM STM STM STM STM STM SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB

STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM STM STM NOP NOP STM STM SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD

;XCERA

## ;--------------------------McBSP2 Initializations-----------------------------STM SPCR1,McBSP2_SPSA ;SPCR1 reset

www.jprnotes.blogspot.com46 STM NOP NOP STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM STM SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD ;SPCR2 reset #0090h,McBSP2_SPSD

PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD ;RCR1 ;32 BITS WORDSIZE ;RCR2 ;XCR1 ;32 BITS WORDSIZE ;XCR2 ;SRGR1 ;--5 ;SRGR2 ;MCR1 ;MCR2 ;RCERB ;RCERA ;XCERB ;XCERA

www.jprnotes.blogspot.com47

## STM STM NOP NOP STM STM

SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD

## ;Take 'em out of reset

SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD

## ;--------------------End of Serial Ports Initializations----------------------RSBX INTM

LD #02Fh,0,A STLM A,IMR STM #0h,McBSP0_DXR1 STM #0h,McBSP0_DXR2 STM STM #0007h,GPIOCR #0003h,GPIOSR #SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD #0007h,GPIOSR #SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD ;Sclk & Fs ;Mclk

## STM STM NOP STM STM STM

;---------------------------------------------------------------------------STM #64,BK STM #1700h,AR6 STM #1650h,AR7 LD #0h,A RPT #1000h STL A,*AR7+ STM #1650h,AR7

WAIT

NOP

## www.jprnotes.blogspot.com48 NOP NOP LD CNT,A BC FSK,AEQ NOP NOP B WAIT

_XINT0_ISR LDM LDM McBSP0_DRR1,A McBSP0_DRR2,A PORTR 0h,VAR LD *AR6+%,A STLM STLM LD SUB STL RETE FSK LD STL STM STM STM STM #40h,A A,CNT #1650h,AR1 #1700h,AR2 ;OUTPUT #1600h,AR3 ;1000Hz #1610h,AR4 ;2000Hz A,McBSP0_DXR1 A,McBSP0_DXR2 CNT,A #1h,A A,CNT ;o/p for R Channel ;current(Y) ;o/p for L Channel ;voltage(R) ;R Channel ;L Channel

LD VAR,A AND #00FFh,A NOP NOP STL A,VAR STL A,VAR2 HAI LD SUB #8h,B; #1h,B;

www.jprnotes.blogspot.com49

LD VAR2,A AND #0001h,A STL A,*AR1+ LD VAR2,B SFTA B,-1 STL B,VAR2 BC HAI,BNEQ;

;-------------------------------------------------------------------------------------------------------STM #1650h,AR1 STM #1700h,AR2 ;OUTPUT STM #1658h,AR5 LD #8h,B L5 LD *AR1+,A BC ZERO,AEQ

ONE

STM #1600h,AR3 RPT #7 MVDD *AR3+,*AR2+ B STAT STM #1610h,AR4 RPT #7 MVDD *AR4+,*AR2+

ZERO

STAT

## SUB #1h,B BC L5,BGT PORTW B WAIT VAR,0h

www.jprnotes.blogspot.com50