TI中文支持网
TI专业的中文技术问题搜集分享网站

帮忙看看这单相逆变的程序

期望的输出波形时正弦波,但是输出波形很不理想

以下为程序,求帮忙看看 谢谢。

#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#include"math.h"
#define PRD 7500/2

//实验现象:在ePWM3A、ePWM3B、ePWM4A、ePWM4B输出相互独立的PWM波
void InitEPwm1(void);
void InitEPwm2(void);
void InitEPwm1Gpio(void);
void InitEPwm2Gpio(void);

interrupt void epwm1_isr(void);

int k=0;

int Sin_tab[400]={1888,1915,1941,1968,1994,2021,2047,2073,2100,2126,2152,2178,2204,2230,
2256,2282,2307,2333,2359,2384,2409,2434,2459,2484,2509,2533,2557,2581,2605,
2629,2653,2676,2700,2723,2745,2768,2790,2813,2834,2856,2878,2899,2920,2940,2961,2981,
3001,3020,3040,3059,3078,3096,3114,3132,3150,3167,3184,3200,3216,3232,3247,3360,3373,3385,
3396,3407,3418,3429,3439,3449,3458,3467,3476,3484,3492,3499,3506,3513,3519,3525,3530,3535,
3540,3544,3547,3551,3554,3556,3558,3560,3561,3562,3562,3562,3562,3561,3560,3558,3556,3554,
3551,3547,3544,3540,3535,3530,3525,3519,3513,3506,3499,3492,3484,3476,3467,3458,3449,3439,
3429,3418,3407,3396,3385,3373,3360,3347,3334,3321,3307,3293,3278,3263,3248,3232,3216,3200,
3184,3167,3150,3132,3114,3096,3078,3059,3040,3020,3001,2981,2961,2940,2920,2899,2878,2856,
2834,2813,2790,2768,2745,2723,2700,2676,2653,2629,2605,2581,2557,2533,2509,2484,2459,2434,
2409,2384,2359,2333,2307,2282,2256,2230,2204,2178,2152,2126,2100,2073,2047,2021,1994,1968,
1941,1915,1888,1862,1835,1809,1782,1756,1729,1703,1677,1650,1624,1598,1572,1546,1520,1494,
1468,1443,1417,1391,1366,1341,1316,1291,1266,1241,1217,1193,1169,1145,1121,1097,1074,1050,
1027,1005,982,960,937,916,894,872,851,830,810,789,769,749,730,710,691,672,654,636,618,600,
583,566,550,534,518,502,487,472,457,443,429,416,403,390,377,365,354,343,332,321,311,301,292,
283,274,266,258,251,244,237,231,225,220,215,210,206,203,199,196,194,192,190,189,188,188,188,
189,190,192,194,196,199,203,206,210,215,220,225,231,237,244,251,258,266,274,283,292,301,311,
321,332,343,354,365,377,390,403,416,429,443,457,472,487,502,518,534,550,566,583,600,618,636,
654,672,691,710,730,749,769,789,810,830,851,872,894,916,937,960,982,1005,1027,1050,1074,1097,
1121,1145,1169,1193,1217,1241,1266,1291,1316,1341,1366,1391,1417,1443,1468,1494,1520,1546,1572,
1598,1624,1650,1677,1703,1729,1756,1782,1809,1835,1862,1888,1915};

void main(void)
{
InitSysCtrl(); //系统时钟150M
InitEPwm1Gpio();
InitEPwm2Gpio();

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

EALLOW;
PieVectTable.EPWM1_INT = &epwm1_isr;

EDIS;

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EDIS;

InitEPwm1();
InitEPwm2();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;

IER|= M_INT3; // 使能INT3通道上的中断请求 epwm

PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

//PieCtrlRegs.PIEIER1.bit.INTx6 = 1; //允许AD中断

IER |= M_INT1;

EINT;
ERTM;

for(;;)
{
asm(" NOP");
}

}

void InitEPwm1Gpio(void)
{
EALLOW;
GpioCtrlRegs.GPAPUD.bit.GPIO0=0; //使能上拉
GpioCtrlRegs.GPAMUX1.bit.GPIO0=1; //配置为EPWM1-a功能
GpioCtrlRegs.GPAPUD.bit.GPIO1=0; //使能上拉
GpioCtrlRegs.GPAMUX1.bit.GPIO1=1; //配置为EPWM1-B功能
EDIS;
}

void InitEPwm2Gpio(void)
{
EALLOW;
//配置GPIO2为EPWM2a功能
GpioCtrlRegs.GPAPUD.bit.GPIO2=0; //使能上拉
GpioCtrlRegs.GPAMUX1.bit.GPIO2=1; //配置为EPWM2a功能
GpioCtrlRegs.GPAPUD.bit.GPIO3=0; //使能上拉
GpioCtrlRegs.GPAMUX1.bit.GPIO3=1; //配置为EPWM2b功能
EDIS;
}
void InitEPwm1()
{
EPwm1Regs.TBPRD = PRD; // Period = 2500 TBCLK counts 时间基准周期寄存器
EPwm1Regs.TBPHS.half.TBPHSHR = 0;// Set Phase register to zero HRPWM相位寄存器
EPwm1Regs.TBCTL.bit.CTRMODE = 2; //计数器模式为增减计数模式
EPwm1Regs.TBCTL.bit.PHSEN = 0; // Master module 禁止相位控制
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; //主周期寄存器从映像寄存器选择中加载
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //同步输出选择,用来选择EPWMxSYNCO信号源
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; //设定CMPA为映射模式
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero //在CTR=0 时,加载CMPA
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
EPwm1Regs.CMPA.half.CMPA = 1875;

// set actions for EPWM1A 当计数器等于主CMPA寄存器并且计数递增时动作 EPWM1A 输出为高
EPwm1Regs.AQCTLA.bit.CAD = 2; // 当计数器等于CMPA且计数递减时EPWM1A输出为高

EPwm1Regs.AQCTLA.bit.CBU = 1; // 当计数器等于CMPB且计数递增时EPWMxA输出为低
EPwm1Regs.DBCTL.bit.OUT_MODE = 3; // enable Dead-band module 死区控制输出模块
EPwm1Regs.DBCTL.bit.POLSEL =2; // DB_ACTV_HIC;(2的话为高互补) Active Hi complementary 低互补极性选择控制
EPwm1Regs.DBFED = 200; // FED = 50 TBCLKs 延时时间计算
EPwm1Regs.DBRED = 200; // RED = 50 TBCLKs 501

EPwm1Regs.ETSEL.bit.INTEN=1;
//EPwm1Regs.ETSEL.bit.INTSEL=0x1; //当TBCTR=0时产生中断
EPwm1Regs.ETSEL.bit.INTSEL=0x2; //当TBCTR=TBPRD时产生中断
EPwm1Regs.ETPS.bit.INTPRD=1; //1对1 在第一个事件处产生中断
}

void InitEPwm2()
{
EPwm2Regs.TBPRD = PRD; // Period = 1600 TBCLK counts
EPwm2Regs.TBPHS.half.TBPHS = 0; // Set Phase register to zero
EPwm2Regs.TBCTL.bit.CTRMODE = 2; // Symmetrical mode
EPwm2Regs.TBCTL.bit.PHSEN = 1; // Slave module () ???? )
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = 0; // sync flow-through???
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR=Zero
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR=Zero
EPwm2Regs.CMPA.half.CMPA = 1875;

EPwm2Regs.AQCTLA.bit.CAD = 2;
EPwm2Regs.AQCTLA.bit.CBU = 1; //EPwm2Regs.AQCTLA.bit.CBU = 2; // 当计数器等于CMPB且计数递增时EPWMxA输出为低
//EPwm2Regs.AQCTLA.bit.CAD = 1; // 当计数器等于CMPA且计数递减时EPWMxA输出为高
EPwm2Regs.DBCTL.bit.OUT_MODE = 3; // enable Dead-band module
EPwm2Regs.DBCTL.bit.POLSEL = 2; // Active Hi complementary
EPwm2Regs.DBFED = 200; // FED = 50 TBCLKs
EPwm2Regs.DBRED = 200; // RED = 50 TBCLKs
}
interrupt void epwm1_isr(void)
{
if(k>=400)
k=0;
EPwm1Regs.CMPA.half.CMPA=Sin_tab[k];
EPwm2Regs.CMPA.half.CMPA=Sin_tab[k];
k++;
if(k>=400)
k=0;
EPwm1Regs.CMPB=Sin_tab[k];
EPwm2Regs.CMPB=Sin_tab[k];
k++;
EPwm1Regs.ETCLR.bit.INT=1;
PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}

赞(0)
未经允许不得转载:TI中文支持网 » 帮忙看看这单相逆变的程序
分享到: 更多 (0)