|
回复 板凳mayiqing888 的帖子
配置函数如下,帮忙看一下吧
void InitEPwm1Timer()
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // 停止TB计数
EDIS;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm1Regs.TBCTR = 0x0000; // 清除TB计数器
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; // 系统时钟分频系数为0
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV4;
EPwm1Regs.TBCTL.bit.PHSEN = 0;
EPwm1Regs.TBPHS.half.TBPHS = 0;
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.CMPA.half.CMPA = 200;
EPwm1Regs.CMPB = 200;
//**********************输出A比较方式寄存器*******************//
EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; //计数器清零
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; //达到CMPA的值变为低电平。
//**********************输出B比较方式寄存器*******************//
EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET; //计数器清零
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; //达到CMPB的值变为低电平。
EPwm1Regs.TBPRD = 30000; //设定周期
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // 向上计数模式
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // 中断使能选择
EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE; // 使能中断
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; //
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // TB时钟设定
EDIS;
} |
|