|
简单来说这段代码是用来做FIR+RMS计算的。FIR的部分是直接用TI的例程的。RMS算法部分是自己写了。
AD采集得到数据由CLA读取中断和采样结果,并且进行数字滤波。
RMS算法的部分就是每次滤波完的数据都求一次平方,并且累加。同时设定某一个阀值Vth,当电压超过Vth时认为是采样满了一个周期,得到将所得平方和开放求平均开方得到有效值。再输出到CLA的通讯RAM中。代码如下,内含错误若干。已经改了几个通宵了,第一次写汇编被这么简单的程序纠结了。。望各位大哥帮小弟个忙。没看懂的程序部分请留言。@dontium ~
- MMOV32 MR0,@_X4 ;1 Load MR0 with X4
- MMOV32 MR1,@_A4 ;2 Load MR1 with A4
- MNOP ;3 Wait till I8 to read result
- MNOP ;4 Wait till I8 to read result
- MNOP ;5 Wait till I8 to read result
- MNOP ;6 Wait till I8 to read result
- MNOP ;7 Wait till I8 to read result
- MUI16TOF32 MR2, @_AdcResult.ADCRESULT1 ;8 Read ADCRESULT1 and convert to float
- MMPYF32 MR2, MR1, MR0 ; MR2 (Y) = MR1 (A4) * MR0 (X4)
- || MMOV32 @_X0, MR2
- MMOVD32 MR0,@_X3 ; Load MR0 with X3, Load X4 with X3
- MMOV32 MR1,@_A3 ; Load MR1 with A3
-
- MMPYF32 MR3, MR1, MR0 ; MR3 (Y) = MR1 (A3) * MR0 (X3)
- || MMOV32 MR1,@_A2 ; Load MR1 with A2
- MMOVD32 MR0,@_X2 ; Load MR0 with X2, Load X3 with X2
- MMACF32 MR3, MR2, MR2, MR1, MR0 ; MR3 = A3*X3 + A4*X4
- || MMOV32 MR1,@_A1 ; MR2 = MR1 (A2) * MR0 (X2)
- MMOVD32 MR0,@_X1 ; Load MR0 with X1, Load X2 with X1
- MMACF32 MR3, MR2, MR2, MR1, MR0 ; MR3 = A2*X2 + (A3*X3 + A4*X4)
- || MMOV32 MR1,@_A0 ; MR2 = MR1 (A1) * MR0 (X1)
- MMOVD32 MR0,@_X0 ; Load MR0 with X0, Load X1 with X0
- MMACF32 MR3, MR2, MR2, MR1, MR0 ; MR3 = A1*X1 + (A2*X2 +A3*X3 + A4*X4)
- || MMOV32 MR1,@_A0 ; MR2 = MR1 (A0) * MR0 (X0)
- MADDF32 MR3, MR3, MR2 ; MR3 = A0*X0 + (A1*X1 + A2*X2 +A3*X3 + A4*X4)
- MF32TOUI16 MR2, MR3 ; Get back to Uint16 value
- MMOV16 @_VoltFilt, MR2 ; Output
- .if CLA_DEBUG == 1
- MDEBUGSTOP
- .endif
- MMOV32 MR1, @_Vavr
- MSUBF32 MR3, MR3, MR1 ; use the current average votage for blocking
- MMOV32 MR1, @_Vavrc ; calculate the total votage for the average calc
- MADDF32 MR1, MR1, MR3
- MMOV32 @_Vavrc, MR1
- MMPYF32 MR2, MR3, MR3 ; calculate the total power for the rms calc
- || MMOV32 MR1, @_Vrmsc
- MADDF32 MR1, MR1, MR2
- MMOV32 @_Vrmsc, MR1
- MMOVZ16 MR1, @_calcnum ; N+1
- MMOVZ16 MR0, @_TRUE_Value
- MADD32 MR1, MR0, MR1
- MMOV16 @_calcnum, MR1
- MUI16TOF32 MR2, @_Vth ; load MR2 with the votage threshold
- MCMPF32 MR3,MR2 ; compare the votage and its threshold
- MNOP
- MNOP
- MNOP
- MBCNDD aboveVth,GT ; if votage is larger than its threshold,then jump to the aboveVth and do the calcalation
- MNOP
- MNOP
- MNOP
- ;MMOVIZ MR0, #0.0 ; clear the check flag
- ;MF32TOUI16 MR0, MR0
- ;MMOV16 @_Frag, MR0
- MMOV16 MAR0, @_FALSE_Value
- MMOV16 @_Frag, MAR0
- MNOP
- MNOP
- MNOP
- MBCNDD Tsk7STOP, UNC ; jump to the end of the task
- MNOP
- MNOP
- MNOP
- aboveVth: MUI16TOF32 MR2, @_Frag ; load MR2 with the Flag
- .if CLA_DEBUG == 1
- MDEBUGSTOP
- .endif
- MMOVF32 MR0, #0.0
- ;MF32TOI32 MR0, MR0
- MCMPF32 MR2, MR0 ; compare Frag with 0
- MNOP
- MNOP
- MNOP
- MBCNDD Tsk7STOP,GT ; if Frag is biger than 0,which means it has been set to 1 and has been calclated ,Jump to the end
- MNOP
- MNOP
- MNOP
- MMOV16 MAR0,@_TRUE_Value ; set the Frag
- MMOV16 @_Frag,MAR0
- MNOP
- MNOP
- MNOP
- MNOP
- MMOV32 MR1, @_calcnum ;calc the average of the RMS
- MMOV16 MAR1, @_calcnum
- MNOP
- MNOP
- MNOP
- MNOP
- MMOV16 @_calcPRD, MAR1
- MNOP
- MNOP
- MNOP
- MNOP
- MEINVF32 MR0, MR1
- MMOV32 MR1, @_Vrmsc
- MMPYF32 MR2, MR0, MR1
- MMOV32 @_Vrms, MR2 ;load the Vrms with MR2
- MDEBUGSTOP
- ;MMOV32 MR0, @_invn ;calc the average of the RMS
- MMOV32 MR1, @_Vavrc
- MMPYF32 MR2, MR0, MR1
- MMOV32 @_Vavr, MR2 ;load the Vrms with MR2
- MMOVIZ MR0, #0.0
- MUI16TOF32 MR0, MR0
- MMOV32 @_Vavrc, MR0
- MMOV32 @_Vrmsc, MR0
- MMOVI16 MAR0, #0
- MMOV16 @_calcnum,MAR0
- MNOP
- MNOP
- MNOP
- MNOP
- Tsk7STOP: MSTOP ; End task
复制代码
|
|