📄 sincosph.asm
字号:
;=====================================================================================
; File name: SINCOSPH.ASM
;
; Originator: Digital Control Systems Group
; Texas Instruments
;
; Description:
; Sine-Cosine generation with phase/magitude/frequency control
;=====================================================================================
; History:
;-------------------------------------------------------------------------------------
; 9-15-2000 Release Rev 1.0
;================================================================================
; Applicability: F240,F241,C242,F243,F24xx. (Peripheral Independent).
;================================================================================
; Routine Name: sincosph_calc Type: C Callable
;
; C prototype : void sincosph_calc(struct SINCOSPH *p);
;
; The struct object is defined in the header file "sincosph.h" as follows:
;
; typedef struct { int phase_cs; /* Input: Phase shift in degree (Q0) */
; int freq_cs; /* Input: Frequency (Q15) */
; int gain_cs; /* Input: Magnitude (Q15) */
; int sg2_freq_max; /* Parameter: Maximum step angle (Q0) */
; int ALPHA_a1; /* Variable: Incremental angle (Q0) */
; int sine_a1; /* Output: Sinusoidal output 1 (Q15) */
; int sine_a2; /* Output: Sinusoidal output 2 (Q15) */
; int (*calc)(); /* Pointer to calculation function */
; } SINCOSPH;
;
;
; Frame Usage Details:
; step | a | b | c | d | e |
;___________|_______|_____________|_________|______|_________|
; FR0 | GPR | STEP_ANGLE2 | ENTRY13 | GPRC | ENTRY13 |
; FR1 | phase | | | | |
;
;================================================================================
.def _sincosph_calc
.ref SINTAB_360 ; Sine look-up table (256 entries)
;================================================================================
__sincosph_calc_framesize .set 0002h
;================================================================================
_sincosph_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,__sincosph_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->phase_cs, AR2->phase_cs
;----------------------------------------------------------------------------------
ADRK #3 ; ARP=AR0, AR0->FR0, AR2->phase_cs
;----------------------------------------------------------------------------------
CLRC SXM ; Turn sign extension mode off
; ARP=AR0, AR0->FR0, AR2->phase_cs
;----------------------------------------------------------------------------------
SETC OVM ; Set overflow mode
; ARP=AR0, AR0->FR0, AR2->phase_cs
;----------------------------------------------------------------------------------
SPM 0 ; Reset product mode
; ARP=AR0, AR0->FR0, AR2->phase_cs
;----------------------------------------------------------------------------------
SPLK #0B6h,* ; FR0 = 0B6h
; ARP=AR0, AR0->FR0, AR2->phase_cs
;----------------------------------------------------------------------------------
LT *+,AR2 ; TREG = FR0 = 0B6h
; ARP=AR0, AR0->FR1, AR2->phase_cs, ARP=AR2
;----------------------------------------------------------------------------------
MPY *+,AR0 ; PREG = 0B6h*phase_cs
; ARP=AR2, AR0->FR1, AR2->freq_cs, ARP=AR0
;----------------------------------------------------------------------------------
PAC ; ACC = 0B6h*phase_cs
; ARP=AR0, AR0->FR1, AR2->freq_cs
;----------------------------------------------------------------------------------
SACL *-,AR2 ; FR1 = phase = 0B6h*phase_cs
; ARP=AR0, AR0->FR0, AR2->freq_cs, ARP=AR2
;----------------------------------------------------------------------------------
LT * ; TREG = freq_cs (Q15)
; ARP=AR2, AR0->FR0, AR2->freq_cs
;----------------------------------------------------------------------------------
ADRK #2 ; ARP=AR2, AR0->FR0, AR2->sg2_freq_max
;----------------------------------------------------------------------------------
MPY *+,AR0 ; PREG = freq_cs*sg2_freq_max (Q15)
; ARP=AR2, AR0->FR0, AR2->ALPHA_a1, ARP=AR0
;----------------------------------------------------------------------------------
PAC ; ACC = freq_cs*sg2_freq_max (Q15)
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
SACH *,1,AR2 ; FR0 = STEP_ANGLE2
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1, ARP=AR2
;----------------------------------------------------------------------------------
SG_a1 ; ARP=AR2, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
LACC *,AR0 ; ACC = ALPHA_a1
; ARP=AR2, AR0->FR0, AR2->ALPHA_a1, ARP=AR0
;----------------------------------------------------------------------------------
ADD *,AR2 ; ACC = ALPHA_a1 + STEP_ANGLE2
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1, ARP=AR2
;----------------------------------------------------------------------------------
SACL * ; ALPHA_a1 = ALPHA_a1 + STEP_ANGLE2
; ARP=AR2, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
LACC *+,8,AR0 ; ACC high = ALPHA_a1/256
; ARP=AR2, AR0->FR0, AR2->sine_a1, ARP=AR0
;----------------------------------------------------------------------------------
SACH * ; FR0 = ENTRY13
; ARP=AR0, AR0->FR0, AR2->sine_a1
;----------------------------------------------------------------------------------
LACC #SINTAB_360 ; ACC = #SINTAB_360
; ARP=AR0, AR0->FR0, AR2->sine_a1
;----------------------------------------------------------------------------------
ADD *+,AR2 ; ACC = #SINTAB_360 + ENTRY13
; ARP=AR0, AR0->FR1, AR2->sine_a1, ARP=AR2
;----------------------------------------------------------------------------------
TBLR * ; sine_a1 = sin(ALPHA_a1) (Q15)
; ARP=AR2, AR0->FR1, AR2->sine_a1
;----------------------------------------------------------------------------------
LT * ; TREG = sine_a1 (Q15)
; ARP=AR2, AR0->FR1, AR2->sine_a1
;----------------------------------------------------------------------------------
SBRK #3 ; ARP=AR2, AR0->FR1, AR2->gain_cs
;----------------------------------------------------------------------------------
MPY * ; PREG = sine_a1*gain_cs (Q30)
; ARP=AR2, AR0->FR1, AR2->gain_cs
;----------------------------------------------------------------------------------
PAC ; ACC = sine_a1*gain_cs (Q30)
; ARP=AR2, AR0->FR1, AR2->gain_cs
;----------------------------------------------------------------------------------
ADRK #3 ; ARP=AR2, AR0->FR1, AR2->sine_a1
;----------------------------------------------------------------------------------
SACH *-,1 ; sine_a1 = sine_a1*gain_cs (Q15)
; ARP=AR2, AR0->FR1, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
SG_a2 ; ARP=AR2, AR0->FR1, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
LACC *,AR0 ; ACC = ALPHA_a1
; ARP=AR2, AR0->FR1, AR2->ALPHA_a1, ARP=AR0
;----------------------------------------------------------------------------------
ADD *- ; ACC = ALPHA_a1 + phase (FR1)
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
SACL * ; FR0 = GPRC = ALPHA_a1 + phase
; ARP=AR, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
LACC *,8 ; ACC = GPRC = ALPHA_a1 + phase
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
SACH * ; FR0 = ENTRY13
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
LACC #SINTAB_360 ; ACC = #SINTAB_360
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1
;----------------------------------------------------------------------------------
ADD *,AR2 ; ACC = #SINTAB_360 + ENTRY13
; ARP=AR0, AR0->FR0, AR2->ALPHA_a1, ARP=AR2
;----------------------------------------------------------------------------------
ADRK #2 ; ARP=AR2, AR0->FR0, AR2->sine_a2
;----------------------------------------------------------------------------------
TBLR * ; sine_a2 = sin(ALPHA_a1+phase) (Q15)
; ARP=AR2, AR0->FR0, AR2->sine_a2
;----------------------------------------------------------------------------------
LT * ; TREG = sine_a2 (Q15)
; ARP=AR2, AR0->FR0, AR2->sine_a2
;----------------------------------------------------------------------------------
SBRK #4 ; ARP=AR2, AR0->FR0, AR2->gain_cs
;----------------------------------------------------------------------------------
MPY * ; PREG = sine_a2*gain_cs (Q30)
; ARP=AR2, AR0->FR0, AR2->gain_cs
;----------------------------------------------------------------------------------
PAC ; ACC = sine_a2*gain_cs (Q30)
; ARP=AR2, AR0->FR0, AR2->gain_cs
;----------------------------------------------------------------------------------
ADRK #4 ; ARP=AR2, AR0->FR0, AR2->sine_a2
;----------------------------------------------------------------------------------
SACH *,1,AR1 ; sine_a2 = sine_a2*gain_cs (Q15)
; ARP=AR2, AR0->FR0, AR2->sine_a2, ARP=AR1
;----------------------------------------------------------------------------------
_sincosph_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
SBRK #(__sincosph_calc_framesize+1)
LAR AR0,*-
PSHD *
RET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -