这是初始化的程序:
void pwm2_init()
{
EPwm2Regs.TBPRD = 749;
EPwm2Regs.CMPA.half.CMPA = 450;
EPwm2Regs.CMPB = 300;
EPwm2Regs.TBPHS.all = 0; // Set Phase register to zero
EPwm2Regs.TBCTR = 0; // clear TB counter
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;//增减计数模式
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //关闭相位寄存器
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //时钟频率与系统时钟频率相同
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;//CMPA和CMPB的映射寄存器在CTR = Zero时装载
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.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CBD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;
}
主循环里更改CMPA和CMPB,但示波器上显示的占空比还是初始化时的值:
while (1)
{
EPwm2Regs.CMPA.half.CMPA = 700;
EPwm2Regs.CMPB = 50;
}
mangui zhang:
是不是放到while里面重复太快的原因
这是初始化的程序:
void pwm2_init()
{
EPwm2Regs.TBPRD = 749;
EPwm2Regs.CMPA.half.CMPA = 450;
EPwm2Regs.CMPB = 300;
EPwm2Regs.TBPHS.all = 0; // Set Phase register to zero
EPwm2Regs.TBCTR = 0; // clear TB counter
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;//增减计数模式
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE; //关闭相位寄存器
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //时钟频率与系统时钟频率相同
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;//CMPA和CMPB的映射寄存器在CTR = Zero时装载
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.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CBD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;
}
主循环里更改CMPA和CMPB,但示波器上显示的占空比还是初始化时的值:
while (1)
{
EPwm2Regs.CMPA.half.CMPA = 700;
EPwm2Regs.CMPB = 50;
}
chong chen61:
回复 mangui zhang:
它这个不是在计数器等于0的时候装载到CMPA嘛,如果是这个原因的话只会反应比较慢吧