原创 DSP28_Example.c

2009-1-13 13:42 3117 4 4 分类: 处理器与DSP
TMDX ALPHA RELEASE?
// Intended for product evaluation purposes?
//?
//###########################################################################?
//?
// FILE: DSP28_Example.c?
//?
// TITLE: DSP28 CPU_Timer example program.?
//?
//###########################################################################?
//?
// Ver | dd mmm yyyy | Who | Description of changes?
// =====|=============|======|===============================================?
// 0.55| 06 May 2002 | S.S. | EzDSP Alpha Release?
// 0.57| 27 May 2002 | L.H. | No change?
//###########################################################################?

// Step 0. Include required header files?
// DSP28_Device.h: device specific definitions #include statements for?
// all of the peripheral .h definition files.?
// DSP28_Example.h is specific for the given example.?

//#include "DSP28_Device.h"?


//void main(void)?
//{?
/*初始化系统*/?
// InitSysCtrl();?

/*关中断*/?
// DINT;?
// IER = 0x0000;?
// IFR = 0x0000;?

/*初始化PIE控制寄存器*/?
// InitPieCtrl();?

/*初始化PIE矢量表*/?
// InitPieVectTable();

/*初始化EV*/?
// InitEv();?

// EINT;?
// ERTM;?

// for(;;)?
// {?
// KickDog();?
// }?

//}?

//实现了SPWM的输出?
// #include "DSP281x_Device.h"?
#include "DSP28_Device.h"?
#include "stdio.h"?
#include "math.h"?
#include "float.h"?
#define NX 404?
#define PI 3.1415925?
float M=0.8;?
int k0=0,h1=0;?
double a[NX];?
void zkb();?
interrupt void eva_T1UFINT_ISR(void);?
unsigned int n=0;?
float q,l,j;?
void main(void)?
{?
InitSysCtrl(); //系统初始化?
DINT; //禁止全局中断?
IER=0x0000;?
IFR=0x0000;?

EALLOW;?
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins?
EDIS;?

InitPieCtrl();?
InitPieVectTable();?

EALLOW; //使能定时器1下益中断?
PieVectTable.T1UFINT=&amt;eva_T1UFINT_ISR;?
EDIS;?

IER|=M_INT2; //开中断2?
// PieCtrlRegs.PIEIER2.bit.INTx6=1; //开下益中断?
PieCtrl.PIEIER2.bit.INTx6=1; //by jjun?
// PieCtrl.PIEIER2.all = M_INT4;?
////////////////////?

while (n<=NX)?
{?
q=(n+0.75); //为消除偶次偕波,减少谐波角度出发,选择从A相3/4周期进行采样?
q=q*2*PI;?
q/=405;?
j=sin(q);?
l=1875*(1+M*j);//M为振幅调制比 //计算占空比表达式?
//if(l>=187&amt;l<=1687)(此处网友设置为错误的)?
if(l>=375&amt;l<=3375)?
a[n]=l;?
else?
{?
if(l>3375)?
a[n]=3375;?
else?
a[n]=375;?
}?

n=n+1;?
}?
//////////////////////////////?


///init_eva?
///////////////////////////////?
EvaRegs.ACTRA.all=0x0666; //比较方式控制器,?
// EvaRegs.DBTCONA.all = 0x0000; // Disable deadband?
EvaRegs.DBTCONA.all = 0x0FBC; //by jjun?
EvaRegs.COMCONA.all = 0xa600; //使能比较操作,选择禁止SVPWM模式?
// EvaRegs.COMCONA.all = 0x8200; //by jjun?
// EvaRegs.COMCONA.all = 0x8600; //by jjun?
EvaRegs.EVAIMRA.all=0x0200;?
//EVAIMRA(EVA的中断屏蔽寄存器A).T1UIINT(通用定时器1的下溢中断使能)?
EvaRegs.EVAIMRB.all=0x0000;?
EvaRegs.EVAIMRC.all=0x0000;?
EvaRegs.EVAIFRA.all=0xffff;//EVAIFRA(EVA的中断标志寄存器.T1UIINT(通用定时器1的下溢中断标志)?
EvaRegs.EVAIFRB.all=0xffff;//写1清除定时器1的下溢中断标志?
EvaRegs.EVAIFRC.all=0xffff;?
EvaRegs.CMPR1=0; //初始化寄存器的值?
EvaRegs.CMPR2=0;?
EvaRegs.CMPR3=0;?

EvaRegs.GPTCONA.all=0x0041;//通用定时控制器。各定时器独立出发逻辑,输出低有效?
//周期必须大于最大的正弦表格值?
EvaRegs.T1PR = 3750; // Timer1 period PWM载波周期为 65536个定标的定时器时钟周期?
//EvaRegs.T1PR = 0xffff;?
//EvaRegs.T1CNT = 937; // Timer1 counter?
EvaRegs.T1CNT = 937;?
//EvaRegs.T1CON.all = 0x0b4e; // 选择模式产生PWM波10?

EvaRegs.T1CON.all = 0x0b4e;?
EINT;?



// return;?
///////////////////////////?
EvaRegs.T1CON.all=EvaRegs.T1CON.all|0x0040; //启动定时器1?


for(;;);?
}?

interrupt void eva_T1UFINT_ISR(void) // EV-A?
{?
int h2;?
int flag;?
flag=(EvaRegs.EVAIFRA.all)&amt;0x0200; //T1UFINT中下益中断标志位置1?
if(flag!=0x0200)?
{?
EINT;?
return;?
}?
else?
{?
if(k0<=NX)?
{?
h1=k0+135; //B相表达式?
if(h1>=404)?
h1=h1-404;?
h2=k0+270; //C相表达式?
if(h2>=404)?
h2=h2-404;?
EvaRegs.CMPR1=a[k0];?
EvaRegs.CMPR2=a[h1]; //更新比较寄存器2的值?
EvaRegs.CMPR3=a[h2]; //更新比较寄存器3的值?
k0=k0+1;?
}?
else?
{?
k0=0;?
}?
}?

EvaRegs.EVAIMRA.bit.T1UFINT=1; //清除中断屏蔽标志?
EvaRegs.EVAIFRA.bit.T1UFINT=1; //清楚中断使能标志?
// PieCtrlRegs.PIEACK.all=0x0002; //响应同组中断?
PieCtrl.PIEACK.all=0x0002;?
EINT; //开全局中断?
}?
//===========================================================================?
// No more.?
//===========================================================================?


文章评论0条评论)

登录后参与讨论
我要评论
0
4
关闭 站长推荐上一条 /2 下一条