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

📄 rampgen.asm

📁 TI公司24X系列DSP控制永磁同步电机PMSM
💻 ASM
字号:
;===========================================================================
; File Name:	rampgen.asm
;
; Module Name: 	RAMP_GEN				      
;
; Initialization Routine: RAMP_GEN_INIT
;
; Originator:	Digital Control Systems Group
;			Texas Instruments
;
; Description:	This module generates ramp output of adjustable gain, 
;		frequency and dc offset.
;				|~~~~~~~~~~~~~~~~~|
;	   rmp_gain	o------>|		  |
;	   rmp_offset 	o------>|    RAMP_GEN	  |----->o  rmp_out
;	   rmp_freq	o------>|		  |
;				|_________________|
;
;
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 09-15-2000	Release Rev 1.00	
; 10-06-2000    Release Rev 1.10
;===========================================================================
;(To use this Module, copy this section to main system file)
;		.ref	RAMP_GEN, RAMP_GEN_INIT			;function call
;		.ref	rmp_gain, rmp_offset, rmp_freq		;Inputs
;		.ref	step_angle_max				;Input
;		.ref	rmp_out					;Outputs
;===========================================================================
		.def	RAMP_GEN, RAMP_GEN_INIT			;function call
		.def	rmp_gain, rmp_offset, rmp_freq		;Inputs
		.def	step_angle_max				;Input
		.def	rmp_out					;Output
;===========================================================================
		.include 	"x24x_app.h"  

STEP_ANGLE_RG_MAX	.set	1000	;Corresponds to 305.2Hz for fs=20kHz
					;See related doc for details

alpha_rg	.usect "rampgen",1
step_angle_rg	.usect "rampgen",1
step_angle_max	.usect "rampgen",1
rmp_gain	.usect "rampgen",1
rmp_offset	.usect "rampgen",1
rmp_freq	.usect "rampgen",1
rmp_out		.usect "rampgen",1
rmp_out_abs	.usect "rampgen",1
rmp_freq_p  .usect "rampgen",1


RAMP_GEN_INIT:
		LDP	#alpha_rg
		SPLK	#0, alpha_rg  				
		SPLK	#STEP_ANGLE_RG_MAX, step_angle_max

		SPLK	#3FFFh, rmp_gain	 		
		SPLK	#3FFFh, rmp_offset 		
		SPLK	#3FFFh, rmp_freq	 		
		RET

RAMP_GEN:
		LDP		#rmp_freq
		LACC	rmp_freq,16	; ACC = rmp_freq  (Q15)
		ABS					; ACC = |rmp_freq|  (Q15)
		SACH	rmp_freq_p 	; rmp_freq_p = |rmp_freq|  (Q15)
	
		LT	rmp_freq_p		;Normalized frequency rmp_freq 
						;is in Q15
		MPY	step_angle_max		;Q15 x Q0
		PAC				;Q0 x Q15 = Q15 (32bit)
		SACH	step_angle_rg,1		;Q0 

		LACC	alpha_rg		;Q0
		ADD	step_angle_rg		;Q0+Q0
		SACL	alpha_rg		;Q0

	;scale the output with gain(user specified)
		LT	alpha_rg		;Q0
		MPY	rmp_gain		;Q0 x Q15
		PAC				;P = rmp_gain * alpha_rg
		SACH	rmp_out_abs,1		;Q0
		LACC	rmp_out_abs		;Q0
		SACL	rmp_out			;Q15**
**
;In the last two instructions the variables rmp_out_abs and rmp_out contain 
;the same value which is the result of the preceeding multiply operation.
;Although they have the same value, by representing rmp_out with a 
;different Q format(Q15) than rmp_out_abs(Q0), we have essentially performed
;an implicit normalization(division) operation. The normalized ramp output, 
;rmp_out(in Q15), and the absolute ramp output, rmp_out_abs (in Q0), are 
;related by, 
;rmp_out = rmp_out_abs/7FFFh. 
;The output of this module(rmp_out) is normalized (expressed in Q15) since 
;in many other s/w modules, where this is used as input, require the input 
;be provided in Q15 format.

		SETC	SXM					; Sign extension mode
		SETC	OVM					; Set Overflow mode
		LACC	rmp_freq			; ACC = rmp_freq  (Q15)
		BCND	RMP_FREQ_POS, GT  	; Branch to RMP_FREQ_POS if rmp_freq > 0  	
		LACC	rmp_out,16			; ACC = rmp_out  (Q15)
		NEG							; ACC = -rmp_out  (Q15)
		SACH	rmp_out				; rmp_out = -rmp_out  (Q15) 
RMP_FREQ_POS		

    ;add offset value
		LACC	rmp_out			;Q15
		ADD		rmp_offset		;Q15+Q15
		SACL	rmp_out			;Q15

		RET

⌨️ 快捷键说明

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