📄 cursample.asm
字号:
;-----------------------------------------------------------
;重庆大学DSP实验室
;函数名:void cursample(cursample_struct *p)
;函数功能:采样电机相电流ia,ib,并转换为Q12格式
;(以额定电流为基准)
;数字滤波方式:平均值滤波
;转换公式:
; ix=Kcurrent*((result>>6)-512) (Q12)
; ;result 为电流平均值
; ;x=a, b
; Kcurrent=(4096*imax)/(512*ib) (Q0)
; ;选择imax=(1.5V*33.33)/(27*50e-3)
; ;ib为额定电流峰值
;入口条件:
; result8--result11
; ;电流ia的AD转换结果寄存器
; result12--result15
; ;电流ib的AD转换结果寄存器
;出口条件:
; typedef struct
; { int zeropoint_ib;B相电流采样提升零点
; int ib; ;B相电流值,Q12
; int zeropoint_ia;A相电流采样提升零点 Q0
; int ia; ;A相电流值,Q12
; }cursample_struct;
;请用户在主程序中声明以下函数和全局变量:
; typedef struct
; { int zeropoint_ib;B相电流采样提升零点
; int ib; ;B相电流值,Q12
; int zeropoint_ia;A相电流采样提升零点 Q0
; int ia; ;A相电流值,Q12
; }cursample_struct;
; extern void cursample(cursample_struct *p);
;2002.4.16.
;-----------------------------------------------------------
.def _cursample
Kcurrent .set 1h ;Q0
cursample_frame .set 02h
.text
_cursample:
POPD *+
SAR AR0,*+
SAR AR1,*
LAR AR0,#cursample_frame
LAR AR0,*0+,AR0
LAR AR2,*,AR2
SBRK #3h
LAR AR3,*,AR2 ;AR3:zeropoint_ib
LAR AR2,#70B0h ;STACK:*p/address/AR0/AR1
;ARP:AR2, AR0:AR1, AR2:RESULT8
CLRC SXM
LACC #0
RPT #3
ADD *+,8 ;CALCULATE AVERAGE OF AD RESULT
MAR *,AR0 ;ARP:AR0
SACH *+,AR2 ;STACK:*p/ADDRESS/AR0/ia/y
;ARP:AR2, AR0:y, AR2:RESULT12
LACC #0
RPT #3
ADD *+,8 ;CALCULATE AVERAGE OF AD RESULT
MAR *,AR3
SETC SXM
SUB *+,16,AR0 ;STACK:*p/ADDRESS/AR0/ia/ib
;ARP:AR0, AR0:ib,
SACH *
LT *-,AR3 ;STACK:*p/ADDRESS/AR0/ia/ib
;ARP:AR0, AR0:ia, AR2:RESULT17
MPY #Kcurrent ;Kcurrent*ib
SPL *+,AR0 ;ib=Kcurrent*ib
LACC *,AR3
SUB *+,AR0
SACL * ;GETTING POSITIVE OR NEGATIVE VALUES OF ia
LT *,AR3 ;ARP:AR3
MPY #Kcurrent ;Kcurrent*ia
SPL *,AR1 ;ia=Kcurrent*ia
SBRK #(cursample_frame+1)
LAR AR0,*-
PSHD *
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -