以下是我的程序:
#include "math.h"
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
volatile Uint16 Ton = 360; //define on time,稳定工作时Ton=950
Uint16 Tdelay = 180; //还要减小
void InitEPwm1Example(void); //Configure ePWM module
int main(void) {
InitSysCtrl(); // Initialize System Control
InitGpio(); //Initialize GPIO
InitEPwm1Gpio(); //PWM1_L
InitTzGpio();
//Configure ePWM module
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
InitEPwm1Example();
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
EDIS;
//wait for timer0 interrupt
for(;;);
}
void InitEPwm1Example(){
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm1Regs.TBPRD = 9000; // Set timer period
EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm1Regs.TBPHS.half.TBPHS = 0; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// Setup shadow register load on ZERO
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;
// Set Compare values
EPwm1Regs.CMPA.half.CMPA = Ton+Tdelay; // Set compare A value
EPwm1Regs.CMPB = Tdelay; // Set Compare B value
// Set Actions
EPwm1Regs.AQCTLB.bit.CBU = AQ_SET; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Clear PWM1A on event A, up count
// EPwm1Regs.AQCTLA.bit.CBU = AQ_CLEAR; // Set PWM1B on Zero
// EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1B on event B, up count
EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = 0x1; // DCAH = TZ2
EPwm1Regs.TZDCSEL.bit.DCAEVT1 = 0x2; // DCAEVT1 = DCAH high, DCAL don't care;
EPwm1Regs.DCACTL.bit.EVT1SRCSEL = 0x0; // 0 Source Is DCAEVT1 Signal; 1 Source Is DCEVTFILT Signal;
EPwm1Regs.DCACTL.bit.EVT1SYNCE = 0x1; // Take sync path
}
以上程序在LAUNCHXL-F28069M上运行的结果如下。下图是示波器观测的波形,从上往下依次是TZ2(绿色),EPWM1A(深蓝),EPWM1B(浅蓝),可见EPWM1A出现异常现象,没有稳定在0电平,而是有一个1V左右的脉冲。
而注释掉以上程序最后四句关于DC模块的配置,输出波形正常,如下
希望能有大牛帮忙解答这个问题。由于这个异常现象,我无法配置一个EPWM去控制一个桥臂,耽误了项目进度。
PS:我更换过DSP板,供电方式,EPWM2和EPWM3都存在这个问题。