我用28035实现如下功能: PWM1的计数器为零时触发一路AD采样,为周期时触发另外一路AD采样,同时PWM1和PWM2的计数器是同步的。具体设置见下面。
问题是:PWM1的计数器为零时触发AD采样和PWM1和PWM2的计数器同步两个同时存在时,则pwm输出完全乱掉了,不只是pwm1和pwm2,连pwm3和pwm6都乱掉了,如果注释掉红字的一行或者绿色的三行都能正常运行。就是说pwm1过零时同时触发ad和pwm同步信号就有问题,而单独执行一个就ok,我在手册里没有看到说这两个不能同时设置。
请问上述问题是我设置不对还是别的问题?有没有好的解决办法?
EPwm3Regs.TBPRD = 3124;
EPwm3Regs.TBPHS.half.TBPHS = 0x0000;
EPwm3Regs.TBCTR = 0x0000;
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm3Regs.CMPA.half.CMPA = 1500;
EPwm3Regs.AQCTLB.all = 0x0018;
EPwm6Regs.TBPRD = 3124;
EPwm6Regs.TBPHS.half.TBPHS = 0x0000;
EPwm6Regs.TBCTR = 0x0000;
EPwm6Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm6Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm6Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm6Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm6Regs.CMPA.half.CMPA = 0;
EPwm6Regs.AQCTLB.all = 0x0018;
EPwm1Regs.TBPRD = 1500;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000;
EPwm1Regs.TBCTR = 0x0000;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_PRD;
EPwm1Regs.CMPA.half.CMPA = 0;
EPwm1Regs.CMPB = 0;
EPwm1Regs.AQCTLA.all = 0x0090;
EPwm1Regs.AQCTLB.all = 0x0900;
EPwm1Regs.ETSEL.bit.SOCAEN = 1;
EPwm1Regs.ETSEL.bit.SOCASEL = 1;
EPwm1Regs.ETSEL.bit.SOCBEN = 1;
EPwm1Regs.ETSEL.bit.SOCBSEL = 2;
EPwm1Regs.ETPS.bit.SOCAPRD = 1;
EPwm1Regs.ETPS.bit.SOCBPRD = 1;
EPwm2Regs.TBPRD = 1500;
EPwm2Regs.TBPHS.half.TBPHS = 0x0000;
EPwm2Regs.TBCTR = 0x0000;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
// EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_PRD;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_PRD;
EPwm2Regs.CMPA.half.CMPA = 0;
EPwm2Regs.CMPB = 0;
EPwm2Regs.AQCTLA.all = 0x0090;
EPwm2Regs.AQCTLB.all = 0x0900;