www.pudn.com > 6pathPWMSwave---00.rar > PWMS波.c, change:2007-01-24,size:6124b


FCL		.USECT		".DATA0",1 		;载波频率 
FCH		.USECT		".DATA0",1 
FRL		.USECT		".DATA0",1		;信号频率 
FRH		.USECT		".DATA0",1 
AL		.USECT		".DATA0",1		;调谐度AL=A*1000 
AH		.USECT		".DATA0",1 
N		.USECT		".DATA0",1		;一个周期的脉冲数 
NL		.USECT		".DATA0",1  
NH		.USECT		".DATA0",1 
I		.USECT		".DATA0",1    
T3PR_TEMPL		.USECT		".DATA0",1		;T3周期寄存器的周期 
T3PR_TEMPH		.USECT		".DATA0",1 
DATIOL		.USECT		".DATA0",1		;占空比 
DATIOH		.USECT		".DATA0",1 
DFLAG		.USECT		".DATA0",1		;标记位 
ST0_CON1	.USECT	".DATA0",1			;保存现场时记录ST0 
ST1_CON1    .USECT	".DATA0",1				;保存现场时记录ST1 
 
		 
		.include "LF2407REGS.H" 
		.ref F$$ITOF,F$$DIV,F$$MUL,F$$FTOI,F$$ADD,F$$LTOF,F$$SUB 
		.ref _sin 
		.def _c_int0 
		.sect ".vectors" 
RSVECT		B		_c_int0   
INT1		B		PHANTOM 
INT2		B		GISR2 
 
		.sect ".pvecs" 
PVECTORS		B  		PHANTOM 
				B		PHANTOM   
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM  
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM  
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		PHANTOM 
				B  		PHANTOM 
				B		T3GP_ISR     
				 
		.text 
 
SYSINIT:  
		SETC	INTM				;屏避可屏避中断 
		CLRC	CNF 
		LDP		#0 
		SPLK	#02H,IMR			;使能INT2 
		SPLK	#0FFFFH,IFR			;清中断标志寄存器 
		LDP		#0E0H 
		SPLK	#0E8H,WDCR  
		LDP		#00E0H 
		SPLK	#81FEH,SCSR1		系统初始化 
		RET 
 
PWM_INIT: 
		LDP		#0E1H 
		LACL	MCRC 
		OR		#07EH 
		SACL	MCRC 
		LDP		#DP_EVB 
		SPLK	#0FFFFH,EVBIFRA		;清EVA的所有中断标志 
		SPLK	#0666H,ACTRB		;PWM6,4,2为低有效,PWM5,3,1高有效 
		SPLK	#00H,DBTCONB		;禁止死区控制 
		SPLK	#1FH,CMPR4B		;设置三个比较器初值 
		SPLK	#2FH,CMPR5B 
		SPLK	#3FH,CMPR6B 
		SPLK	#0960H,T3PR			;周寄存器赋初值,可改变正弦波步率 
		LDP		#0 
		SPLK	#0960,T3PR_TEMPL 
		SPLK	#0,T3PR_TEMPH 
		LDP		#DP_EVB 
		SPLK	#0A600H,COMCONB		;使能比较功能 
		SPLK	#0,T3CNT 
		SPLK	#41H,GPTCONB		;TCOMPOE=1,T3PIN=01 
		SPLK	#080H,EVBIMRA		;通用定时器3使能 
		SPLK	#0B4EH,T3CON 
		CLRC	INTM 
		RET 
 
JISUAN: 
		LDP		#0 
		LACL	AL			;调谐度由整型转成浮点型 
		LRLK	AR1,#STACK		;设置STACK指针 
		SETC	SXM 
		CALL	F$$ITOF,AR1		;A=a*1000 
		CLRC	SXM 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		SACL	AL 
		SACH	AH 
		LRLK	AR1,#STACK		;A/2000=0。5*a 
		SETC	SXM 
		LACL	#0 
		SACL	*+ 
		LACL	#44FAH 
		SACL	*+ 
		LACL	AL 
		SACL	*+ 
		LACL	AH 
		SACL	*+ 
		CALL	F$$DIV 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		LACL	AL 
		LACH	AH 
		LACL	T3PR_TEMPL 
		LRLK	AR1,#STACK 
		SETC	SXM				;定时器财期寄存器的值转变为浮点数 
		CALL	F$$ITOF,AR1 
		CLRC	SXM 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		SACL	T3PR_TEMPL 
		SACH	T3PR_TEMPH 
		LACL	FCL				;FC值转成浮点数 
		LRLK	AR1,#STACK 
		SETC	SXM 
		CALL	F$$LTOF,AR1 
		CLRC	SXM 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		SACL	FCL 
		SACH	FCH 
		LACL	FRL				;FR值转成浮点数 
		LRLK	AR1,#STACK 
		SETC	SXM 
		CALL	F$$ITOF,AR1 
		CLRC	SXM 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		SACL	FRL 
		SACH	FRH 
		LRLK	AR1,#STACK			;N=FC/FR 
		LACL	FRL 
		SACL	*+ 
		LACL	FRH 
		SACL	*+ 
		LACL	FCL 
		SACL	*+ 
		LACL	FCH 
		SACL	*+ 
		CALL	F$$DIV 
		MAR 	*- 
		LACC	*-,16 
		ADDS	* 
		SACL	NL 
		SACH	NH				;N为浮点数 
		LRLK	AR1,#STACK 
		SETC	SXM 
		SACL	*+ 
		SACH	*+ 
		CALL	F$$FTOI 
		SACL	N 
		LRLK	AR1,#STACK 
		SACL	*+ 
		LACL	NH 
		SACL	*+ 
		LACL	#0F5C3H			;40C8F5C3H=6。282=2*3。141 
		SACL	*+ 
		LACL	#40C8H 
		SACL	*+ 
		CALL	F$$DIV 
		MAR		*- 
		LACC	*-,16 
		ADDS	* 
		SACL	NL 
		SACH	NH 
		RET 
		 
