⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proc_motoraction_sctr.s

📁 一个直流电机的闭环控制源代码程序
💻 S
字号:
	.module PROC_MotorAction_SCTR.c
	.area text(rom, con, rel)
	.dbfile H:\单片机\源程序\2007全国电子设计大赛\电机闭环模块\PROC_MotorAction_SCTR.c
	.area data(ram, con, rel)
	.dbfile H:\单片机\源程序\2007全国电子设计大赛\电机闭环模块\PROC_MotorAction_SCTR.c
_Delta::
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile H:\单片机\源程序\2007全国电子设计大赛\电机闭环模块\PROC_MotorAction_SCTR.c
L2:
	.blkb 2
	.area idata
	.word 0
	.area data(ram, con, rel)
	.dbfile H:\单片机\源程序\2007全国电子设计大赛\电机闭环模块\PROC_MotorAction_SCTR.c
	.area text(rom, con, rel)
	.dbfile H:\单片机\源程序\2007全国电子设计大赛\电机闭环模块\PROC_MotorAction_SCTR.c
	.dbfunc e PROC_Motor_Postion_Control _PROC_Motor_Postion_Control fc
;           ERR3 -> R12,R13
;           ERR1 -> R12,R13
; dTempDCounter1 -> y+0
	.even
_PROC_Motor_Postion_Control::
	rcall push_xgsetF03C
	sbiw R28,4
	.dbline -1
	.dbline 75
