📄 rmp2cntl.asm
字号:
;=====================================================================================
; File name: RMP2CNTL.ASM
;
; Originator: Digital Control Systems Group
; Texas Instruments
;
; Description:
; This file contains source for a ramp up and ramp down function.
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000 Release Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx. (Peripheral Independant).
;
;
;================================================================================
; Routine Name : RMP2CNTL Routine Type: C Callable.
;
; Description : This module implements a ramp up and ramp down function.
;
; C prototype : void rmp2_calc(RMP2 *p);
;================================================================================
; History Created July 26, 2000.
;
; Definition of RMP2:
;
; typedef struct RMP2{
;
; int max; /* Maximum value of Ramp2 */
; int min; /* Minimum value of Ramp2 */
; int dly; /* Ramp 2 step delay in number of sampling cycles */
; int delay_cntr; /* Counter for ramp 2 step delay */
; int desired; /* Desired value of ramp2 */
; int out; /* Ramp2 output */
; (int (*)(int))rmp2_calc) /* Pointer to the calculation function */
; } ;
;
;================================================================================
ON .set 1
OFF .set 0
;--------------------------------------------------------------------------------
RETURN_ADDRESS_SAVE .set ON
; If this function calls no other functions
; set RETURN_ADDRESS_SAVE to OFF for
; optimization.
;--------------------------------------------------------------------------------
.def _rmp2_calc
;================================================================================
_rmp2_calc:
__RMP2_framesize .set 0001h
;--------------------------------------------------------------------------------
.if (RETURN_ADDRESS_SAVE=ON)
; AR1 = stack pointer (SP)
; AR0 = frame pointer (FP)
; ARP = AR1
POPD *+ ; Save return address from hardware stack onto
; the software stack.
.endif
SAR AR0,*+ ; push AR0 (FP). ARP = AR1
SAR AR1,* ; *SP = SP. ARP = AR1
LAR AR0,#__RMP2_framesize ; FP = size of frame. ARP = AR1
LAR AR0,*0+,AR2 ; Allocate frame. AR0 = *AR1
; AR1 = AR1 + AR0. ARP = AR2
;================================================================================
.if(RETURN_ADDRESS_SAVE=ON)
LAR AR2,#-3
.endif
.if(RETURN_ADDRESS_SAVE=OFF)
LAR AR2,#-2
.endif
;--------------------------------------------------------------------------------
MAR *0+ ; AR2 -> passed parameter
; (i.e. pointer to the structure).
; ARP = AR2. AR2 = AR2 + AR0.
;--------------------------------------------------------------------------------
LAR AR3,* ; AR3 points to the first structure member
; (i.e. AR3 -> Max)
; ARP = AR2.
;--------------------------------------------------------------------------------
LAR AR4,* ,AR4
; ARP = AR4.
; AR4 points to the first structure member
; (i.e.AR4 -> Max)
; AR3-> Max
;--------------------------------------------------------------------------------
ADRK #5 ; ARP = AR4.
; AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
LACC *,AR3 ; Accumulator = Out.
; ARP = AR3. AR3-> Max. AR4-> Out
;--------------------------------------------------------------------------------
ADRK #4 ; Points to Desired
; ARP = AR3. AR3-> Desired AR4-> Out
;--------------------------------------------------------------------------------
SUB *- ; Accumulator = Out - Desired.
; ARP = AR3. AR3-> Delay_cntr. AR4-> Out.
;-------------------------------------------------------------------------------
BCND rmp2_calc_exit, EQ
; ARP = AR3. AR3-> Delay_cntr. AR4-> Out.
; If(out == desired) go to RMP2_calc_exit.
;--------------------------------------------------------------------------------
LACC * ; Accumulator = Delay_cntr.
; ARP = AR3. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
ADD #1 ; Accumulator = Delay_cntr+1.
; ARP = AR3.
; AR3-> Delay_cntr.
; AR4-> Out
;--------------------------------------------------------------------------------
SACL *- ; Delay_cntr =Delay_cntr+1.
; ARP = AR3. AR3-> Dly. AR4-> Out.
;--------------------------------------------------------------------------------
SUB *+ ; Accumulator = Delay_cntr - Dly.
; ARP = AR3. AR3 -> Delay_cntr.
; AR4-> Out.
;--------------------------------------------------------------------------------
BCND rmp2_calc_exit,LT
; ARP = AR3. AR3 -> Delay_cntr. AR4-> Out.
; If (Delay_cntr < Dly),goto RMP2_calc_exit.
;--------------------------------------------------------------------------------
SPLK #0, * ,AR4
; Reset Delay_cntr.
; ARP = AR4. AR3 -> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
RMP2_Chng_Rmp2:
LACC *- ; Accumulator = Out.
; ARP = AR4. AR3-> Delay_cntr. AR4-> Desired.
;--------------------------------------------------------------------------------
SUB *+ ; Accumulator = Out - Desired.
; ARP = AR4. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
BCND RMP2_Inc_Rmp2, LT
; If (Out < Desired) goto INC_RMP2.
; ARP = AR4. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
RMP2_Dec_Rmp2:
LACC * ; Accumulator = Out. AR4-> Out.
; ARP = AR4. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
SUB #1 ; Decrement the contents of Accumulator by one.
; ARP = AR4. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
SACL * ,AR3 ; Decrement Out by one
; ARP = AR3. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
SBRK #2 ; ARP = AR3. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
SUB * ; Accumulator = Out- Min.
; ARP = AR3. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
BCND rmp2_calc_exit ,GEQ
; If(Out >= Min) goto RMP2_calc_exit.
; ARP = AR3. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
LACC * ,AR4 ; Accumulator = Min.
; ARP = AR4. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
SACL * ; Out = Min.
; ARP = AR4. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
B rmp2_calc_exit
; Goto RMP2_calc_exit.
; ARP = AR4. AR3-> Min. AR4-> Out.
;--------------------------------------------------------------------------------
; ARP = AR4. AR3-> Delay_cntr. AR4-> Out.
RMP2_Inc_Rmp2:
LACC * ; Accumulator= Out.
; ARP = AR4. AR3->Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
ADD #1 ; Contents of Accumulator is incremented by one.
; ARP = AR4. AR3->Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
SACL * ,AR3 ; Increment Out by one.
; ARP = AR3. AR3-> Delay_cntr. AR4-> Out.
;--------------------------------------------------------------------------------
SBRK #3 ; ARP = AR3. AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
SUB * ; Accumulator = Out - Max.
; ARP = AR3. AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
BCND rmp2_calc_exit ,LEQ
; If(Out <= Max) goto RMP2_calc_exit.
; ARP = AR3. AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
LACC *,AR4 ; Accumulator = Max.
; ARP = AR4. AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
SACL * ; Max = Out. ARP = AR4. AR3-> Max. AR4-> Out.
;--------------------------------------------------------------------------------
rmp2_calc_exit:
; Retrieve FP and SP of parent function.
MAR * , AR1 ; set ARP = SP before you exit.
SBRK #(__RMP2_framesize+1)
; Deallocate frame, point to saved FP.
.if (RETURN_ADDRESS_SAVE = ON)
LAR AR0, *- ; Restore frame pointer.
PSHD * ; Push return address on Hardware stack.
.endif
.if (RETURN_ADDRESS_SAVE = OFF)
LAR AR0, * ; Restore frame pointer.
.endif
RET ; Return to the Parent Function
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -