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

📄 pwm_drv.asm.txt

📁 此源码事有关DSP编程用的
💻 TXT
字号:
;===============================================================
; Filename	:	pwm_drv.asm
; Module Name	:	FC_PWM_DRV
; Initialization Routine: FC_PWM_DRV_INIT
; Description	:	This module uses the duty ratio information and calculates 
;					the compare values for generating PWM outputs. The compare 
;					values are used in the full compare unit in 24x/24xx event 
;					manager(EV). This also allows PWM period modulation.
;
;						|~~~~~~~~~~~~~~~|
; Mfunc_c1	o---->	|		     	|----->o  CMPR1 (EV register)
; Mfunc_c2	o---->	|  FC_PWM_DRV    |----->o  CMPR2 (EV register)
; Mfunc_c3	o---->	|		     	|----->o  CMPR3 (EV register)
; Mfunc_p		o---->	|                	|----->o  T1PER (EV register)
; n_period  	o---->	|_______________|
;=====================================================================;----------------------
; Reference/Prototype
;----------------------
;		.ref FC_PWM_DRV,FC_PWM_DRV_INIT				;function calls
;		.ref Mfunc_c1,Mfunc_c2,Mfunc_c3,Mfunc_p		;Inputs
;		.ref n_period								;Input

;---------------------------------
; Define Related Peripherals
;---------------------------------
		.include "x24x_app.h"

;-------------------------
; Default PWM Period
;-------------------------
PWM_PERIOD	.set	50						; PWM period in uS (20KHz)

;-------------------------
; Global Definitions
;-------------------------
		.def FC_PWM_DRV,FC_PWM_DRV_INIT			;function calls
		.def Mfunc_c1,Mfunc_c2,Mfunc_c3,Mfunc_p	;Inputs
		.def n_period							;Input

;------------
; Variables
;------------
Mfunc_c1	.usect "pwm_drv",1				; Phase 1 mod function Q15
Mfunc_c2	.usect "pwm_drv",1      			; Phase 2 mod function Q15
Mfunc_c3	.usect "pwm_drv",1      			; Phase 3 mod function Q15
Mfunc_p	.usect "pwm_drv",1				; Period mod function Q15
n_period	.usect "pwm_drv",1  				; Norminal period/compare value
m_period	.usect "pwm_drv",1      			; Modulated period

;------------------------------
; Configuration parameters
;------------------------------
		.if x240
T1PER_	.set	PWM_PERIOD*10		; *1000nS/(2*50nS)
T1CON_	.set	1010100001000000b	; Symmetric PWM
DBTCON_	.set	03F8h				; D/B = 1.2uS @ 50nS clk
ACTR_		.set	011001100110b		; 1/3/5 Active Hi, 2/4/6 Active Lo
COMCON_	.set	0000001000000111b	; Compare Control
		.endif

		.if x243
T1PER_	.set	PWM_PERIOD*10		; *1000nS/(2*50nS)
T1CON_	.set	1000100001000000b	; Symmetric PWM
DBTCON_	.set	03ECh				; D/B = 1.2uS @ 50nS clk
ACTR_		.set	011001100110b		; 1/3/5 Active Hi, 2/4/6 Active Lo
COMCON_	.set	1000001000000000b	; Compare Cntl	
		.endif

		.if x2407
T1PER_	.set	PWM_PERIOD*15		; *1000nS/(2*33nS)
T1CON_	.set	1000100001000000b	; Symmetric PWM
DBTCON_	.set	09E8h				; D/B = 1.18uS @ 33nS clk
ACTR_		.set	011001100110b		; 1/3/5 Active Hi, 2/4/6 Active Lo
COMCON_	.set	1000001000000000b	; Compare Cntl	
		.endif

;-------------------
; Initialization
;-------------------
FC_PWM_DRV_INIT
		LDP		#T1PER>>7
		SPLK	#T1PER_,T1PER		
		SPLK	#T1CON_,T1CON
		SPLK	#DBTCON_,DBTCON
		SPLK	#ACTR_,ACTR
		SPLK	#COMCON_,COMCON
		.if x240
		SPLK	#COMCON_+8000h,COMCON
		.endif
		.if x243|x2407
		ldp		#OCRA>>7				; Configure pins
		LACC	OCRA
		OR		#0000111111000000b
		SACL	OCRA
		.endif
		ldp		#n_period
		SPLK	#T1PER_,n_period
		SPLK	#7FFFh,Mfunc_p
		RET

;--------------------
; Driver Routine
;--------------------
FC_PWM_DRV:
		ldp		#Mfunc_p		; modulate period
		LT		Mfunc_p     
		MPY		n_period		; Mfunc_p*n_period/2
		PAC						;
		add		n_period,15		; offset by n_period/2
		SACH	m_period		; save for later reference
		ldp		#T1PER>>7		;
		sach	T1PER			; save
		
		ldp		#Mfunc_c1		; Modulate channel one
		LT		Mfunc_c1
		MPY		m_period		; Mfunc_c1 x m_period/2
		PAC						;
		add		m_period,15		; offset by m_period/2
		ldp		#CMPR1>>7
		SACH	CMPR1			; save

		ldp		#Mfunc_c2		; Modulate channel two
		LT		Mfunc_c2
		MPY		m_period		; Mfunc_c2 x m_period/2
		PAC						;
		add		m_period,15		; offset by m_period/2
		ldp		#CMPR2>>7
		SACH	CMPR2			; save

		ldp		#Mfunc_c3		; modulate channel three
		LT		Mfunc_c3
		MPY		m_period		; Mfunc_c3 x m_period/2
		PAC						;
		add		m_period,15		; offset by m_period/2
		ldp		#CMPR3>>7
		SACH	CMPR3			; save

		RET

⌨️ 快捷键说明

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