Forums

VC33 comms error

Started by hariunnik June 1, 2005
hi all,
im trying to do a realtime adaptive noise cancellation with Vc33
university DSK. I got a simple loopback program (posted by

keith larson) from this group to start with and im trying to make my
program working based on that loopback program. It uses

2 interupts- Txn interrupt and Rxv interrup. But im using only
TRANSMIT interrupt for my adaptive noise program. though i

tried the one-interrupt loopback code running successfully im
getting a communication error when im trying to run the

adaptive filter code. i tried my program in single step and found
that when it reaches GIE bit enable code in MAIN it digs up

some communication error. but single-step on the original program
works well. im using dsk3dw assembler for this. im using

left channel for noise i/p and right channel for (signal+noise)
input and sending output thru' both channels.
your help is much appreciated.
Thanx a lot.
hari.

; **********************************************

.start "adapt",0x809802 ; start assembling here in a safe
place

.start ".data",0x809A00 ;where data begins

.data ;assemble into data section

GIE .set 2000h ; This bit in ST turns on interrupts
LRCIN .word 80A000h ; LRCIN is bit 4 of this location
S0_rst .word 2BF3000h
S0_run .word 0xEBF3000
ADC_R .word 0h
ADC_L .word 0h
OUTDAT .word 0h

NOISE_ADDR .word NOISE+LENGTH-1 ;last address of noise samples
WN_ADDR .word COEFF ;address of coefficients w(N-1)
ERF_ADDR .word ERR_FUNC ;address of error function
ERR_FUNC .float 0 ;initialize error function
BETA .float 2.5E-20 ;rate of adaptation constant
LENGTH .set 50 ;set filter length
COEFF: ;buffer for coefficients
.loop LENGTH ;loop length times
.float 0 ;init coefficients to zero
.endloop ;end of loop
.brstart "XN_BUFF",128 ;align buffer for noise
samples
NOISE .sect "XN_BUFF" ;section for input noise
samples
.loop LENGTH ;loop length times
.float 0 ;initialize noise samples
.endloop ;end of loop .entry START ; on starting program go to this point

.sect "adapt"
START ldp @START
ldi @stack,SP ; setup the stack

LDI @ERF_ADDR,AR6 ;error function
address ->AR6
LDI LENGTH,BK ;filter
length ->BK
LDI @WN_ADDR,AR0 ;coefficient addrs w(N-
1) ->AR0
LDI @NOISE_ADDR,AR1 ;last noise sample
addrs ->AR1

call AICINIT ; sets up the DSK.
or 14h,IE ; Enable the XINT INT2

;---ENEABLE INTERRUPT ----------

main or GIE,ST ; Turn on INTS
idle ; wait for interrupt
andn GIE,ST ; Turn off INTS
br main ; endless loop
; ***********************************
; * Interrupt Service Routine *
; ***********************************

XINT0 push ST ; Interrupt service routine
push R0 ; save fp significance
pushf R0 ;
; push AR7 ;

ldi @LRCIN,AR7 ;
ldi *AR7,R0 ;
and 10h,R0

;*************** this isolates the LRCIN bit ******

bnz lft
ldi @OUTDAT,R0
br shift
lft ldi @OUTDAT,R0

shift lsh -12,R0
sti R0,@S0_xdata

******** RECEIVE DATA HERE **********************

and 0h,R0 ;clear R0
ldi @LRCIN,AR7 ;
ldi *AR7,R0 ;

; Sample the LRCIN bit, and then store the data in the right place

and 10h,R0 ; isolated the LRCIN bit
bnz left

right ldi @S0_rdata,R0
float R0,R6 ; R6 for RCHN "signal+noise" (d+n)
br fin_int

left ldi @S0_rdata,R0
float R0,R7 ; R7 for LCHN "noise" (n)

fin_int ;####################################################################

STF R7,*AR1++% ;store noise sample-> circ
buffer

LDI @WN_ADDR,AR0 ;w(N-1) coefficients address-
>AR0
FILT LDF 0,R2 ;R2 = 0
RPTS LENGTH-1 ;next 2 instr (LENGTH-1) times
MPYF3 *AR0++,*AR1++%,R0 ;w(N-1-i)*x(n-(N-1-i))
|| ADDF3 R0,R2,R2 ;accumulate
ADDF3 R0,R2,R0 ;add last product=y(n) -> R0

; CALL IOPRI ;signal+noise d+n from pri
input

LDF R6,R4 ;R4= d+n in floating-
point
SUBF3 R0,R4,R0 ;error e => R0 = (d+n)-y

FIX R0,R5 ;R5=R0 in integer
STI R5,@OUTDAT ;OUTPUT DATA

MPYF @BETA,R0 ;R0=ERR FUNCta*e
STF R0,*AR6 ;store error function
LDI LENGTH-2,RC ;set repeat counter register RC
LDI @WN_ADDR,AR0 ;w(N-1) coefficients address-
>AR0

;************** ADAPTATION ROUTINE *****************

