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

📄 rampgen.asm

📁 TI公司24X系列DSP控制无刷直流电机
💻 ASM
字号:
;=====================================================================================
; File name:        RAMPGEN.ASM                      
;                    
; Originator:	Digital Control Systems Group
;			Texas Instruments
;
; Description:                                 
; This module generates ramp output of adjustable gain, frequency and dc offset.
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 09-15-2000	Release Rev 1.00	
; 01-15-2001	Release	Rev 1.10
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx.  (Peripheral Independent).
;================================================================================
; Routine Name: rampgen_calc   					            Type: C Callable
;  
;  C prototype : void rampgen_calc(struct RAMPGEN *p);
;
;        The struct object is defined in the header file "rampgen.h" as follows:
;
; typedef struct { int  rmp_freq; 		/* Input: Ramp frequency (Q15) */	
;			 	   int  step_angle_max;	/* Parameter: Maximum step angle (Q0) */		
;		 	 	   int  angle_rg;		/* Variable: Step angle (Q0) */					  
;				   int  rmp_gain;		/* Input: Ramp gain (Q15) */
;				   int  rmp_out;  	 	/* Output: Ramp signal (Q15) */	
;				   int  rmp_offset;		/* Input: Ramp offset (Q15) */				 
;		  	  	   int  (*calc)();	  	/* Pointer to calculation function */ 
;				 } RAMPGEN;	            
;        
;        Frame Usage Details:
;     step  |     a       |      b       |    c      |  d      |   e     |
;___________|_____________|______________|___________|_________|_________|
;     FR0   |  rmp_freq_p | step_angle_rg|rmp_out_abs|         |         |  
;
;================================================================================
                .def        _rampgen_calc    
;================================================================================
__rampgen_calc_framesize 	.set 	0001h
;================================================================================
_rampgen_calc:
 													; Assume now ARP=AR1
     	POPD	*+									; Keep return address
       	SAR  	AR0,*+								; Keep old frame pointer (FP)
       	SAR   	AR1,*								; Keep old stack pointer (SP)
       	LARK  	AR0,__rampgen_calc_framesize 		; Load AR0 with frame size	
       	LAR   	AR0,*0+,AR0							; AR0->FP0 (new FP), ARP=AR0

;================================================================================
		SBRK	#3		; ARP=AR0, AR0->FR0-3 (1st argument)		
;----------------------------------------------------------------------------------
		LAR		AR2,*	; ARP=AR0, AR0->rmp_freq, AR2->rmp_freq			
;----------------------------------------------------------------------------------
		ADRK	#3		; ARP=AR0, AR0->FR0, AR2->rmp_freq
;----------------------------------------------------------------------------------
		SETC	SXM		; Turn sign extension mode on
						; ARP=AR0, AR0->FR0, AR2->rmp_freq
;----------------------------------------------------------------------------------
		SETC	OVM		; Set overflow mode
						; ARP=AR0, AR0->FR0, AR2->rmp_freq
;----------------------------------------------------------------------------------
 		SPM     0       ; Reset product mode
       					; ARP=AR0, AR0->FR0, AR2->rmp_freq 
;----------------------------------------------------------------------------------
       	MAR     *,AR2   ; ARP=AR2, AR0->FR0, AR2->rmp_freq		
;----------------------------------------------------------------------------------
		LACC	*+,16,AR0 ; ACC = rmp_freq  (Q15)
						; ARP=AR2, AR0->FR0, AR2->step_angle_max, ARP=AR0
;----------------------------------------------------------------------------------
		ABS				; ACC = |rmp_freq|  (Q15)
						; ARP=AR0, AR0->FR0, AR2->step_angle_max		
;----------------------------------------------------------------------------------
		SACH	*		; FR0 = rmp_freq_p = |rmp_freq|  (Q15)
						; ARP=AR0, AR0->FR0, AR2->step_angle_max			
;----------------------------------------------------------------------------------
		LT		*,AR2	; TREG = |rmp_freq|  (Q15)
						; ARP=AR0, AR0->FR0, AR2->step_angle_max, ARP=AR2 	
;----------------------------------------------------------------------------------
		MPY		*+,AR0	; PREG = |rmp_freq|*step_angle_max  (Q15)
						; ARP=AR2, AR0->FR0, AR2->angle_rg, ARP=AR0
;----------------------------------------------------------------------------------
 		PAC				; ACC = |rmp_freq|*step_angle_max  (Q15)
						; ARP=AR0, AR0->FR0, AR2->angle_rg
;----------------------------------------------------------------------------------
		SACH	*,1,AR2	; FR0 = step_angle_rg  (Q0)
						; ARP=AR0, AR0->FR0, AR2->angle_rg, ARP=AR2
;----------------------------------------------------------------------------------
		LACC	*,AR0	; ACC = angle_rg (Q0)
						; ARP=AR2, AR0->FR0, AR2->angle_rg, ARP=AR0
;----------------------------------------------------------------------------------
      	ADD		*,AR2	; ACC = angle_rg + step_angle_rg  (Q0)
      					; ARP=AR0, AR0->FR0, AR2->angle_rg, ARP=AR2
;----------------------------------------------------------------------------------
		SACL	*		; angle_rg = angle_rg + step_angle_rg  (Q0)
						; ARP=AR2, AR0->FR0, AR2->angle_rg
;----------------------------------------------------------------------------------
		LT		*+		; TREG = angle_rg  (Q0)
						; ARP=AR2, AR0->FR0, AR2->rmp_gain
;----------------------------------------------------------------------------------
     	MPY		*+,AR0	; PREG = angle_rg*rmp_gain  (Q15)
						; ARP=AR2, AR0->FR0, AR2->rmp_out, ARP=AR0
;----------------------------------------------------------------------------------
		PAC				; ACC = angle_rg*rmp_gain  (Q15)
						; ARP=AR0, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
		SACH	*,1		; FR0 = rmp_out_abs = angle_rg*rmp_gain  (Q0)
						; ARP=AR0, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
      	LACC	*,AR2	; ACC = rmp_out_abs (Q0)
      					; ARP=AR0, AR0->FR0, AR2->rmp_out, ARP=AR2
;----------------------------------------------------------------------------------
		SACL	*		; rmp_out = rmp_out_abs (Q15)**
      					; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
;**
;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.
;----------------------------------------------------------------------------------
     	SBRK	#4		; ARP=AR2, AR0->FR0, AR2->rmp_freq 
;----------------------------------------------------------------------------------
		LACC	*		; ACC = rmp_freq  (Q15)
						; ARP=AR2, AR0->FR0, AR2->rmp_freq
;----------------------------------------------------------------------------------
      	ADRK	#4		; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
		BCND	RMP_FREQ_POS, GT ; Branch to RMP_FREQ_POS if rmp_freq > 0  	
      	               	; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
      	LACC	*,16	; ACC = rmp_out  (Q15)
      					; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
    	NEG				; ACC = -rmp_out  (Q15)
      					; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
        SACH	*		; rmp_out = -rmp_out  (Q15)
        				; 2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
RMP_FREQ_POS           	; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
		LACC	*+      ; ACC = rmp_out  (Q15)
						; ARP=AR2, AR0->FR0, AR2->rmp_offset
;----------------------------------------------------------------------------------
     	ADD		*-		; ACC = rmp_out + rmp_offset (Q15)
						; ARP=AR2, AR0->FR0, AR2->rmp_out
;----------------------------------------------------------------------------------
		SACL	*,AR1	; rmp_out = rmp_out + rmp_offset (Q15)
						; ARP=AR2, AR0->FR0, AR2->rmp_out, ARP=AR1
;----------------------------------------------------------------------------------
_rampgen_calc_exit:
       	;MAR     *,AR1   ; can be removed if this condition is met on
       	;                ; every path to this code. (i.e., ARP=AR1 here)

        CLRC	OVM
        CLRC	SXM

    	SBRK 	#(__rampgen_calc_framesize+1)
        LAR  	AR0,*-
        PSHD	*
        RET


⌨️ 快捷键说明

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