?? fir5402.asm
字號:
.title "fir5402.asm"
.ref _c_int00
.mmregs
;---------------------------------
;寄存器地址設置
;--------------------------------
gpiocr .set 3ch
gpiosr .set 3dh
dxr10 .set 23h
drr10 .set 21h
spsa0 .set 38h
spcr10 .set 39h
spcr20 .set 39h
xcr10 .set 39h
pcr0 .set 39h
dxr11 .set 43h
spsa1 .set 48h
spcr11 .set 49h
spcr21 .set 49h
xcr11 .set 49h
pcr1 .set 49h
srgr1 .set 49h
srgr2 .set 49h
swcr .set 2bh
;----------------------------
;定義變量
;----------------------------
timer_count .set 060h
mcbsp_init .set 061h
wave_ptr .set 062h
is_new_data .set 063h
new_ad .set 064h
out_wave_ptr .set 065h
t_ar2 .set 066h
t_ar3 .set 067h
temp .set 068h
wave_buf .set 0900h
out_wave_buf .set 01000h
N .set 38 ; FIR taps
fir_coef_buf .set 100h ; FIR coef buffer
fir_data .set 200h ; FIR windows data buffer !
.text
;----------------------------
;中斷向量
;----------------------------
rs b _c_int00
nop
nop
nmi b _ret
nop
nop
sint17 b _ret
nop
nop
sint18 b _ret
nop
nop
sint19 b _ret
nop
nop
sint20 b _ret
.word 0,0
sint21 b _ret
.word 0,0
sint22 .word 01000h
.word 0,0,0
sint23 .word 0ff80h
.word 0,0,0
sint24 .word 01000h
.word 0,0,0
sint25 .word 0ff80h
.word 0,0,0
sint26 .word 01000h
.word 0,0,0
sint27 .word 0ff80h
.word 0,0,0
sint28 .word 01000h
.word 0,0,0
sint29 .word 0ff80h
.word 0,0,0
sint30 .word 01000h
.word 0,0,0
int0 b _ret
nop
nop
int1 b _ret
nop
nop
int2 b _ret
nop
nop
tint b timer ;內部定時中斷
nop
nop
brint0 b receive ;緩沖串口接受中斷
nop
nop
bxint0 b transmit ;緩沖串口發送中斷
nop
nop
trint b _ret
nop
nop
txint b _ret
nop
nop
int3 b _ret
nop
nop
hpint b _ret
nop
nop
q26 .word 0ff80h
.word 0,0,0
q27 .word 01000h
.word 0,0,0
q28 .word 0ff80h
.word 0,0,0
q29 .word 01000h
.word 0,0,0
q30 .word 0ff80h
.word 0,0,0
q31 .word 01000h
.word 0,0,0
;--------------------------
;復位中斷服務程序
;--------------------------
_c_int00:
stm #2020h,pmst ;vector table start:0x2000
ssbx intm ; close all int ! (ssbx intm)
ssbx sxm ; extend sign !
ssbx frct ; faction multiply
stm #10h,26h ; stop TIMER0 !
stm #10h,36h ; stop TIMER1 !
stm #0ffh,sp ; sp= 0x0ff
ld #0,dp ; dp=0
stm #8020h,pmst ; vector table start: 0x8000(0x38000)
stm #0ffffh,ifr ; clear all int !
stm #20h,imr ; bit5->BXINT0, bit4->BRINT0, enable BXINT0
stm #02492h,swwsr ; all 2 waits !
stm #0,swcr
;----------------------------
;配置DSP的時鐘
;----------------------------
stm #0,58h
wait_pll:
ldm 58h,a
and #1,a
bc wait_pll,aneq
stm #97ffh,58h ; switch pll*10 -> 100M clk
rpt #100
nop
;----------------------------
;初始化RAM,Variable....
;----------------------------
stm #wave_buf,ar6
stm #1,ar0
rpt #24
mvpd wave_data,*ar6+0 ; move wave data to wave_buf -> 0x6000h
stm #wave_buf,wave_ptr ; save wave buffer'ptr
stm #out_wave_buf,out_wave_ptr ; save out wave buffer'ptr, because use
; circular address, so when save out_wave
; date,must ++ !
stm #fir_coef_buf,ar6
rpt #N-1
mvpd fir_coef,*ar6+ ; move fir coef to fir_coef_buf(in data mem)
stm #fir_coef_buf,t_ar2
stm #fir_data,t_ar3
stm #0aa55h,mcbsp_init ; when mcbsp_init==0xaa55, transmit for init ac01
stm #5,timer_count ; init variable timer_count !
stm #0,is_new_data ; if is_new_data ==1 , has new AD data by slave ac01 !
stm #1000h,ar0
stm #1800h,ar5
stm #400h,bk
ld *ar0,t
ld #0,b
;-----------------------------
;初始化McBSP0
;-----------------------------
stm #0,spsa0 ; choose SPCR10
stm #2000h,spcr10 ; receive sign_extend in DRR
stm #1,spsa0 ; choose SPCR20
stm #0c0h,spcr20 ; fs -> int !
stm #2,spsa0 ; choose RCR10
stm #40h,39h
stm #3,spsa0 ; choose RCR20
stm #0,39h
stm #4,spsa0 ; choose XCR10
stm #40h,xcr10
stm #5,spsa0 ; choose XCR20
stm #0,39h
stm #0eh,spsa0 ; choose PCR0
stm #0dh,pcr0 ; fs is low active, rise edge of clkx, falling edge
; of clkr
stm #7h,spsa0
stm #8000h,39h
rpt #0ffffh
nop
stm #00h,dxr10
ldm 22h,a
stm #1,38h
stm #0c1h,39h ; start McBSP0 send !
ld #603h,a
rsbx intm ; enable all int !
;-----------------------------
;初始化AC01
;-----------------------------
idle 1
idle 1
idle 1
idle 1 ; reset two AC01 by software !
ld #600h,a
idle 1 ; wait for int .....
ld #3,a
idle 1 ; send #3
ld #00105h,a ; fs=10M/2/A/B= 25k
; flp=10M/2/40/A= 25k (all pass)
; fhp=fs/200= 125Hz (not use !)
; A=05,B=40(0x28)
idle 1 ; send 1th regs -> 05h
ld #3,a
idle 1 ; send #3
ld #00228h,a
idle 1 ; send 2th regs -> 28h
ld #3,a
idle 1 ; send #3
ld #00300h,a
idle 1 ; send 3th regs -> 00h
ld #3,a
idle 1 ; send #3
ld #00405h,a
idle 1 ; send 4th regs -> 05h (AD & DA 0 dB)
ld #3,a
idle 1 ; send #3
ld #00505h,a
idle 1 ; send 5th regs -> 05h (highpass filter disable)
ld #3,a
idle 1 ; send #3
ld #00600h,a
idle 1 ; send 6th regs -> 00h
ld #3,a
idle 1 ; send #3
ld #00700h,a
idle 1 ; send 7th regs -> 0
ld #3,a
idle 1 ; send #3
ld #800h,a
idle 1 ; send 8th regs -> 0
ld #0h,a
stm #0,38h
stm #2001h,39h ; start MCbsp0 receive !
stm #30h,imr ; bit5->BXINT0, bit4->BRINT0, enable BXINT0
;---------------------------------
;初始化TIMER@@@@@@@@
;---------------------------------
period .set 65535
.asg ar1,counter
stm #timer_count,counter
stm #10h,tcr ; 停止計數器
stm #period,tim
stm #period,prd ;65535=>prd 定義計數周期
stm #0fh,tcr ;15=>TDDR 定時器的中斷周期=10ns*16*65536=10s TIMER start, each about 100MHZ
stm #0008h,imr ; 開TIME0中斷
; rsbx intm
;----------------------------------
;主程序
;----------------------------------
main:
bitf is_new_data,#1 ; test is_new_data == 1 ?
cc fir,tc ; ==1, then call fir ! new AD data in new_ad(0x64)
b main
;------------------------------------
;緩沖串口發送中斷服務程序(McBSP0發送)
;------------------------------------
transmit:
pshm st1
pshm st0
pshm bk
pshm ar7
pshm ah
pshm al
cmpm mcbsp_init,#0aa55h
bc init,tc
stm #25,bk ; each AC01 has 25 dots to D/A !
mvdm #wave_ptr,ar7 ; restore wave buffer ptr !
nop
ld *ar7+%,a
nop
stlm a,dxr10 ; send wave data ! Master AC01 make source wave,
; Slave AC01 make filter result wave !
bd wave_make_end
mvmd ar7,#wave_ptr ; save wave buffer ptr !
init:
stlm a,dxr10
bitf dxr10,#800h ; if setup last reg of AC01, set mcbsp_init=0 !
bc wave_make_end,ntc ; not equal ,jump !
stm #0,mcbsp_init ; when mcbsp==0 or 1, transmit for make wave !
wave_make_end:
popm al
popm ah
popm ar7
popm bk
popm st0
popm st1
_ret:
rete
;------------------------------------
;緩沖串口接收中斷服務程序(McBSP0接收)
;------------------------------------
receive:
pshm st1
pshm st0
ld #0,dp
mvkd drr10,*ar5 ;save AD data
pshd *ar5+%
popd new_ad
stm #1,is_new_data ;has new AD data
end_receive:
popm st0
popm st1
rete
;---------------------------------
;定時中斷TIMER
;---------------------------------
timer: pshm ah
pshm al
banz next,*counter-
stm #timer_count,counter
bitf *ar2,#1
bc restxf,tc
setxf: ssbx xf
st #1,*ar2
b next
restxf: rsbx xf
st #0,*ar2
next:
popm al
popm ah
rete
;------------------------------
; FIR濾波
;------------------------------
fir:
pshm st1
pshm st0
pshm bk
pshm ar7
pshm ah
pshm al
pshm ar0
pshm ar2
pshm ar3
mvdm #t_ar2,ar2 ; restore ar2
mvdm #t_ar3,ar3 ; restore ar3
ld new_ad,-2,a ; new AD data -> a, remove two LSBs
stm #1,ar0
stm #N,bk ; 循環緩沖區長度
stl a,*ar3+%
rptz a,#(N-1) ; a=0,下條指令執行N(38)次
mac *ar2+0%,*ar3+0%,a ; done FIR filter, result in a h
mvmd ar3,#t_ar3 ; save ar3
mvmd ar2,#t_ar2 ; save ar2
stm #2,ar0
stm #100H,bk ; each AC01 has 25 dots to D/A !
mvdm #out_wave_ptr,ar7 ; restore wave buffer ptr !
sth a,-2,temp ; save FIR result in temp
ld temp,2,a ; shift 2 bit for AC01 D/A !
stl a,*ar7+0% ; save FIR result to wave buffer !
mvmd ar7,#out_wave_ptr ; save wave buffer ptr !
stm #0,is_new_data ; 新數據到達標志置0
ccs_show: ; 此處加斷點,查看結果
nop ; if out_wave_ptr == 0xc00,
nop ; may show out_wave in CCS !!! show 128 dots !
; input buffer -> 0x1800
; output buffer -> 0x1000 (show from 0x1020)
con_fir:
popm ar3
popm ar2
popm ar0
popm al
popm ah
popm ar7
popm bk
popm st0
popm st1
ret
;--------------------------
;FIR參數表
;--------------------------
wave_data: ; freq about 1k Hz
.word 03ffch ; +2 volt
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 03ffch
.word 0c000h ; -2 volt
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
.word 0c000h
;----------------------------------------
; Filter Type Lowpass -
; Filter Length 38 -
; Sampling Frequency 25.00000000 -
; Upper Band Edge 1.20000005 -
; Lower Band Edge 2.79999995 -
;----------------------------------------
fir_coef:
.word -68
.word 58
.word 114
.word 180
.word 222
.word 202
.word 93
.word -108
.word -371
.word -631
.word -794
.word -760
.word -446
.word 182
.word 1097
.word 2200
.word 3339
.word 4331
.word 5007
.word 5247
.word 5007
.word 4331
.word 3339
.word 2200
.word 1097
.word 182
.word -446
.word -760
.word -794
.word -631
.word -371
.word -108
.word 93
.word 202
.word 222
.word 180
.word 114
.word 58
.word -68
.end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -