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

📄 mc_stm8s_bldc_drive.ls

📁 STM8S105 BLDC源代码
💻 LS
📖 第 1 页 / 共 5 页
字号:
1535                     ; 789 		TIM1->IER |= BIT0;
1537                     ; 795 			vtimer_SetTimer(DEV_DUTY_UPDATE_TIMER,SPEED_PID_SAMPLING_TIME,&dev_BLDC_driveUpdate);
1539  0184 ae01f7        	ldw	x,#_dev_BLDC_driveUpdate
1540  0187 72105254      	bset	21076,#0
1541  018b 89            	pushw	x
1542  018c ae0005        	ldw	x,#5
1543  018f 89            	pushw	x
1544  0190 a605          	ld	a,#5
1545  0192 cd0000        	call	_vtimer_SetTimer
1547  0195 5b04          	addw	sp,#4
1548                     ; 796 			StartUpStatus = STARTUP_IDLE;
1550  0197 3f00          	clr	L3_StartUpStatus
1551                     ; 797 			return FUNCTION_ENDED;
1553  0199 a601          	ld	a,#1
1556  019b 81            	ret	
1557  019c               L105:
1558                     ; 801 	case STARTUP_RAMPING:
1558                     ; 802 		if( (MTC_Status & MTC_STEP_MODE) == 0 )
1561  019c 7200002b14    	btjt	_MTC_Status,#0,L325
1562                     ; 804 			vtimer_SetTimer(DEV_DUTY_UPDATE_TIMER,SPEED_PID_SAMPLING_TIME,&dev_BLDC_driveUpdate);
1564  01a1 ae01f7        	ldw	x,#_dev_BLDC_driveUpdate
1565  01a4 89            	pushw	x
1566  01a5 ae0005        	ldw	x,#5
1567  01a8 89            	pushw	x
1568  01a9 a605          	ld	a,#5
1569  01ab cd0000        	call	_vtimer_SetTimer
1571  01ae 5b04          	addw	sp,#4
1572                     ; 805 			StartUpStatus = STARTUP_IDLE;
1574  01b0 3f00          	clr	L3_StartUpStatus
1575                     ; 806 			return FUNCTION_ENDED;
1577  01b2 a601          	ld	a,#1
1580  01b4 81            	ret	
1581  01b5               L325:
1582                     ; 810 			if( MTC_Status & (MTC_STARTUP_FAILED|MTC_OVER_CURRENT_FAIL) )
1584  01b5 b62b          	ld	a,_MTC_Status
1585  01b7 a506          	bcp	a,#6
1586  01b9 2707          	jreq	L515
1587                     ; 812 				StartUpStatus = STARTUP_IDLE;
1589  01bb 3f00          	clr	L3_StartUpStatus
1590                     ; 813 				dev_driveStop();
1592  01bd ad16          	call	_dev_driveStop
1594                     ; 814 				return FUNCTION_ERROR;
1596  01bf a602          	ld	a,#2
1599  01c1 81            	ret	
1600  01c2               L515:
1601                     ; 819 	return FUNCTION_RUNNING;
1603  01c2 4f            	clr	a
1606  01c3 81            	ret	
1632                     ; 822 MC_FuncRetVal_t dev_driveRun(void)
1632                     ; 823 { 
1633                     	switch	.text
1634  01c4               _dev_driveRun:
1638                     ; 824 	if( ((MTC_Status & MTC_OVER_CURRENT_FAIL) == MTC_OVER_CURRENT_FAIL) ||
1638                     ; 825 		((MTC_Status & MTC_MOTOR_STALLED) == MTC_MOTOR_STALLED) )
1640  01c4 7204002b05    	btjt	_MTC_Status,#2,L345
1642  01c9 7209002b05    	btjf	_MTC_Status,#4,L145
1643  01ce               L345:
1644                     ; 827 		dev_driveStop();
1646  01ce ad05          	call	_dev_driveStop
1648                     ; 828 		return FUNCTION_ERROR;
1650  01d0 a602          	ld	a,#2
1653  01d2 81            	ret	
1654  01d3               L145:
1655                     ; 830 	return FUNCTION_RUNNING;
1657  01d3 4f            	clr	a
1660  01d4 81            	ret	
1688                     ; 833 MC_FuncRetVal_t dev_driveStop(void)
1688                     ; 834 {
1689                     	switch	.text
1690  01d5               _dev_driveStop:
1694                     ; 835 	vtimer_KillTimer(DEV_DUTY_UPDATE_TIMER);
1696  01d5 a605          	ld	a,#5
1697  01d7 cd0000        	call	_vtimer_KillTimer
1699                     ; 836 	StopMotor();
1701  01da cd0894        	call	_StopMotor
1703                     ; 840 	*pcounter_reg = 0;
1705  01dd 5f            	clrw	x
1706  01de 92cf0a        	ldw	[L51_pcounter_reg.w],x
1707                     ; 843 	if (g_pBLDC_Struct->pBLDC_Var->bToggleMode)
1709  01e1 92ce03        	ldw	x,[_g_pBLDC_Struct.w]
1710  01e4 e615          	ld	a,(21,x)
1711  01e6 2709          	jreq	L555
1712                     ; 845 		g_pBLDC_Struct->pBLDC_Var->hTarget_rotor_speed = -g_pBLDC_Struct->pBLDC_Var->hTarget_rotor_speed;
1714  01e8 9093          	ldw	y,x
1715  01ea 90ee04        	ldw	y,(4,y)
1716  01ed 9050          	negw	y
1717  01ef ef04          	ldw	(4,x),y
1718  01f1               L555:
1719                     ; 847 	return FUNCTION_ENDED;
1721  01f1 a601          	ld	a,#1
1724  01f3 81            	ret	
1748                     ; 850 MC_FuncRetVal_t dev_driveWait(void)
1748                     ; 851 {
1749                     	switch	.text
1750  01f4               _dev_driveWait:
1754                     ; 871 		return FUNCTION_ENDED;
1756  01f4 a601          	ld	a,#1
1759  01f6 81            	ret	
1788                     ; 875 void dev_BLDC_driveUpdate(void)
1788                     ; 876 {
1789                     	switch	.text
1790  01f7               _dev_BLDC_driveUpdate:
1794                     ; 877 	vtimer_SetTimer(DEV_DUTY_UPDATE_TIMER,SPEED_PID_SAMPLING_TIME,&dev_BLDC_driveUpdate);
1796  01f7 ae01f7        	ldw	x,#_dev_BLDC_driveUpdate
1797  01fa 89            	pushw	x
1798  01fb ae0005        	ldw	x,#5
1799  01fe 89            	pushw	x
1800  01ff a605          	ld	a,#5
1801  0201 cd0000        	call	_vtimer_SetTimer
1803  0204 5b04          	addw	sp,#4
1804                     ; 880 			g_pBLDC_Struct->pBLDC_Var->hDuty_cycle = Set_Duty(*pDutyCycleCounts_reg);
1806  0206 92ce08        	ldw	x,[L71_pDutyCycleCounts_reg.w]
1807  0209 cd0ade        	call	_Set_Duty
1809  020c 91ce03        	ldw	y,[_g_pBLDC_Struct.w]
1810  020f 90ef06        	ldw	(6,y),x
1811                     ; 892 }
1814  0212 81            	ret	
1843                     ; 894 @near @interrupt @svlreg void TIM1_UPD_OVF_TRG_BRK_IRQHandler (void)
1843                     ; 895 {
1844                     	switch	.text
1845  0213               _TIM1_UPD_OVF_TRG_BRK_IRQHandler:
1847  0213 8a            	push	cc
1848  0214 84            	pop	a
1849  0215 a4bf          	and	a,#191
1850  0217 88            	push	a
1851  0218 86            	pop	cc
1852  0219 3b0002        	push	c_x+2
1853  021c be00          	ldw	x,c_x
1854  021e 89            	pushw	x
1855  021f 3b0002        	push	c_y+2
1856  0222 be00          	ldw	x,c_y
1857  0224 89            	pushw	x
1858  0225 be02          	ldw	x,c_lreg+2
1859  0227 89            	pushw	x
1860  0228 be00          	ldw	x,c_lreg
1861  022a 89            	pushw	x
1864                     ; 899 	if( (TIM1->SR1 & BIT7) == BIT7 )
1866  022b 720f52551e    	btjf	21077,#7,L706
1867                     ; 901 		TIM1->SR1 &= (u8)(~BIT7);
1869  0230 721f5255      	bres	21077,#7
1870                     ; 908 				LS_A_PORT->ODR &= (u8)(~LS_A_PIN);
1872  0234 721f500a      	bres	20490,#7
1873                     ; 914 				LS_B_PORT->ODR &= (u8)(~LS_B_PIN);
1875  0238 721d500a      	bres	20490,#6
1876                     ; 920 				LS_C_PORT->ODR &= (u8)(~LS_C_PIN);
1878  023c 721b500a      	bres	20490,#5
1879                     ; 926 		StartUpStatus = STARTUP_IDLE;
1881  0240 3f00          	clr	L3_StartUpStatus
1882                     ; 928 		g_pDevice->regs.r16[VDEV_REG16_HW_ERROR_OCCURRED] |= OVER_CURRENT;
1884  0242 be01          	ldw	x,_g_pDevice
1885  0244 ee02          	ldw	x,(2,x)
1886  0246 e611          	ld	a,(17,x)
1887  0248 aa04          	or	a,#4
1888  024a e711          	ld	(17,x),a
1890  024c 2015          	jra	L116
1891  024e               L706:
1892                     ; 948 		if ((TIM1->SR1 & BIT0) == BIT0)
1894  024e 7201525510    	btjf	21077,#0,L116
1895                     ; 950 			hTim3Cnt++;
1897  0253 be1a          	ldw	x,_hTim3Cnt
1898  0255 5c            	incw	x
1899  0256 bf1a          	ldw	_hTim3Cnt,x
1900                     ; 953 			if (hTim3Cnt >= hTim3Th)
1902  0258 b31c          	cpw	x,_hTim3Th
1903  025a 2503          	jrult	L516
1904                     ; 955 				ComHandler();
1906  025c cd06d7        	call	_ComHandler
1908  025f               L516:
1909                     ; 959 			TIM1->SR1 &= (u8)(~BIT0);
1911  025f 72115255      	bres	21077,#0
1912  0263               L116:
1913                     ; 962 }
1916  0263 85            	popw	x
1917  0264 bf00          	ldw	c_lreg,x
1918  0266 85            	popw	x
1919  0267 bf02          	ldw	c_lreg+2,x
1920  0269 85            	popw	x
1921  026a bf00          	ldw	c_y,x
1922  026c 320002        	pop	c_y+2
1923  026f 85            	popw	x
1924  0270 bf00          	ldw	c_x,x
1925  0272 320002        	pop	c_x+2
1926  0275 80            	iret	
1958                     ; 964 void Application_ADC_Manager( void )
1958                     ; 965 {
1959                     	switch	.text
1960  0276               _Application_ADC_Manager:
1964                     ; 966 	vtimer_SetTimer(ADC_SAMPLE_TIMER,ADC_SAMPLE_TIMEOUT,&Application_ADC_Manager);
1966  0276 ae0276        	ldw	x,#_Application_ADC_Manager
1967  0279 89            	pushw	x
1968  027a ae000a        	ldw	x,#10
1969  027d 89            	pushw	x
1970  027e a608          	ld	a,#8
1971  0280 cd0000        	call	_vtimer_SetTimer
1973  0283 5b04          	addw	sp,#4
1974                     ; 968 	GetCurrent();
1976  0285 ad0c          	call	_GetCurrent
1978                     ; 969 	GetSyncUserAdc();
1980  0287 ad32          	call	_GetSyncUserAdc
1982                     ; 970 	GetBusVoltage();
1984  0289 ad33          	call	_GetBusVoltage
1986                     ; 971 	GetTemperature();
1988  028b ad37          	call	_GetTemperature
1990                     ; 972 	GetNeutralPoint();
1992  028d cd0318        	call	_GetNeutralPoint
1994                     ; 973 	GetAsyncUserAdc();
1997                     ; 974 }
2000  0290 cc031f        	jp	_GetAsyncUserAdc
2038                     	switch	.const
2039  0148               L621:
2040  0148 000f4240      	dc.l	1000000
2041  014c               L031:
2042  014c 00e4c000      	dc.l	14991360
2043  0150               L231:
2044  0150 00000064      	dc.l	100
2045                     ; 976 void GetCurrent(void)
2045                     ; 977 {
2046                     	switch	.text
2047  0293               _GetCurrent:
2049  0293 89            	pushw	x
2050       00000002      OFST:	set	2
2053                     ; 979 	disableInterrupts();
2056  0294 9b            	sim	
2058                     ; 980 	hVal = ADC_Buffer[ADC_CURRENT_INDEX];
2061  0295 be35          	ldw	x,_ADC_Buffer
2062  0297 1f01          	ldw	(OFST-1,sp),x
2063                     ; 981 	enableInterrupts();
2066  0299 9a            	rim	
2068                     ; 983 	BLDC_Set_Current_measured((u16)(ADC_TOMILLIAMP(hVal)/100));
2071  029a cd0000        	call	c_uitolx
2073  029d ae0148        	ldw	x,#L621
2074  02a0 cd0000        	call	c_lmul
2076  02a3 ae014c        	ldw	x,#L031
2077  02a6 cd0000        	call	c_ludv
2079  02a9 a605          	ld	a,#5
2080  02ab cd0000        	call	c_smul
2082  02ae ae0150        	ldw	x,#L231
2083  02b1 cd0000        	call	c_ludv
2085  02b4 be02          	ldw	x,c_lreg+2
2086  02b6 cd0000        	call	_BLDC_Set_Current_measured
2088                     ; 984 }
2091  02b9 85            	popw	x
2092  02ba 81            	ret	
2129                     ; 986 void GetSyncUserAdc(void)
2129                     ; 987 {
2130                     	switch	.text
2131  02bb               _GetSyncUserAdc:
2133       00000002      OFST:	set	2
2136                     ; 990 	disableInterrupts();
2139  02bb 9b            	sim	
2141                     ; 991 	hSyncUserAdc = ADC_Buffer[ADC_USER_SYNC_INDEX];
2144                     ; 992 	enableInterrupts();
2147  02bc 9a            	rim	
2149                     ; 995 }
2153  02bd 81            	ret	
2177                     ; 1049 	void GetBusVoltage( void )
2177                     ; 1050 	{
2178                     	switch	.text
2179  02be               _GetBusVoltage:
2183                     ; 1051 		BLDC_Set_Bus_Voltage((u16)(BUS_VOLTAGE_VALUE));
2185  02be ae014a        	ldw	x,#330
2187                     ; 1052 	}
2190  02c1 cc0000        	jp	_BLDC_Set_Bus_Voltage
2238                     ; 1056 	void GetTemperature(void)
2238                     ; 1057 	{
2239                     	switch	.text
2240  02c4               _GetTemperature:
2242  02c4 5203          	subw	sp,#3
2243       00000003      OFST:	set	3
2246                     ; 1061 		disableInterrupts();
2249  02c6 9b            	sim	
2251                     ; 1062 		data = ADC_Buffer[ ADC_TEMP_INDEX ];
2254  02c7 be3b          	ldw	x,_ADC_Buffer+6
2255  02c9 1f02          	ldw	(OFST-1,sp),x
2256                     ; 1063 		enableInterrupts();
2259  02cb 9a            	rim	
2261                     ; 1064 		g_pDevice->regs.r8[VDEV_REG8_HEATSINK_TEMPERATURE] = (u8)(data >> 2);
2264  02cc 54            	srlw	x
2265  02cd 54            	srlw	x
2266  02ce 9f            	ld	a,xl
2267  02cf 92ce01        	ldw	x,[_g_pDevice.w]
2268  02d2 e70b          	ld	(11,x),a
2269                     ; 1066 		if (data > NTC_THRESHOLD)
2271  02d4 1e02          	ldw	x,(OFST-1,sp)
2272  02d6 a300eb        	cpw	x,#235
2273  02d9 2516          	jrult	L517
2274                     ; 1068 			g_pDevice->regs.r16[VDEV_REG16_HW_ERROR_OCCURRED] |= HEATSINK_TEMPERATURE;
2276  02db be01          	ldw	x,_g_pDevice
2277  02dd ee02          	ldw	x,(2,x)
2278  02df e611          	ld	a,(17,x)
2279  02e1 aa08          	or	a,#8

⌨️ 快捷键说明

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