This is a FIR filter based on modulo addressing mode.
; GLOBAL INIT_Coefficent_Data,INI_Sam_Data,NPTSS
NPTSS EQU 32
Section xramdata
org x:
INI_Sam_Buff dsm NPTSS
org x:
INIT_Coefficent_Buff dc \
0.9,0.1,0.2,0.2,0.5,0.5,-0.2,-0.1,0.9,0.1,\
0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,\
0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,\
0.1,0.1
Fir_Result ds 1
sample_Flag dc $01
new_Sample dc 0.1
sample_PTR ds 1
temporary ds 1
ENDSEC
; sample code
section rtlib
org p:
global Fmain
SUBROUTINE "Fmain",Fmain,FmainEND-Fmain
; assembly level entry point
Fmain:
;Begin to initialize both sample and coefficents buffer
move.l #INI_Sam_Buff,r0
nop
moveu.w #NPTSS-1,m01
do #NPTSS,labelsample ;fill sample buffer with data
move.w #0.3,y0
move.w y0,x:(r0)+
move.w r0,x:sample_PTR
labelsample:
;initialization end
label1: nop
;update sample buffer with new ADC sample
moveu.w x:sample_PTR,r0
brclr #$01,x:sample_Flag,* ;the sample_Flag should be set by ISR of ADC
move.w X:(r0)+,y0 ;only for increment r0
move.w x:new_Sample,y0
move.w y0,x:(r0)+
move.l #INIT_Coefficent_Buff+31,r3
clr a
move.w x:(r3)-,x0
;Begint to count the cycle from here
do #NPTSS-1,label
mac x0,y0,a x:(r0)+,y0 x:(r3)-,x0
label:
macr x0,y0,a
;stop counting and compute the cycle number
move.w a,x:Fir_Result
move.w r0,x:sample_PTR ;save the address new sample should be saved
nop ;Does nothing
bra label1
nop ; do nothing
rts
FmainEND:
endsec
end