PWM1的计数器为零时触发AD采样和PWM1和PWM2的计数器同步两个同时存在时,则pwm输出完全乱掉了,请问 是什么原因?

evpt ( 楼主 ) 2018-6-6 08:00:32  显示全部楼层
本帖最后由 一只耳朵怪 于 2018-6-7 10:12 编辑

我用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;

1个回复

szbliy 发表于 2018-6-6 08:06:13
应该是可以设置的,但也没看出来你的代码有什么问题,不知道你说的PWM输出乱了是个具体的什么情况?
另外,是否有在以上的ePWM初始化之前先关闭同步时钟信号(EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; EDIS;),初始化完之后再打开(EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS;)?
如果可以,建议将程序简化以排除其它因素的影响(猜测是某些顺序导致?),或者将整个工程共享出来测试一下。
                                                                         If a post answers your question, please mark it with the "verify answer" button.
回复

举报 使用道具

您需要登录后才可以回帖 登录 | 注册

本版积分规则


关闭

站长推荐上一条 /9 下一条

小黑屋|手机版|Archiver|电子发烧友 ( 粤ICP备14022951号-2 )

GMT+8, 2018-8-17 00:17 , Processed in 1.165465 second(s), 25 queries , Memcache On.

Powered by 电子发烧友网

© 2015 bbs.elecfans.com

微信扫描
快速回复 返回顶部 返回列表