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

📄 trigono.dsp

📁 非常实用的AD和pwm的ad公司21990dsp芯片的控制源代码
💻 DSP
字号:
/****************************************************************************************
*                                                                                      *
* Library: Trigonometric Functions Library for Sine, Cosine and Arctangent             *
*                                                                                      *
* File: trigono.dsp                                                                    *
*                                                                                      *
* Description: This module contains various trigonometric functions.                   *
* Purpose    : Library Routines for Trig functions                                     *
*                                                                                      *
* Based on:                                                                            *
*              "Digital Signal Processing Applications using the ADSP2100              *
*	       family: Volume 1" Prentice Hall 1992, chapter 4 pp 51-60                *
*                                                                                      *
* Author     : KU                                                                      *
* Version    : 1.0                                                                     *
* Date       : January 2000                                                            *
* Modification History:    None                                                        *
*                                                                                      *
* Embedded Control Systems                                                             *
* Analog Devices Inc.                                                                  *
****************************************************************************************/

#include <main.h>;

/****************************************************************************************
* Calculate Configuration Register Contents from Parameters                            *
****************************************************************************************/

/* None */

/****************************************************************************************
* Constants Defined in this Module                                                     *
****************************************************************************************/

/* None */

/****************************************************************************************
* Routines Defined in this Module                                                      *
****************************************************************************************/

.global        Sin_;
.global        Cos_;


/****************************************************************************************
* Global Variables Defined in this Module                                              *
****************************************************************************************/

/* None */

/****************************************************************************************
* Local Variables Defined in this Module                                               *
****************************************************************************************/
.section/pm seg_pmcode;

//.var/init24 SIN_COEFF[5] = 0x324000, 0x005300, 0xAACC00, 0x08B700, 0x1CCE00;
.var SIN_COEFF[5] = 0x3240, 0x0053, 0xAACC, 0x08B7, 0x1CCE;
//.var/init24 ATN_COEFF[5] = 0x28BD00, 0x006D00, 0xEF3E00, 0x08C600, 0xFED400;

/****************************************************************************************
*                                                                                      *
* Type: Routine                                                                        *
*                                                                                      *
* Call: call Cos_;                                                                     *
*                                                                                      *
* This function preforms the cosine calculation. It first shifts the angle and then    *
* preforms the equivelent sine calculation.					       *
*                                                                                      *
* INPUTS:      AX0 = x in scaled 1.15 format                                           *
*                                                                                      *
* OUTPUTS:     AX1 = Y in 1.15 format                                                   *
*                                                                                      *
* Modified:    AX1, AY0, AY1, AR, AF, MY0, MX1, MY1, MR, SR, I6                              *
*                                                                                      *
****************************************************************************************/

Cos_:    ar=abs ax0;                   /* abs(x)*/
	     ay0=0x4000;                   /* pi/2 = 0.5 */
	     ay1=0x7fff;                   /* pi = 1.0 */
	     ar=ay0-ar;                    /* pi/2 - |x|*/
	     ay0=ar;                       /* store sign of result in ay0*/
	     ar=abs ar;                    /* abs value for approx  */
	     jump sin_approx;              /* skip to Taylor series */

/****************************************************************************************
*                                                                                      *
* Type: Routine                                                                        *
*                                                                                      *
* Call: call Sin_;                                                                     *
*                                                                                      *
* This function preforms the Sine calculation				               *
*                                                                                      *
* INPUTS:      AX0 = x in scaled 1.15 format                                           *
*	       M5 = 1                                                                  *
*              L5 = 0                                                                  *
*                                                                                      *
* OUTPUTS:     AR = Y in 1.15 format                                                   *
*                                                                                      *
* Modified:    AX1, AY0, AY1, AR, AF, MY0, MX1, MY1, MR, SR, I6, M6, L6                             *
*                                                                                      *
****************************************************************************************/

Sin_:	 

		dis mm;
		 m6=1;
		 l6=0;
		 ay0=0x4000;

		 ay1=0x7fff;                   /* pi = 1 */
	     ar=ax0 and ay1;               /* take |x|  */
	     af=ay0-ar;                    /* pi/2 - |x| check for LHS angle*/
	     if LT ar=ay1-ar;              /* if x > pi/2 x = pi -x */
	     ay0=ax0;                      /* store sign of result in ay0*/

sin_approx:
	     I6=SIN_COEFF;                        /*Pointer to coeff. buffer*/
	     my1=ar;                               /*Coeffs in 4.12 format*/
//	     mf=ar*my1 (rnd), mx1=pm(i5,m5);       /*mf = x**2*/
		 sr=ar*my1 (rnd), mx1=pm(i6,m6);       /*mf = x**2*/
	     mr=mx1*my1 (ss), mx1=pm(i6,m6);       /*mr = c1*x*/
	     cntr=3;
	     do approx1 until ce;
		   //mr=mr+mx1*mf (SS);              /*Do summation */
		   mr=mr+mx1*sr1 (SS);              /*Do summation */
//approx1:           mf=ar*mf (RND), mx1=PM(I5,M5);
					my0=sr1;
approx1:           sr=ar*my0 (rnd), mx1=pm(i6,m6);
//	     mr=mr+mx1*mf (SS);
		 mr=mr+mx1*sr1 (SS);
	     sr=ASHIFT mr1 by 3 (HI);
	     sr=sr or LSHIFT mr0 by 3 (LO);        /*Convert to 1.15 format*/
	     ar=pass sr1;
	     if LT ar=pass ay1;                    /*Saturate if needed*/
	     af=pass ay0;
	     if LT ar=-ar;                         /*Negate output if needed*/
//Patched for C inteface - expects return integer in ax1
		 ax1=ar;
	     rts;

⌨️ 快捷键说明

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