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

📄 bldcsensor.asm

📁 TI公司的DSP(LF2407A)编写的有霍尔位置传感器的无刷直流电机控制程序,内含子程序说明
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;>>>> 	    rc1.RampDelayMax = 0x00ff;
	LACK	255
	SACL	_rc1+1
	.line	20
;>>>> 	    rc1.RampLowLimit = 0x8000;		//_IQ(0);
	SPLK	#-32768,_rc1+2
	.line	21
;>>>> 	    rc1.RampHighLimit = 0x7FFF;		//_IQ(1);
;>>>> 	// Initialize Hall module   
;>>>> 	    //hall1.DebounceAmount = 5;
;>>>> 	    //hall1.Revolutions = -10;		//?
	SPLK	#32767,_rc1+3
	.line	25
;>>>> 	    hall1.init(&hall1);
;>>>> 	// Initialize RMP2 module
	LALK	_hall1+0
	SACL	*+
	LAC	_hall1+7
	CALA
	MAR	*-,AR3
	.line	27
;>>>> 		rmp2.Out = DFuncDesired;
	LDPK	_DFuncDesired
	BLDD	_DFuncDesired,#_rmp2+5
	.line	28
;>>>> 		rmp2.Ramp2Delay = 50;
	LACK	50
	SACL	_rmp2+4
	.line	29
;>>>> 	    rmp2.Ramp2Max = 0x7FF0;
	SPLK	#32752,_rmp2+1
	.line	30
;>>>> 	    rmp2.Ramp2Min = 0x000F;
;>>>> 	// Initialize the PID2 module for dc-bus current
	LACK	15
	SACL	_rmp2+2
	.line	32
;>>>> 	    pid1_idc.k0_reg2 = 0x0200; 		//Q9,_IQ(1);                  
	SPLK	#512,_pid1_idc+2
	.line	33
;>>>> 		pid1_idc.k1_reg2 = 0x0e0; 		//Q13,_IQ(T/0.003);			
	LACK	224
	SACL	_pid1_idc+3
	.line	34
;>>>> 	 	pid1_idc.kc_reg2 = 0x0506; 		//Q13,_IQ(0.2);
	SPLK	#1286,_pid1_idc+4
	.line	35
;>>>> 	    pid1_idc.max_reg2 = 0x7fff;   // Q15  D=100% ,_IQ(0.99);
	SPLK	#32767,_pid1_idc+9
	.line	36
;>>>> 	    pid1_idc.min_reg2 = 0x0000; 	//_IQ(0); 
;>>>> 	// Initialize the PID2 module for speed
	LACK	0
	SACL	_pid1_idc+10
	.line	38
;>>>> 	    pid1_spd.k0_reg2 = 0x0800;		//_IQ(2);
	SPLK	#2048,_pid1_spd+2
	.line	39
;>>>> 		pid1_spd.k1_reg2 = 0x40;//0x0740;	//_IQ(T/0.1);()0.002
	LACK	64
	SACL	_pid1_spd+3
	.line	40
;>>>> 	 	pid1_spd.kc_reg2 = 0x0506;		//_IQ(0.2);
	SPLK	#1286,_pid1_spd+4
	.line	41
;>>>> 	    pid1_spd.max_reg2 = 0x7fff;	//// Q15  D=100%;
	SPLK	#32767,_pid1_spd+9
	.line	42
;>>>> 	    pid1_spd.min_reg2 = 0;	// _IQ(10%); 
	LACK	0
	SACL	_pid1_spd+10
	.line	44
;>>>> 	    T2PR = SYSTEM_INT_PERIOD;  /* Initialize period register ,time base from T2 underflow interrupt (i.e. period)*/
	LARK	AR3,29703
	SPLK	#1000,* 
	.line	45
;>>>> 	    T2CNT = 0x0000;
	SBRK	2
	SACL	* 
	.line	46
;>>>> 	    T2CON = 0x9040;		   // Count up, x1, internal clk, disable compare, use own period
;>>>> 	#if (REAL_TIME == TRUE)
;>>>> 	        rtmon_init();      /* Call the monitor init function  */
;>>>> 	#endif /* REAL_TIME==TRUE */
;>>>> 	// Enable global Interrupts and higher priority real-time debug events:
	ADRK	3
	SPLK	#-28608,* 
	.line	56
;>>>> 	        asm("  CLRC	INTM ");      /* set off the system running */
  CLRC	INTM 
	.line	61
;>>>> 	 			LCD_disp1();
;>>>> 	//			COM=PFDATDIR;
;>>>> 	//        	PFDATDIR=COM;
;>>>> 	//  		PFDATDIR=PFDATDIR|0x0020; 
;>>>> 	// IDLE loop. Just sit and loop forever:	
;>>>> 	        while(1)             /* Nothing running in the background at present */
	CALL	_LCD_disp1,AR1
	MAR	* ,AR2
L1:
	.line	70
;>>>> 	        	keycounter++;
	LDPK	_keycounter
	LAC	_keycounter
	ADDK	1
	SACL	_keycounter
	.line	71
;>>>> 				disp_refresh++;
	LAC	_disp_refresh
	ADDK	1
	SACL	_disp_refresh
	.line	72
;>>>> 				if(disp_refresh>=40000)//1s刷新一次LCD显示
	ZALS	_disp_refresh
	BNV	$+2
	LARK	AR2,1
	MAR	*0+
	SACL	*+
	SACH	*-
	LT	*+
	MPYK	1
	LPH	* 
	RSXM
	LACK	40000
	SPAC
	BNV	$+6
	BLZ	L3
	B	$+4
	BGZ	L3
	.line	74
;>>>> 					disp_refresh=0;
;>>>> 	//			PFDATDIR=(PFDATDIR|0x2020)&((~runled)|0x0ffdf);
;>>>> 	//			COM=PFDATDIR;
	LACK	0
	SACL	_disp_refresh
	.line	77
;>>>> 				Iref_disp();			//电流给定值显示
	CALL	_Iref_disp,AR1
	.line	78
;>>>> 				Ifb_disp();				//电流实际值显示
	CALL	_Ifb_disp
	.line	79
;>>>> 				Vref_disp();			//转速给定值显示
	CALL	_Vref_disp
	.line	80
;>>>> 				Vfb_disp();				//转速实际值显示
	CALL	_Vfb_disp
	.line	81
;>>>> 				fpwm_disp();			//PWM斩波频率显示
	CALL	_fpwm_disp
	.line	82
;>>>> 				Dpwm_disp();			//PWM占空比显示
	CALL	_Dpwm_disp
	.line	83
;>>>> 				mod6_disp();			//换向的状态,0~5中的一个.St显示
	CALL	_mod6_disp
	.line	84
;>>>> 				Hmap_disp();			//换向表
	CALL	_Hmap_disp
	.line	85
;>>>> 				prop_int();
;>>>> 	//			PFDATDIR=COM;
	CALL	_prop_int
L3:
	.line	89
;>>>> 			   if(keycounter>=400)    //10ms处理一次按键
	SSXM
	LDPK	_keycounter
	LAC	_keycounter
	SUBK	400
	BLZ	L4
	.line	90
;>>>> 		  		{	keycounter=0;
	LACK	0
	SACL	_keycounter
	.line	91
;>>>> 					key=Keys1s8();
;>>>> 	    	  	 switch(key)
	CALL	_Keys1s8,AR1
	LDPK	_key
	SACL	_key
	B	L5
L6:
	.line	94
;>>>> 	 				case 1:	{SpeedRef = SpeedRef+56;break;} //设定+步长10RPM
	SSXM
	LDPK	_SpeedRef
	LAC	_SpeedRef
	ADDK	56
	SACL	_SpeedRef
	B	L4
L8:
	.line	95
;>>>> 		 			case 2: {SpeedRef = SpeedRef-56;break;} //设定-步长10RPM
	SSXM
	LDPK	_SpeedRef
	LAC	_SpeedRef
	SUBK	56
	SACL	_SpeedRef
	B	L4
L9:
	.line	96
;>>>> 		 			case 3: {pid1_spd.k0_reg2 = pid1_spd.k0_reg2+0x010;break;}		//_IQ(2);
	SSXM
	LDPK	_pid1_spd+2
	LAC	_pid1_spd+2
	ADDK	16
	SACL	_pid1_spd+2
	B	L4
L10:
	.line	97
;>>>> 		 			case 4: {pid1_spd.k0_reg2 = pid1_spd.k0_reg2-0x010;break;}		//_IQ(2);
	SSXM
	LDPK	_pid1_spd+2
	LAC	_pid1_spd+2
	SUBK	16
	SACL	_pid1_spd+2
	B	L4
L11:
	.line	98
;>>>> 		 			case 5: {pid1_spd.k1_reg2 = pid1_spd.k1_reg2+0x01;break;}		//_IQ(2);
	SSXM
	LDPK	_pid1_spd+3
	LAC	_pid1_spd+3
	ADDK	1
	SACL	_pid1_spd+3
	B	L4
L12:
	.line	99
;>>>> 		 			case 6: {pid1_spd.k1_reg2 = pid1_spd.k1_reg2-0x01;break;}		//_IQ(2);
	SSXM
	LDPK	_pid1_spd+3
	LAC	_pid1_spd+3
	SUBK	1
	SACL	_pid1_spd+3
	B	L4
L13:
	.line	100
;>>>> 					case 7: {duty = duty + 0x1000;break;}
	SSXM
	LDPK	_duty
	LAC	_duty
	ADDK	4096
	SACL	_duty
	B	L4
L14:
	.line	101
;>>>> 					case 8: {TabShift = TabShift+1;break;}
;>>>> 					default:;
	SSXM
	LDPK	_TabShift
	LAC	_TabShift
	ADDK	1
	SACL	_TabShift
	B	L4
L5:
	.line	92
	SSXM
	LAC	_key
	MAR	* ,AR0
	SUBK	8
	BGZ	L4
	ADDK	7
	BLZ	L4
	ADLK	LL3
	TBLR	*
	LAC	*
	BACC
	.sect	".switch"
LL3:
	.word	L6
	.word	L8
	.word	L9
	.word	L10
	.word	L11
	.word	L12
	.word	L13
	.word	L14
	.text
L4:
	.line	120
	MAR	* ,AR2
	B	L1
	.endfunc	182,000000000H,3

	.sym	_c_int03,_c_int03,32,2,0
	.globl	_c_int03

	.func	184
;>>>> 	void interrupt c_int03()
;>>>> 	//        asm("      CLRC     XF ");
******************************************************
* FUNCTION DEF : _c_int03
******************************************************
_c_int03:
	CALL	I$$SAVE
	SAR	AR1,*
	LARK	AR0,1
	LAR	AR0,*0+,AR3

	.line	4
;>>>> 	        isr_ticker++;
	LDPK	_isr_ticker
	LAC	_isr_ticker
	ADDK	1
	SACL	_isr_ticker
	.line	7
;>>>> 	        EVAIFRB=0x0ffff;          /* Clear all EV1 Group A EV interrupt flags*/
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Call the ADC04U_DRV read function.
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//	  adc1.read(&adc1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the RMP module and call the Ramp control
;>>>> 	//    calculation function.
;>>>> 	// ------------------------------------------------------------------------------
	LARK	AR3,29744
	SPLK	#-1,* ,AR1
	.line	16
;>>>> 	      rc1.TargetValue = SpeedRef;
	BLKD	#_SpeedRef,_rc1
	.line	17
;>>>> 	      rc1.calc(&rc1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the HALL module and call the Hall sensor
;>>>> 	//    read function.
;>>>> 	// ------------------------------------------------------------------------------
	LALK	_rc1+0
	SACL	*+
	LAC	_rc1+7
	CALA
	MAR	*-
	.line	22
;>>>> 	      hall1.read(&hall1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the MOD6 module and call the Modulo 6 counter
;>>>> 	//    calculation function.
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	      //mod1.TrigInput = hall1.CmtnTrigHall;
;>>>> 	      //mod1.Counter = hall1.HallMapPointer; 
;>>>> 	      //mod1.calc(&mod1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the RMP2 module and call the Ramp control 2
;>>>> 	//    calculation function.
;>>>> 	// ------------------------------------------------------------------------------
	LALK	_hall1+0
	SACL	*+
	LDPK	_hall1+8
	LAC	_hall1+8
	CALA
	MAR	*-
	.line	34
;>>>> 	      rmp2.DesiredInput = DFuncDesired;
	LDPK	_DFuncDesired
	BLDD	_DFuncDesired,#_rmp2
	.line	35
;>>>> 	      rmp2.calc(&rmp2);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the PID_REG3 module and call the PID speed controller
;>>>> 	//    calculation function.
;>>>> 	// ------------------------------------------------------------------------------  
	LALK	_rmp2+0
	SACL	*+
	LAC	_rmp2+6
	CALA
	MAR	*-
	.line	40
;>>>> 	      pid1_spd.ref_reg2 = rc1.SetpointValue;
	LDPK	_rc1+5
	BLDD	_rc1+5,#_pid1_spd+1
	.line	41
;>>>> 	      pid1_spd.fb_reg2 = (int)(speed1.Speed);
	BLKD	#_speed1+6,_pid1_spd
	.line	42
;>>>> 	      pid1_spd.calc(&pid1_spd);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Set the speed closed loop flag once the speed is built up to a desired value. 
;>>>> 	// ------------------------------------------------------------------------------
	LALK	_pid1_spd+0
	SACL	*+
	LAC	_pid1_spd+12
	CALA
	MAR	*-
	.line	46
;>>>> 	      if (rc1.EqualFlag == 0x7FFF)  {
;>>>> 	//         SpeedLoopFlag = TRUE; 
	SSXM
	LDPK	_rc1+6
	LAC	_rc1+6
	SUBK	32767
	BNZ	L16
	.line	48
;>>>> 	         rc1.RampDelayMax = 300;  
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the PWM_DRV module and call the PWM signal generation
;>>>> 	//    update function.
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	   // Switch from fixed duty-cycle or controlled Speed duty-cycle by SpeedLoopFlag variable
	SPLK	#300,_rc1+1
L16:
	.line	55
;>>>> 	      if (SpeedLoopFlag == FALSE)
	LAC	_SpeedLoopFlag
	BNZ	L17
	.line	56
;>>>> 	         pwm1.DutyFunc = (rmp2.Out+duty)&0x07fff;           // fixed duty-cycle
;>>>> 	      else 
	LAC	_duty
	ADD	_rmp2+5
	ANDK	32767
	SACL	_pwm1+3
	B	L18
L17:
	.line	58
;>>>> 	         pwm1.DutyFunc = pid1_spd.out_reg2;   	// controlled Speed duty-cycle
;>>>> 	      //pwm1.CmtnPointer = hall1.tab;
	BLKD	#_pid1_spd+11,_pwm1+3
L18:
	.line	61
;>>>> 		  HallValue=hall1.tab;
	BLKD	#_hall1+6,_HallValue
	.line	62
;>>>> 		  ACTRB=ACTRX1[(hall1.tab+TabShift)&6];
	LAC	_TabShift
	ADD	_hall1+6
	ANDK	6
	RSXM
	ADLK	_ACTRX1+0,0
	MAR	* ,AR0
	SACL	* 
	LAR	AR3,* ,AR3
	LARK	AR4,29971
	SSXM
	LAC	* ,AR4
	SACL	* ,AR1
	.line	63
;>>>> 	      pwm1.update(&pwm1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Connect inputs of the SPEED_PR module and call the speed calculation 
;>>>> 	//    function.
;>>>> 	// ------------------------------------------------------------------------------  
	LALK	_pwm1+0
	SACL	*+
	LAC	_pwm1+5
	CALA
	MAR	*-
	.line	69
;>>>> 	      if (HallValue == 3) {
	SSXM
	LDPK	_HallValue
	LAC	_HallValue
	SUBK	3
	BNZ	L19
	.line	70
;>>>> 			HallValue = 0xFF; // 强制一个新值作为区间值
	LACK	255
	SACL	_HallValue
	.line	71
;>>>> 			if (++speedcount == speed1.motorpairs) // 对于23对极电机,将此代码段执行23 个电周期(即1 个 机械周期)
	LAC	_speedcount
	ADDK	1
	SACL	_speedcount
	SUB	_speed1+10
	BNZ	L20
	.line	73
;>>>> 	        	 speed1.TimeStamp = VirtualTimer;
;>>>> 	        // speed1.calc(&speed1);
;>>>> 	//      if (speed1.InputSelect == 0)  
;>>>> 		   //{
	BLKD	#_VirtualTimer,_speed1+2
L20:
	.line	78
;>>>> 		     	 speed1.OldTimeStamp = speed1.NewTimeStamp;
	BLKD	#_speed1,_speed1+1
	.line	79
;>>>> 		    	 speed1.NewTimeStamp = speed1.TimeStamp; 
	BLKD	#_speed1+2,_speed1
	.line	80
;>>>> 		    	 speed1.EventPeriod = speed1.NewTimeStamp - speed1.OldTimeStamp; 
	LAC	_speed1
	SUB	_speed1+1
	SACL	_speed1+4
	.line	82
;>>>> 	 	    	if (speed1.EventPeriod < 0)
	LAC	_speed1+4
	BGEZ	L21
	.line	83
;>>>> 	 	      	speed1.EventPeriod += 32767;   // 0x7FFF = 32767
;>>>> 	 	   //}
	ADDK	32767
	SACL	_speed1+4
L21:
	.line	85
;>>>> 	        	speed1.calc(&speed1);
;>>>> 	// ------------------------------------------------------------------------------
;>>>> 	//    Increase virtual timer and force 15 bit wrap around
;>>>> 	// ------------------------------------------------------------------------------
	LALK	_speed1+0
	SACL	*+
	LAC	_speed1+11
	CALA
	MAR	*-
L19:
	.line	94
;>>>> 		VirtualTimer++;
	LDPK	_VirtualTimer
	LAC	_VirtualTimer
	ADDK	1
	SACL	_VirtualTimer
	.line	95
;>>>> 		VirtualTimer &= 0x7FFF;
	ANDK	32767
	SACL	_VirtualTimer
	.line	96
;>>>> 		speedtime++;
	ZALS	_speedtime
	ADDH	_speedtime+1
	ADDK	1
	SACL	_speedtime
	SACH	_speedtime+1
	.line	97
;>>>> 		speedtime &= 0x7FFFFFFF;
;>>>> 	// asm("      SETC     XF ");//SCSR2中/BOOT EN.BOOT使能位,这一位反映XF引脚在复位时的状态,它可以被软件改变.XF=0硎臼鼓芤

⌨️ 快捷键说明

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