#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,h1,h2;
double a[NX];
extern int tp = 1250;
void zkb();
interrupt void eva_T1UFINT_ISR(void);
void main(void){
k0 = 0;
h1 = 0;
h2 = 0;
InitSysCtrl();
DINT; //禁止全局中断
IER=0;
IFR=0;
EALLOW;
// Enable PWM pins
GpioMuxRegs.GPAMUX.all = 0x00FF; // EVA PWM 1-6 pins
// GpioMuxRegs.GPBMUX.all = 0x00FF; // EVB PWM 7-12 pins
EDIS;
InitPieCtrl();
InitPieVectTable();
EALLOW;
PieVectTable.T1UFINT=&eva_T1UFINT_ISR;
EDIS;
IER|=M_INT2;
PieCtrl.PIEIER2.bit.INTx6=1;
InitEv();
zkb();
EvaRegs.T1CON.all=EvaRegs.T1CON.all|0x0040; //启动定时器1
EINT;
while(1)
{
asm("NOP");
}
}
void zkb()
{
unsigned int n=0;
float q,l,j;
while (n<=NX)
{
q=(n+0.75); //为消除偶次偕波,减少谐波角度出发,选择从A相3/4周期进行采样
q=q*2*PI;
q/=405;
j=sin(q);
l=0.5*tp*(1+M*j);//M为调制比 //计算占空比表达式
/* l=1875*(1+M*j);//M为调制比 //计算占空比表达式
if(l>=375&&l<=3375)
a[n]=l;
else
{
if(l>3375)
a[n]=3375;
else
a[n]=375;
}
n=n+1;
*/
if((l>=(tp*0.1))&&(l<=(tp*0.9)))
a[n]=l;
else
{
if(l>(tp*0.9))
a[n]=tp*0.9;
else
a[n]=tp*0.1;
}
n=n+1;
}
}
interrupt void eva_T1UFINT_ISR(void) // EV-A
{
int h2;
int flag;
flag=(EvaRegs.EVAIFRA.all) & 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];
EvaRegs.CMPR3=a[h2];
k0=k0+1;
}
else
{
k0=0;
}
}
EvaRegs.EVAIMRA.bit.T1UFINT=1;
EvaRegs.EVAIFRA.bit.T1UFINT=1;
PieCtrl.PIEACK.all=0x0002;
EINT; //开全局中断
}
此帖出自
小平头技术问答
哈哈,这回答,得急死楼主!
本人不懂,友情帮顶吧
一周热门 更多>