#include<DSP2833x_Device.h>
#include<DSP2833x_Examples.h>
#include<math.h>
#define PI 3.1415926
#define SYS_CLCK 150000000
#define DB_Time 200
float M=0.8;
float N=200;
float F_out=50;//The Freque Of Output
int k=0;
void EPwmGpioSet();
void EPwm1Set();
void EPwm2Set();
void EPwm3Set();
interrupt void EPwm1_isr();
interrupt void EPwm2_isr();
interrupt void EPwm3_isr();
void main()
{
InitSysCtrl();
InitXintf16Gpio();
DINT;
InitPieCtrl();
InitPieVectTable();
IER=0x0000;
IFR=0x0000;
EALLOW;
PieVectTable.EPWM1_INT=&EPwm1_isr;
PieVectTable.EPWM2_INT=&EPwm2_isr;
PieVectTable.EPWM3_INT=&EPwm3_isr;
EPwm1Regs.TBPRD=0;
EPwm1Regs.TBCTL.bit.SWFSYNC=1;
EPwm1Set();
EPwm2Set();
EPwm3Set();
EDIS;
PieCtrlRegs.PIECTRL.bit.ENPIE=1;
PieCtrlRegs.PIEIER3.bit.INTx1=1;
PieCtrlRegs.PIEIER3.bit.INTx2=1;
PieCtrlRegs.PIEIER3.bit.INTx3=1;
EINT;
ERTM;
IER=M_INT3;
EPwmGpioSet();
for(;1;)
{
}
}
void EPwmGpioSet()
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO1=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO2=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO3=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO4=1;
GpioCtrlRegs.GPAMUX1.bit.GPIO5=1;
GpioCtrlRegs.GPAPUD.bit.GPIO0=0;
GpioCtrlRegs.GPAPUD.bit.GPIO1=0;
GpioCtrlRegs.GPAPUD.bit.GPIO2=0;
GpioCtrlRegs.GPAPUD.bit.GPIO3=0;
GpioCtrlRegs.GPAPUD.bit.GPIO4=0;
GpioCtrlRegs.GPAPUD.bit.GPIO5=0;
EDIS;
}
void EPwm1Set()
{
EALLOW;
EPwm1Regs.TBPRD= SYS_CLCK/(2*F_out*N);
EPwm1Regs.TBPHS.half.TBPHS=0;
EPwm1Regs.TBCTR=0;
EPwm1Regs.TBCTL.bit.FREE_SOFT=0x3;
EPwm1Regs.TBCTL.bit.PHSDIR=1;
EPwm1Regs.TBCTL.bit.SYNCOSEL=1;
EPwm1Regs.TBCTL.bit.PRDLD=0;
EPwm1Regs.TBCTL.bit.PHSEN=1;
EPwm1Regs.TBCTL.bit.CTRMODE=0x2;
EPwm1Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N)));
EPwm1Regs.CMPCTL.bit.SHDWAMODE=0;
EPwm1Regs.CMPCTL.bit.LOADAMODE=1;
EPwm1Regs.AQCTLA.bit.CAD=0x2;
EPwm1Regs.AQCTLA.bit.CAU=0x1;
EPwm1Regs.AQCTLB.bit.CAD=0x1;
EPwm1Regs.AQCTLB.bit.CAU=0x2;
EPwm1Regs.DBCTL.bit.IN_MODE=0;
EPwm1Regs.DBCTL.bit.POLSEL=0x2;
EPwm1Regs.DBCTL.bit.OUT_MODE=0x3;
EPwm1Regs.DBRED=DB_Time;
EPwm1Regs.DBFED=DB_Time;
EPwm1Regs.ETSEL.bit.INTSEL=1;
EPwm1Regs.ETSEL.bit.INTEN=1;
EPwm1Regs.ETPS.bit.INTPRD=1;
EPwm1Regs.ETCLR.bit.INT=1;
EDIS;
}
void EPwm2Set()
{
EALLOW;
EPwm2Regs.TBPRD= SYS_CLCK/(2*F_out*N);
EPwm2Regs.TBPHS.half.TBPHS=0;
EPwm2Regs.TBCTR=0;
EPwm2Regs.TBCTL.bit.FREE_SOFT=3;
EPwm2Regs.TBCTL.bit.PHSDIR=1;
EPwm2Regs.TBCTL.bit.SYNCOSEL=0;
EPwm2Regs.TBCTL.bit.PRDLD=0;
EPwm2Regs.TBCTL.bit.PHSEN=1;
EPwm2Regs.TBCTL.bit.CTRMODE=2;
EPwm2Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N+0.2/0.3*PI)));
EPwm2Regs.CMPCTL.bit.SHDWAMODE=0;
EPwm2Regs.CMPCTL.bit.LOADAMODE=1;
EPwm2Regs.AQCTLA.bit.CAD=2;
EPwm2Regs.AQCTLA.bit.CAU=1;
EPwm2Regs.AQCTLB.bit.CAD=1;
EPwm2Regs.AQCTLB.bit.CAU=2;
EPwm2Regs.DBCTL.bit.IN_MODE=0;
EPwm2Regs.DBCTL.bit.POLSEL=2;
EPwm2Regs.DBCTL.bit.OUT_MODE=3;
EPwm2Regs.DBRED=DB_Time;
EPwm2Regs.DBFED=DB_Time;
EPwm2Regs.ETSEL.bit.INTSEL=1;
EPwm2Regs.ETSEL.bit.INTEN=1;
EPwm2Regs.ETPS.bit.INTPRD=1;
EPwm2Regs.ETCLR.bit.INT=1;
EDIS;
}
void EPwm3Set()
{
EALLOW;
EPwm3Regs.TBPRD= SYS_CLCK/(2*F_out*N);
EPwm3Regs.TBPHS.half.TBPHS=0;
EPwm3Regs.TBCTR=0;
EPwm3Regs.TBCTL.bit.FREE_SOFT=3;
EPwm3Regs.TBCTL.bit.PHSDIR=1;
EPwm3Regs.TBCTL.bit.SYNCOSEL=0;
EPwm3Regs.TBCTL.bit.PRDLD=0;
EPwm3Regs.TBCTL.bit.PHSEN=1;
EPwm3Regs.TBCTL.bit.CTRMODE=2;
EPwm3Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N-0.2/0.3*PI)));
EPwm3Regs.CMPCTL.bit.SHDWAMODE=0;
EPwm3Regs.CMPCTL.bit.LOADAMODE=1;
EPwm3Regs.AQCTLA.bit.CAD=2;
EPwm3Regs.AQCTLA.bit.CAU=1;
EPwm3Regs.AQCTLB.bit.CAD=1;
EPwm3Regs.AQCTLB.bit.CAU=2;
EPwm3Regs.DBCTL.bit.IN_MODE=0;
EPwm3Regs.DBCTL.bit.POLSEL=2;
EPwm3Regs.DBCTL.bit.OUT_MODE=3;
EPwm3Regs.DBRED=DB_Time;
EPwm3Regs.DBFED=DB_Time;
EPwm3Regs.ETSEL.bit.INTSEL=1;
EPwm3Regs.ETSEL.bit.INTEN=1;
EPwm3Regs.ETPS.bit.INTPRD=1;
EPwm3Regs.ETCLR.bit.INT=1;
EDIS;
}
interrupt void EPwm1_isr()
{
EALLOW;
EPwm1Regs.ETCLR.bit.INT=1;
EDIS;
k++;
if(k==(N-1))k=0;
EPwm1Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N)));
PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}
interrupt void EPwm2_isr()
{
EALLOW;
EPwm2Regs.ETCLR.bit.INT=1;
EDIS;
EPwm2Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N+0.2/0.3*PI)));
PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}
interrupt void EPwm3_isr()
{
EALLOW;
EPwm3Regs.ETCLR.bit.INT=1;
EDIS;
EPwm3Regs.CMPA.half.CMPA=(Uint16)((SYS_CLCK/(2*F_out*N))*M*(sin(k*PI/N-0.2/0.3*PI)));
PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}
上面是我的程序代码,出来的波形有点问题。第二第三相有一部分一直是高电平。效果如图,希望各位大侠帮我排查一下是什么愿意,已经搞了好几天了,晕头转向。不胜感激。
|