我的代码如下,开发平台是CCS4,仿真平台是PROTEUS。如果去掉死区代码,可以正常生成波形。搞了很多天了,请大神技术支持帮忙解答。另外一个问题,未设置EPWM2与EPWM3,但两者都有输出,相对于EPWM进行了移相。怎么回事?如何解决?
#include "DSP280x_device.H" #include "DSP280x_Examples.h" #include "DSP280x_Gpio.h" #include "DSP280x_PieVect.h" interrupt void pwm1_isr(); void pwm1_generate(); void main(){ InitSysCtrl();//初始化系统控制 InitPieCtrl(); // InitGpio();//初始化通用端口 InitEPwmGpio();//初始化PWM端口 InitPieCtrl();//初始化中断向量控制 InitPieVectTable();//初始化中断向量表,将需要中断的向量进行函数赋值 // PieVectTable.EPWM1_INT=&pwm1_isr;//对PWM1中断进行处理 pwm1_generate(); while(1){ EPwm1Regs.CMPA.half.CMPA=8000; EPwm1Regs.CMPB = 8000; } } //PWM1中断响应函数 interrupt void pwm1_isr(){ } void pwm1_generate(){ EPwm1Regs.TBPRD = 20000; //设置PERIOD,由于是增减模式,所以PERIOD=2*TBPRD Tpwm=period*sysclock EPwm1Regs.CMPA.half.CMPA=8000; // EPwm1Regs.CMPB = 300; // EPwm1Regs.CMPB = 500; //计数2000时,改变高低电平,用于设置占空比 EPwm1Regs.TBPHS.half.TBPHS = 0; //相位设置为零 EPwm1Regs.TBCTR = 0; //从零开始计数 EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; //增减模式,生成对称波形 EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //关闭相位 EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;//频率加载采用影子式加载 EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;//关闭同步 EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //分频设置 EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;//分频设置 EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;//比较器影子式加载,另一种为立即加载 EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;//增计数至比较器时至低电平 EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;//减计数至比较器时至高电平 // EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; // EPwm1Regs.AQCTLB.bit.CBD = AQ_SET; EPwm1Regs.DBCTL.bit.IN_MODE=DBB_ALL; EPwm1Regs.DBCTL.bit.POLSEL=DB_ACTV_HIC; EPwm1Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE; EPwm1Regs.DBRED=20; EPwm1Regs.DBFED=20; }
Chen Jones:
建议楼主参考TI的官方历程: DeadBand 死区控制历程
C:\ti\controlSUITE\device_support\f2802x\v210\f2802x_examples\epwm_deadband