DATIO: 
		LDP		#0 
		LACL	I				;I由整型转变成浮点数 
		LRLK	AR1,#STACK 
		SETC	SXM 
		CALL	F$$ITOF,AR1 
		CLRC	SXM 
		MAR		*- 
		LACC	*-,16 
		ADDS	*				;结果保存在ACC 
		LRLK	AR1,#STACK			;I*2*3。14/N 
		SACL	*+ 
		SACH	*+ 
		LACL	NL 
		SACL	*+ 
		LACL	NH 
		SACL	*+ 
		CALL	F$$MUL 
		MAR		*- 
		ZALH	*- 
		ADDS	* 
		LRLK	AR1,#STACK			;SIN(I*2*3。14/N) 
		SACL	*+ 
		SACH	*+ 
		CALL	_sin				;结果存在ACC 
		LRLK	AR1,#STACK			;0。5a*sin(I*2*3.14/N) 
		SACL	*+ 
		SACH	*+ 
		LACL	AL 
		SACL	*+ 
		LACL	AH 
		SACL	*+ 
		CALL	F$$MUL 
		MAR		*- 
		ZALH	*- 
		ADDS	*				;结果在ACC 
		LRLK	AR1,#STACK			;D=0。5+A*SIN(I*2*3。14/N) 
		SACL	*+ 
		SACH	*+ 
		LACL	#0 
		SACL	*+ 
		LACL	#3F00H			;3F000000H=0。5 
		SACL	*+ 
		CALL	F$$ADD 
		MAR		*- 
		ZALH	*- 
		ADDS	*				;结果在ACC 
		LRLK	AR1,#STACK 
		SACL	*+ 
		SACH	*+ 
		LACL	T3PR_TEMPL 
		SACL	*+ 
		LACL	T3PR_TEMPH 
		SACL	*+ 
		CALL	F$$MUL 
		MAR		*- 
		ZALH	*- 
		ADDS	*				;结果在ACC 
		LRLK	AR1,#STACK 
		SETC	SXM 
		SACL	*+ 
		SACH	*+ 
		CALL	F$$FTOI,AR1 
		CLRC	SXM				结果在ACC 
		SACL	DATIOL 
		LDP		#0 
		LACL	I 
		SUB		N 
		BCND	NSPWM,GEQ 
		LACC	I 
		ADD		#1 
		SACL	I 
		B		RRET 
 
NSPWM: 
		SPLK	#0,I 
 
RRET: 
		RET 
 
PHANTOM: 
		KICK_DOG 
		RET 
 
GISR2: 
		SST		#0,ST0_CON1			;保存状态寄存器 
		SST		#1,ST1_CON1 
		LDP		#0E0H				;DP指向PIVR所在数据区 
		LACC	PIVR,1					;读EVIVRB,结果左移一位 
		ADD		#PVECTORS			;加偏移量 
		BACC 
 
T3GP_ISR: 
		LDP		#0 
		LACC	DFLAG 
		OR		#1 
		SACL	DFLAG 
		LACL	DATIOL 
		LDP		#DP_EVB 
		SACL	CMPR4B				;更新比较寄存器 
		ADD		#32H 
		SACL	CMPR5B 
		ADD		#32H 
		SACL	CMPR6B 
		LDP		#0 
		LST		#1,ST1_CON1 
		LST		#0,ST0_CON1 
		LDP		#DP_EVB 
		SPLK	#0FFFFH,EVBIFRA 
		CLRC	INTM 
		RET 
		 
_c_int0: 
		CALL	SYSINIT				;系统初始化 
		CALL	PWM_INIT				;初始化产生PWM波的相关模块 
		LDP		#0 
		SPLK	#2710H,FCL				;读入载波频率 
		SPLK	#0,FCH 
		SPLK	#32H,FRL 
		SPLK	#0,FRH 
		SPLK	32H,FRL 
		SPLK	#0,FRH 
		SPLK	#3E8H,AL 
		SPLK	#0,AH 
		SPLK	#0,I 
		SPLK	#1,DFLAG				;设标标位 
		CALL	JISUAN 
 
LOOP: 
		LDP		#0 
		BIT		DFLAG,BIT0 
		BCND	LOOP,NTC				;若标志位不为1则等待 
		LACL	DFLAG					;标志位为1,清标志位 
		AND		#0FFFEH 
		SACL	DFLAG 
		CALL	DATIO					;调用计算占空比子程序 
		B		LOOP 
		END