RAJALAKSHMI ENGINEERING COLLEGE THANDALAM, CHENNAI- 602105
Department of Electronics and Communication Engineering
EC1306 - DIGITAL SIGNAL PROCESSING LABORATORY MANUAL PREPARED BY A.ASHA (2008 – 2009)
EC1306
DIGITAL SIGNAL PROCESSING LAB
USING TMS320C5X 1. Study of various addressing modes of DSP using simple programming examples 2. Sampling of input signal and display 3. Implementation of FIR filter 4. Calculation of FFT USING MATLAB 1. Generation of Signals 2. Linear and circular convolution of two sequences 3. Sampling and effect of aliasing 4. Design of FIR filters 5. Design of IIR filters 6. Calculation of FFT of a signal
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) % - 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); 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’);
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); plot(w/pi, abs(Yz)); grid xlabel(’\omega/\pi’); ylabel(’Magnitude’); title(’Output Spectrum’);
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-->');
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; 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....>'); 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
con1 con2 con3 con4 con5 con6 fs fm pi ms mx CNT
start
.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
;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations----------------------------
SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD
;SPCR1 reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM RCR2,McBSP0_SPSA ;RCR2 STM #0001h,McBSP0_SPSD STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCR2
STM SRGR1,McBSP0_SPSA ;SRGR1 STM #000Bh,McBSP0_SPSD ;--17 STM STM
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM STM
XCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCERB
STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
STM STM
SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD
;XCERA
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;--------------------------McBSP1 Initializations-----------------------------STM STM
SPCR1,McBSP1_SPSA #0090h,McBSP1_SPSD
;SPCR1 reset
STM STM
SPCR2,McBSP1_SPSA #0020h,McBSP1_SPSD
;SPCR2 reset
STM STM
PCR,McBSP1_SPSA ;PCR #0A00h,McBSP1_SPSD
STM STM
RCR1,McBSP1_SPSA #00A0h,McBSP1_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP1_SPSA #0000h,McBSP1_SPSD
;RCR2
STM STM
XCR1,McBSP1_SPSA #00A0h,McBSP1_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP1_SPSA #0000h,McBSP1_SPSD
;XCR2
STM STM
SRGR1,McBSP1_SPSA #0002h,McBSP1_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP1_SPSA #303Bh,McBSP1_SPSD
;SRGR2
STM
MCR1,McBSP1_SPSA
;MCR1
NOP NOP
STM
#0001h,McBSP1_SPSD
STM STM
MCR2,McBSP1_SPSA #0000h,McBSP1_SPSD
STM STM
RCERB,McBSP1_SPSA #0001h,McBSP1_SPSD
;RCERB
STM RCERA,McBSP1_SPSA STM #0001h,McBSP1_SPSD
;RCERA
;MCR2
STM STM
XCERB,McBSP1_SPSA #0001h,McBSP1_SPSD
;XCERB
STM STM
XCERA,McBSP1_SPSA #0001h,McBSP1_SPSD
;XCERA
STM STM
SPCR1,McBSP1_SPSA #0091h,McBSP1_SPSD
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP1_SPSA #00A1h,McBSP1_SPSD
;--------------------End of Serial Ports Initializations----------------------RSBX
INTM
LD #02Fh,0,A STLM A,IMR STM STM
#0h,McBSP0_DXR1 #0h,McBSP0_DXR2
STM STM
#0007h,GPIOCR #0003h,GPIOSR
STM STM
#SPCR2,McBSP1_SPSA #00E1h,McBSP1_SPSD
NOP STM
#0007h,GPIOSR
STM
;Mclk
#SPCR2,McBSP0_SPSA
STM
#00E1h,McBSP0_SPSD
;Sclk & Fs
;---------------------------------------------------------------------------STM #256,BK STM #2000h,AR5 SSBX SXM
WAIT
NOP NOP LD CNT,A BC WAVE,AEQ NOP B WAIT
_XINT0_ISR LD
*AR5+%,A
STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 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
;o/p for R Channel ;o/p for L Channel
;COSINE APPROX 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 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 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
wave1
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
2. Square wave generation ;Starting address : 1000h
;Output address :2000h .include "5416_iv.asm" .def start .data .word 30 ;Positive Count value .word 30 ;Negative Count Value .word 0 ;Dummy 1 .word 0 ;Dummy 2 .word 07fffh,08001h ;Maximum Positive and Negative Values .word 128 ;Total No.of Samples .word 45h ;Display Character 'E' .text
POS NEG P N CNT E start
LD ;
#POS,DP Data Page Pointer RSBX INTM LD #022Bh,0,A STLM A,PMST
;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD
;SPCR1 reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCR2
STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;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
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
STM STM
SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD
;XCERB
;XCERA
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations-----------------------------STM STM
SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD
;SPCR1 reset
STM
SPCR2,McBSP2_SPSA
;SPCR2 reset
NOP NOP
NOP NOP
STM
#0020h,McBSP2_SPSD
STM STM
PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD
STM STM
RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;RCR2
STM STM
XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;XCR2
STM STM
SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD
;SRGR2
STM STM
MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD
;MCR1
STM STM
MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;MCR2
STM STM
RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERB
STM STM
RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERA
STM STM
XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERB
STM STM
XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERA
STM STM
SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD
;Take 'em out of reset
STM STM
SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD
;--------------------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
STM STM
#SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD
NOP STM
#0007h,GPIOSR
STM STM
#SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD
;Mclk
;Sclk & Fs
;---------------------------------------------------------------------------;--------------------------Square Wave Generation Program------------------;--------------------------Initialisation------------------------------------------------------STM #128,BK SSBX SXM STM STM STM
WAIT
#1504h,AR2 ;Memory location of 7fffh #1505h,AR3 ;Memory location of 8001h #2000h,AR4 ;Square Wave Output
NOP NOP LD CNT,B BC WAVE,BEQ
;Jump to WAVE if Count Equals to zero
NOP B WAIT
_XINT0_ISR NOP NOP LD
*AR4+%,A
;Transmitting Square Wave Output to
CODEC STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 LD CNT,B SUB #1h,B STL B,CNT
;Count=Count-1
RETE
WAVE
LD #128,A STL A,CNT
;Initialization of Count Value (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
POS,A A,P NEG,B B,N
;Loop for 128 Samples
L2
LD *AR2,A STL A,*AR4+
;Positive Loop (30 Samples)
LD P,B SUB #1h,B STL B,P BC L2,BNEQ L3
LD *AR3,A STL A,*AR4+
;Negative Loop (30 Samples)
LD N,B SUB #1,B STL B,N BC L3,BNEQ L1
NOP NOP
LD #027h,A STLM A,IMR STM #2000h,AR4
;Initialization of Interrupts ;Interrupt Mask Register ;Output Memory
B
;Branch to Wait Loop
WAIT
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 LD #022Bh,0,A STLM A,PMST
;Variable Declaration
;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD
;SPCR1 reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCR2
STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCR2
STM STM
SRGR1,McBSP0_SPSA #000Bh,McBSP0_SPSD
;SRGR1 ;--17
STM STM
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM STM
XCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCERB
STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCERA
STM STM
SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations-----------------------------STM STM
SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD
;SPCR1 reset
STM STM
SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD
;SPCR2 reset
STM STM
PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD
STM STM
RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;RCR2
STM STM
XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;XCR1 ;32 BITS WORDSIZE
NOP NOP
STM STM
XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;XCR2
STM STM
SRGR1,McBSP2_SPSA #0002h,McBSP2_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD
;SRGR2
STM STM
MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD
;MCR1
STM STM
MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;MCR2
STM STM
RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERB
STM STM
RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERA
STM STM
XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERB
STM STM
XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERA
STM STM
SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD
;--------------------End of Serial Ports Initializations----------------------RSBX
INTM
LD #02Fh,0,A STLM A,IMR STM STM
#0h,McBSP0_DXR1 #0h,McBSP0_DXR2
STM STM
#0007h,GPIOCR #0003h,GPIOSR
STM STM
#SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD
NOP STM
#0007h,GPIOSR
STM STM
#SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD
;Mclk
;Sclk & Fs
;---------------------------------------------------------------------------;----------------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
;Circular Buffer for Input and Output ;Input Buffer Starts at 1600h ;Output Buffer Starts at 1700h
LD #0h,A STM #1900h,AR3 RPT #10
;Temporary Buffer Initialization
STL A,*AR3+ STM #1900h,AR3
WAIT
NOP NOP B WAIT
_XINT0_ISR LDM
McBSP0_DRR1,A
;R Channel (Input Sample From
CODEC) STL
A,0,*AR5
;Loading Input Sample to an Input Buffer
(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
;Initialization of Temporary Buffer ;Moving Input Sample from Input buffer ;Modify Temporary buffer ;Implementation of FIR Filter
SFTA A,-15 STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2
;Shifting the output to Lower order ;o/p for R Channel ;o/p for L Channel
STL A,0,*AR6+% MAR *AR5+% RETE
;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
bpole azero xin xout yin S1 E
.data .word .word .word .word .word .word .word
97e3h,154fh 0b4ch,1698h,0b4ch 0,0 0 0 00 45h
;IIR Filter Co-efficients
.text start
LD #bpole,DP RSBX INTM LD #022Bh,0,A STLM A,PMST
;Variable Declaration
;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD
;SPCR1 reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCR2
STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCR2
STM
SRGR1,McBSP0_SPSA
;SRGR1
STM
#000Bh,McBSP0_SPSD
;--17
STM STM
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM STM
XCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCERB
STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;XCERA
STM STM
SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations-----------------------------STM STM
SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD
;SPCR1 reset
STM STM
SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD
;SPCR2 reset
STM STM
PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD
NOP NOP
STM STM
RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;RCR2
STM STM
XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;XCR2
STM STM
SRGR1,McBSP2_SPSA #0002h,McBSP2_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD
;SRGR2
STM STM
MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD
;MCR1
STM STM
MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;MCR2
STM STM
RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERB
STM STM
RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERA
STM STM
XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERB
STM STM
XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERA
STM STM
SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD
NOP NOP STM STM
SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD
;Take 'em out of reset
;--------------------End of Serial Ports Initializations----------------------RSBX
INTM
LD #02Fh,0,A STLM A,IMR STM STM
#0h,McBSP0_DXR1 #0h,McBSP0_DXR2
STM STM
#0007h,GPIOCR #0003h,GPIOSR
STM STM
#SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD
NOP STM
#0007h,GPIOSR
STM STM
#SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD
;Mclk
;Sclk & Fs
SSBX SXM RSBX FRCT RSBX OVM STM STM STM STM STM
WAIT
_XINT0_ISR
#128,BK #1600h,AR4 #1700h,AR1 #1400h,AR5 #1500h,AR6
NOP NOP NOP NOP NOP B WAIT
;Circular Buffer for Input and Output ;Input Buffer Starts at 1600h ;Output Buffer Starts at 1700h ;IIR Filter Output ;Zero Output Buffer
LDM LDM
McBSP0_DRR1,A McBSP0_DRR2,A
STM STM
#1800h,AR3 #1300h,AR7
;R Channel (Input Sample From CODEC) ;R Channel (Input Sample From CODEC) ;Pole Temporary Buffer ;Pole Output Buffer
STL A,0,xin NOP NOP LD xin,A STL A,0,*AR4+% NOP NOP STM
xout,AR2
RPT #02h MACD *AR2-,azero,A
;Multiplication of Input with zeros
SFTA A,-15 STL A,0,*AR6
;Zero Output
MVDD *AR5,*AR3+ LD #bpole,DP
;Transfer IIR Output to Temp Buffer
RPT #01h MACD *AR3-,bpole,A SFTA STL NOP NOP LD LD SUB STL
*AR6,A *AR7,B B,0,A A,0,*AR5
STL
A,0,*AR1+%
;Multiplication of Output with Poles
A,-15 A,0,*AR7
;Pole Output
;Zero Output - Pole Output
STLM A,McBSP0_DXR1
;o/p for R Channel
STLM A,McBSP0_DXR2 RETE 5. FFT DESIGN
;o/p for L Channel
;Starting address: 0700h ;Input address: 1000h ;Output address: 1800h
R1 I1 stages grp grp1 but but1 R I A1 sizetw sizein bitr shi CNT E start
.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
;------------------------Serial Port Initializations------------------------;--------------------------McBSP0 Initializations---------------------------SSBX INTM STM SPCR1,McBSP0_SPSA STM #0090h,McBSP0_SPSD NOP
;SPCR1 reset
NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCR2
STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;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
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
STM
SPCR1,McBSP0_SPSA
;XCERB
;XCERA
STM
#0091h,McBSP0_SPSD
;Take 'em out of reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;--------------------------McBSP2 Initializations-----------------------------STM STM
SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD
;SPCR1 reset
STM STM
SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD
;SPCR2 reset
STM STM
PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD
STM STM
RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;RCR2
STM STM
XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;XCR2
STM STM
SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD
;SRGR2
STM STM
MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD
;MCR1
STM STM
MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;MCR2
NOP NOP
STM STM
RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERB
STM STM
RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERA
STM STM
XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERB
STM STM
XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERA
STM STM
SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD
STM STM
SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD
;Take 'em out of reset
NOP NOP
;--------------------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
STM STM
#SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD
NOP STM
#0007h,GPIOSR
STM STM
#SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD
;Mclk
;Sclk & Fs
;----------------------------------------------------------------------------
;-----------------------------Program Starts---------------------STM STM
#1000h,AR6 ;FFT I/p #1800h,AR1 ;FFT O/p
SSBX SXM RSBX OVM LD #0h,0,A RPT #127 STL A,*AR1+ STM #1800h,AR1 STM
WAIT
#3500h,AR7
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
;o/p for R Channel ;o/p for L Channel
POPM BL POPM AG POPM AH POPM AL RETE
FFT
NOP NOP LD #0,A STLM A,IMR STM STM
#1000h,AR6 #1800h,AR1
STM STM
#2000h,AR4 #1000h,AR3
RPT #127 MVDD *AR4+,*AR3+ LD
#R1,DP
NOP LD STL NOP
#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
;Bit Reversal
NOP 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 LD STL STL
*AR5,0,A *AR2,0,B A,0,R B,0,I
LD but,0,A STLM A,AR0 NOP NOP MAR *AR5+0% MAR *AR2+0% MPY MPY SUB STH
*AR3,*AR5,A *AR4,*AR2,B B,0,A A,R1
MPY MPY ADD STH
*AR3,*AR2,A *AR4,*AR5,B A,0,B B,I1
LD LD SUB STL
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 LD
R,-1,A R1,0,B
ADD B,0,A STL A,*AR5+ 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
LD but,0,B SFTA B,1
;;;;;;;;Group End
STL B,but STL B,but1 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
LD LD
;;;;;;;;;STAGES
#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
VE
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 LD #0017h,A STLM A,IMR NOP
NOP B 6. FSK DESIGN
WAIT
;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
CNT VAR VAR2
.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
;SPCR1 reset
NOP NOP STM STM
SPCR2,McBSP0_SPSA #0020h,McBSP0_SPSD
;SPCR2 reset
STM STM
PCR,McBSP0_SPSA ;PCR #0A00h,McBSP0_SPSD
STM STM
RCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCR2
STM STM
XCR1,McBSP0_SPSA #00A0h,McBSP0_SPSD
;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
SRGR2,McBSP0_SPSA #303Fh,McBSP0_SPSD
;SRGR2
STM STM
MCR1,McBSP0_SPSA #0001h,McBSP0_SPSD
;MCR1
STM STM
MCR2,McBSP0_SPSA #0000h,McBSP0_SPSD
;MCR2
STM STM
RCERB,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERB
STM STM
RCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
;RCERA
STM XCERB,McBSP0_SPSA STM #0001h,McBSP0_SPSD STM STM
XCERA,McBSP0_SPSA #0001h,McBSP0_SPSD
STM STM
SPCR1,McBSP0_SPSA #0091h,McBSP0_SPSD
NOP NOP STM STM
SPCR2,McBSP0_SPSA #00A1h,McBSP0_SPSD
;XCERB
;XCERA
;Take 'em out of reset
;--------------------------McBSP2 Initializations-----------------------------STM STM
SPCR1,McBSP2_SPSA #0090h,McBSP2_SPSD
;SPCR1 reset
STM STM
SPCR2,McBSP2_SPSA #0020h,McBSP2_SPSD
;SPCR2 reset
STM STM
PCR,McBSP2_SPSA ;PCR #0A00h,McBSP2_SPSD
STM STM
RCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;RCR1 ;32 BITS WORDSIZE
STM STM
RCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;RCR2
STM STM
XCR1,McBSP2_SPSA #00A0h,McBSP2_SPSD
;XCR1 ;32 BITS WORDSIZE
STM STM
XCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;XCR2
STM STM
SRGR1,McBSP2_SPSA #0005h,McBSP2_SPSD
;SRGR1 ;--5
STM STM
SRGR2,McBSP2_SPSA #303Bh,McBSP2_SPSD
;SRGR2
STM STM
MCR1,McBSP2_SPSA #0001h,McBSP2_SPSD
;MCR1
STM STM
MCR2,McBSP2_SPSA #0000h,McBSP2_SPSD
;MCR2
STM STM
RCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERB
STM STM
RCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
;RCERA
STM STM
XCERB,McBSP2_SPSA #0001h,McBSP2_SPSD
;XCERB
NOP NOP
STM STM
XCERA,McBSP2_SPSA #0001h,McBSP2_SPSD
STM STM
SPCR1,McBSP2_SPSA #0091h,McBSP2_SPSD
STM STM
SPCR2,McBSP2_SPSA #00A1h,McBSP2_SPSD
;XCERA
;Take 'em out of reset
NOP NOP
;--------------------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
STM STM
#SPCR2,McBSP2_SPSA #00E1h,McBSP2_SPSD
NOP STM
#0007h,GPIOSR
STM STM
#SPCR2,McBSP0_SPSA #00E1h,McBSP0_SPSD
;Mclk
;Sclk & Fs
;---------------------------------------------------------------------------STM #64,BK STM #1700h,AR6 STM #1650h,AR7 LD #0h,A RPT #1000h STL A,*AR7+ STM #1650h,AR7
WAIT
NOP NOP NOP LD CNT,A BC FSK,AEQ NOP NOP B WAIT
_XINT0_ISR LDM LDM
McBSP0_DRR1,A McBSP0_DRR2,A
;R Channel ;L Channel
PORTR 0h,VAR LD *AR6+%,A STLM A,McBSP0_DXR1 STLM A,McBSP0_DXR2 LD SUB STL
;o/p for R Channel ;current(Y) ;o/p for L Channel ;voltage(R)
CNT,A #1h,A A,CNT
RETE FSK
LD STL
#40h,A A,CNT
STM STM STM STM
#1650h,AR1 #1700h,AR2 ;OUTPUT #1600h,AR3 ;1000Hz #1610h,AR4 ;2000Hz
LD VAR,A AND #00FFh,A NOP NOP STL A,VAR STL A,VAR2
HAI
LD SUB
#8h,B; #1h,B;
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
ZERO
STM #1610h,AR4 RPT #7 MVDD *AR4+,*AR2+
STAT
SUB #1h,B BC L5,BGT PORTW B
WAIT
VAR,0h