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

28335生成带死区PWM的程序运行后自动跳到DSP2833x_DefaultIsr.c

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

mangui zhang:调到非法中断是不是堆栈等设置不合理啊或者指针等的跑飞了

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

xiao li:

回复 mangui zhang:

但是只有POLSEL设置成a不反转b反转程序会停止,设置成其余3个程序都没问题

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

xiao li:

回复 mangui zhang:

那些我都是默认设置没有改过

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

Green Deng:进入interrupt void ILLEGAL_ISR(void)这个中断是因为CPU内核读到了非法指令,之所以会读到非法指令,一般是因为程序跑飞
进入程序后,先单步运行,看看在哪条语句进入了非法中断?
可以参考一下这个帖子:e2echina.ti.com/…/9221

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

xiao li:

回复 Green Deng:

你好,我现在把问题定位到这条语句:EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;

只要将POLSEL设置成A不反转,B反转程序就会跑飞,但我把POLSEL设置成AB都反转、AB都不反转、A反转B不反转时程序都可以正常运行,

并且我运行TI例程Example_2833xEPwmDeadBand中也有将POLSEL设置成A不反转,B反转的语句EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;但这个程序就可以正常运行

#include "DSP28x_Project.h"

void InitEPwm1(void);
void InitEPwm2(void);

#define EPWM1_TIMER_TBPRD750 //PWM周期
#define EPWM1_CMPA 375
#define EPWM1_DB75
#define EPWM2_TIMER_TBPRD 750
#define EPWM2_CMPA 375
#define EPWM2_DB75

void main(void)
{
InitSysCtrl();
InitEPwm1Gpio(); //将引脚配置为EPWM1和EPWM2
InitEPwm2Gpio();

DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();

EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;//关闭EPWM时钟
EDIS;
InitEPwm1();
InitEPwm2();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//打开EPWM时钟
EDIS;

EINT;
for(;;)
{

}
}

//PWM初始化
void InitEPwm1()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD; //设置定时器周期
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm1Regs.TBCTR = 0x0000; //时基计数器清零
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM1频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm1Regs.CMPA.half.CMPA = EPWM1_CMPA; //设置比较寄存器A的值

//设置动作,PWM1A为HIN的信号,PWM1B为LIN的信号
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM1A输出高电平
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM1A输出低电平

EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = EPWM1_DB;
EPwm1Regs.DBFED = EPWM1_DB;
}

void InitEPwm2()
{
//设置时间基准的时钟信号(TBCLK)周期,相位
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //增减计数模式10
EPwm2Regs.TBPRD = EPWM2_TIMER_TBPRD; //设置定时器周期
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //禁止相位加载0
EPwm2Regs.TBPHS.half.TBPHS = 0x0000; //时基相位寄存器的值赋值0,初相0
EPwm2Regs.TBCTR = 0x0000; //时基计数器清零
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;//TBCLK=SYSCLKOUT/1*1=150MHZ,PWM2频率=150MHZ/750=100KHZ;

//设置比较寄存器的阴影寄存器加载条件:时基计数到0或PRD
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO_PRD;

//设置比较寄存器的值
EPwm2Regs.CMPA.half.CMPA = EPWM2_CMPA; //设置比较寄存器A的值

//设置动作,PWM2A为INA的信号,PWM2B为INB的信号
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //递增计数时,发生比较寄存器A匹配时PWM2A输出高电平
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //递增计数时,发生比较寄存器A匹配时PWM2A输出低电平

EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = EPWM2_DB;
EPwm2Regs.DBFED = EPWM2_DB;
}

自己写了个程序生成4路带死区的PWM,但是程序一运行就跳到DSP2833x_DefaultIsr.c中

用EPWM1A输入DB模块生成EPWM1A和EPWM1B 2路PWM

用EPWM2A输入DB模块生成EPWM2A和EPWM2B 2路PWM

现在发现问题出在EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
把 DB_ACTV_HIC换成其他3个,程序都可以一直运行下去,但是设置成DB_ACTV_HIC就不行
#defineDB_ACTV_HI0x0
#defineDB_ACTV_LOC0x1
#defineDB_ACTV_HIC0x2
#defineDB_ACTV_LO0x3
但是我需要互补的PWM,只能用DB_ACTV_HIC,一路反转一路不反转

问题真的很奇怪,程序里我也没使用中断,求大家帮我看下是为什么

Green Deng:

回复 xiao li:

个人认为这不是修改了POLSEL 寄存器的原因。建议你还是看一下程序中是不是有上述参考帖子中的情况以及你的硬件问题。

赞(0)
未经允许不得转载:TI中文支持网 » 28335生成带死区PWM的程序运行后自动跳到DSP2833x_DefaultIsr.c
分享到: 更多 (0)