ADAPT MPYF3 *AR6,*AR1++%,R0 ;error function*x(n-(N-1))->R0
LDF *AR0,R3 ;w(N-1) -> R3
RPTB LOOP_END ;repeat length-2 times
MPYF3 *AR6,*AR1++%,R0 ;error function*x(n-(N-1-i))-
>R0
|| ADDF3 R3,R0,R2 ;w(N-1-i)+error func*x(n-(N-1-
i))
LOOP_END LDF *+AR0(1),R3 ;load subsequent w(k) -> R3
|| STF R2,*AR0++ ;store/update coefficient
ADDF3 R3,R0,R2 ;w(n+1)=w(n)+error function*x
(n)
STF R2,*AR0 ;store/update coefficient

;####################################################################
#####

; pop AR7 ;
popf R0 ;
pop R0 ; restore significance
pop ST ;
reti

; **************************************************
; * CODE TO INITIALISE THE TIMER AND SERIAL PORTS. *
; **************************************************
; params for aic PCM3003 initialization ;
; *****************************************************;

T0_ctrl .set 808020h ; TIM0 gl control
T0_count .set 808024h ; TIM0 count
T0_prd .set 808028h ; TIM0 prd
T1_ctrl .set 808030h ; TIM1 gl control
T1_count .set 808034h ; TIM1 count
T1_prd .set 808038h ; TIM1 prd
S0_gctrl .set 808040h ; SP 0 global control
S0_xctrl .set 808042h ; SP 0 FSX/DX/CLKX port ctl
S0_rctrl .set 808043h ; SP 0 FSR/DR/CLKR port ctl
S0_xdata .set 808048h ; SP 0 Data transmit
S0_rdata .set 80804Ch ; SP 0 Data receive
TIM0_PRD .set 2 ; Timer diviser
;S0_gctrl_val .word 0E970300h ; Serial port control register values
S0_xctrl_val .word 00000111h ;
S0_rctrl_val .word 00000111h ;

;--------------------------------
XCLKSRCE .set 0 << 6 ; 0=external 1= internal
RCLKSRCE .set 0 << 7 ;
XVAREN .set 0 << 8 ; VAREN 0 1
RVAREN .set 0 << 9 ; FS ____---------_____
XFSM .set 0 <<10 ; 0=burst 1=continuous
RFSM .set 0 <<11 ;
CLKXP .set 1 <<12 ;
CLKRP .set 1 <<13 ;
DXP .set 0 <<14 ;
DRP .set 0 <<15 ;
FSXP .set 1 <<16 ;
FSRP .set 1 <<17 ;
XLEN .set 11b<<18 ; 00=8 01 10$ 112
RLEN .set 11b<<20 ;
EXTINT .set 0 <<22 ;
EXINT .set 1 <<23 ;transmit interrupt enable
ERTINT .set 0 <<24 ;
ERINT .set 0 <<25 ;receive interrupt enable/disable
S0 .sdef
XCLKSRCE|RCLKSRCE|XVAREN|RVAREN|XFSM|RFSM|CLKXP|CLKRP
S0 .sdef S0|DXP|DRP|FSXP|FSRP|EXTINT|EXINT|ERTINT|ERINT
SPBITS .set 32
BITSEL .set ((SPBITS/8)-1) ; 0=8, 1, 2$ and 32 bits
S0 .sdef S0|(BITSEL<<18)|(BITSEL<<20)
S0gctrl_rst .word S0
S0gctrl_run .word S0|0C000000h
S0xctrl .set 00000111h
S0rctrl .set 00000111h
S0cpld .word 80A000h; CPLD status byte contains LRCIN

;====================================================================

AICINIT:
ldi 00h,R0 ; halt the timer
sti R0,@T0_ctrl
ldi 03h, R0 ; put a count in prd
sti R0,@T0_prd
ldi 283h,R0 ; set bits to start timer
sti R0,@T0_ctrl ; timer is now running!
ldi 0,R0 ;
sti R0,@T0_count ; T0_count = 0
;------------------------------

ldi S0xctrl,R0 ; Init xmit/recv pin control
sti R0,@S0_xctrl ; S0_xctrl = S0xctrl

;----------- transmit control -----------------------------

ldi S0rctrl,R0 ;
sti R0,@S0_rctrl ; S0_rctrl = S0rctrl

;----------- receive control -----------------------------

ldi @S0gctrl_rst,R0 ; Reset serial port
sti R0,@S0_gctrl ; S0_gctrl = S0gctrl_rst
ldi @S0gctrl_run,R0 ; Run serial port
sti R0,@S0_gctrl ; S0_gctrl = S0gctrl_run
ldi 0,R0 ;
sti R0,@S0_rdata ;
sti R0,@ADC_L ;
sti R0,@ADC_R ;
rets ; return from subroutine

; *****************************
; * STACK *
; *****************************

stack .word $+1 ; the word at stack is the address of the
next cell

.start "int_vects", 0x809FC5 ; here's where the XINT0
vector is
.sect "int_vects" ; name the section something

br XINT0

.end