; /***********************************************************
; *   函数库说明:电机闭环位置控制模块函数库                 *
; *   版本:      v1.00                                      *
; *   作者:      王卓然                                     *
; *   创建日期:  2007年4月16日                              *
; * -------------------------------------------------------- *
; *  [支 持 库]                                              *
; *   支持库名称:                                           *
; *   需要版本:                                             *
; *   支持库说明:                                           *
; * -------------------------------------------------------- *
; *  [版本更新]                                              *
; *   修改:                                                 *
; *   修改日期:                                             *
; *   版本:                                                 *
; * -------------------------------------------------------- *
; *  [版本历史]                                              *
; * -------------------------------------------------------- *
; *  [使用说明]                                              *
; ***********************************************************/
; 
; /********************
; * 头 文 件 配 置 区 *
; ********************/
; # include "RD_MacroAndConst.h"
; # include "PF_Config.h"
; # include "PROC_MotorAction_SCTR.h"
; 
; /********************
; *   系 统 宏 定 义  *
; ********************/
; 
; /*------------------*
; *   常 数 宏 定 义  *
; *------------------*/
; #ifndef MOTOR_P
;     # define MOTOR_P                10             
; #endif
; 
; 
; /*------------------*
; *   动 作 宏 定 义  *
; *------------------*/
; 
; /********************
; *    结构体定义区   *
; ********************/
; 
; /********************
; *   模块函数声明区  *
; ********************/
; 
; /********************
; *   全局函数声明区  *
; ********************/
; BOOL PROC_Motor_Postion_Control(void);
; 
; /********************
; *   模块变量声明区  *
; ********************/
; 
; /********************
; *   全局变量声明区  *
; ********************/
; 
; uint16 Delta = 0;
; 
; /***********************************************************
; *   函数说明:电机位置控制函数                             *
; *   输入:    无                                           *
; *   输出:    无                                           *
; *   调用函数:无                                           *
; ***********************************************************/
; BOOL PROC_Motor_Postion_Control(void)
; {
	.dbline 76
;     uint32 dTempDCounter = 0;
	.dbline 77
;     uint16  ERR = 0;
	.dbline 80
;     static uint16 I = 0;
;     
;     SAFE_CODE_PERFORMANCE
	cli
	.dbline 80
	lds R4,_g_dNowMotorPosition+2
	lds R5,_g_dNowMotorPosition+2+1
	lds R2,_g_dNowMotorPosition
	lds R3,_g_dNowMotorPosition+1
	std y+0,R2
	std y+1,R3
	std y+2,R4
	std y+3,R5
	.dbline 80
	.dbline 80
	sei
	.dbline 85
;     (
;         dTempDCounter = g_dNowMotorPosition;
;     )
;     
;     if (dTempDCounter > g_dAimMotorPosition)
	lds R4,_g_dAimMotorPosition+2
	lds R5,_g_dAimMotorPosition+2+1
	lds R2,_g_dAimMotorPosition
	lds R3,_g_dAimMotorPosition+1
	ldd R6,y+0
	ldd R7,y+1
	ldd R8,y+2
	ldd R9,y+3
	cp R2,R6
	cpc R3,R7
	cpc R4,R8
	cpc R5,R9
	brlo X6
	rjmp L3
X6:
X0:
	.dbline 86
;     {
	.dbline 87
;         ERR = (uint16)((dTempDCounter - g_dAimMotorPosition)*MOTOR_P);
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	ldi R20,20
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R9
	st -y,R8
	st -y,R7
	st -y,R6
	movw R16,R20
	movw R18,R22
	rcall empy32u
	movw R12,R16
	.dbline 88
;         Delta = ABS((int16)(dTempDCounter - g_dAimMotorPosition));
	lds R2,_g_dAimMotorPosition
	lds R3,_g_dAimMotorPosition+1
	ldd R24,y+0
	ldd R25,y+1
	sub R24,R2
	sbc R25,R3
	cpi R24,0
	ldi R30,0
	cpc R25,R30
	brge L5
X1:
	ldd R24,y+0
	ldd R25,y+1
	sub R24,R2
	sbc R25,R3
	com R24
	com R25
	subi R24,0xFF
	sbci R25,0xFF
	movw R10,R24
	rjmp L6
L5:
	lds R2,_g_dAimMotorPosition
	lds R3,_g_dAimMotorPosition+1
	ldd R10,y+0
	ldd R11,y+1
	sub R10,R2
	sbc R11,R3
L6:
	sts _Delta+1,R11
	sts _Delta,R10
	.dbline 92
;         
;         //SAFE_CODE_PERFORMANCE
;         //( 
;             MOTOR_GO_BACK
	in R24,0x12
	andi R24,63
	ori R24,64
	out 0x12,R24
	.dbline 92
	ldi R24,17
	out 0x2e,R24
	.dbline 92
	.dbline 95
;         //)
;         
;         SET_PWM(ERR)
	ldi R24,800
	ldi R25,3
	cp R24,R12
	cpc R25,R13
	brsh L7
X2:
	movw R10,R24
	rjmp L8
L7:
	movw R10,R12
L8:
	out 0x2b,R11
	out 0x2a,R10
	.dbline 96
;     }
	rjmp L4
L3:
	.dbline 97
;     else if (dTempDCounter < g_dAimMotorPosition)
	lds R4,_g_dAimMotorPosition+2
	lds R5,_g_dAimMotorPosition+2+1
	lds R2,_g_dAimMotorPosition
	lds R3,_g_dAimMotorPosition+1
	ldd R6,y+0
	ldd R7,y+1
	ldd R8,y+2
	ldd R9,y+3
	cp R6,R2
	cpc R7,R3
	cpc R8,R4
	cpc R9,R5
	brlo X7
	rjmp L9
X7:
X3:
	.dbline 98
;     {
	.dbline 99
;         ERR = (uint16)((g_dAimMotorPosition - dTempDCounter)*MOTOR_P);
	movw R2,R6
	movw R4,R8
	lds R8,_g_dAimMotorPosition+2
	lds R9,_g_dAimMotorPosition+2+1
	lds R6,_g_dAimMotorPosition
	lds R7,_g_dAimMotorPosition+1
	sub R6,R2
	sbc R7,R3
	sbc R8,R4
	sbc R9,R5
	ldi R20,20
	ldi R21,0
	ldi R22,0
	ldi R23,0
	st -y,R9
	st -y,R8
	st -y,R7
	st -y,R6
	movw R16,R20
	movw R18,R22
	rcall empy32u
	movw R12,R16
	.dbline 100
;         Delta = ABS((int16)(g_dAimMotorPosition - dTempDCounter));
	ldd R2,y+0
	ldd R3,y+1
	lds R24,_g_dAimMotorPosition
	lds R25,_g_dAimMotorPosition+1
	sub R24,R2
	sbc R25,R3
	cpi R24,0
	ldi R30,0
	cpc R25,R30
	brge L11
X4:
	lds R24,_g_dAimMotorPosition
	lds R25,_g_dAimMotorPosition+1
	sub R24,R2
	sbc R25,R3
	com R24
	com R25
	subi R24,0xFF
	sbci R25,0xFF
	movw R10,R24
	rjmp L12
L11:
	ldd R2,y+0
	ldd R3,y+1
	lds R10,_g_dAimMotorPosition
	lds R11,_g_dAimMotorPosition+1
	sub R10,R2
	sbc R11,R3
L12:
	sts _Delta+1,R11
	sts _Delta,R10
	.dbline 104
;         
;         //SAFE_CODE_PERFORMANCE
;         //(        
;             MOTOR_GO_FRONT
	in R24,0x12
	andi R24,63
	ori R24,128
	out 0x12,R24
	.dbline 104
	ldi R24,17
	out 0x2e,R24
	.dbline 104
	.dbline 107
;         //)
;         
;         SET_PWM(ERR)
	ldi R24,800
	ldi R25,3
	cp R24,R12
	cpc R25,R13
	brsh L13
X5:
	movw R10,R24
	rjmp L14
L13:
	movw R10,R12
L14:
	out 0x2b,R11
	out 0x2a,R10
	.dbline 108
;     }
	rjmp L10
L9:
	.dbline 110
;     else                                                    //计数器相等
;     {
	.dbline 111
;         SET_PWM(0)
	clr R2
	clr R3
	out 0x2b,R3
	out 0x2a,R2
	.dbline 113
;         //MOTOR_BRAKE_FREE
;     }
L10:
L4:
	.dbline 125
;     /*
;     Set_DISP_BUFF
;         (
;             0x0F,
;             SET_DWORD_DIV_8(Delta).BYTEBH,
;             SET_DWORD_DIV_8(Delta).BYTEBL,
;             SET_DWORD_DIV_8(Delta).BYTEAH,
;             SET_DWORD_DIV_8(Delta).BYTEAL
;         );
;     */
; 
;     return TRUE;
	ldi R16,1
	.dbline -2
L1:
	.dbline 0 ; func end
	adiw R28,4
	rjmp pop_xgsetF03C
	.dbsym r ERR3 12 i
	.dbsym r ERR1 12 i
	.dbsym l dTempDCounter1 0 l
	.dbend
; }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -