打印

TMS320F28035 TripZone and Comparator

[复制链接]
3711|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gygp|  楼主 | 2012-9-8 21:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
要实现的任务是,将28035比较器的输出来驱动EPWM1A和EPWM1B实现互补。
两天实现了。代码如下。
比较器初始化相当简单。
void InitCompA(void)
{
EALLOW; // This is needed to write to EALLOW protected registers
AdcRegs.ADCCTL1.bit.ADCBGPWD = 1;
Comp1Regs.COMPCTL.bit.COMPDACEN = 1;
Comp1Regs.COMPCTL.bit.CMPINV = 0;
Comp1Regs.COMPCTL.bit.COMPSOURCE = 0;
Comp1Regs.COMPCTL.bit.SYNCSEL = 1;
Comp1Regs.COMPCTL.bit.QUALSEL = 1;
EDIS; // This is needed to disable write to EALLOW protected registers
Comp1Regs.DACVAL.all = 512;

}
PWM初始化。
EALLOW;
EPwm1Regs.DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT;
EPwm1Regs.DCTRIPSEL.bit.DCBHCOMPSEL = DC_COMP1OUT;
EPwm1Regs.TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI; //010 DCAH = high, DCAL = don't care
EPwm1Regs.TZDCSEL.bit.DCAEVT2 = TZ_DCBH_LOW; //011 DCAL = low, DCAH = don't care
EPwm1Regs.TZDCSEL.bit.DCBEVT1 = TZ_DCAH_HI;
EPwm1Regs.TZDCSEL.bit.DCBEVT2 = TZ_DCAH_LOW;
EPwm1Regs.DCACTL.bit.EVT1SRCSEL = DC_EVT1;
EPwm1Regs.DCACTL.bit.EVT2SRCSEL = DC_EVT2;
EPwm1Regs.DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;
EPwm1Regs.DCACTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;
EPwm1Regs.DCBCTL.bit.EVT1SRCSEL = DC_EVT1;
EPwm1Regs.DCBCTL.bit.EVT2SRCSEL = DC_EVT2;
EPwm1Regs.DCBCTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC;
EPwm1Regs.DCBCTL.bit.EVT2FRCSYNCSEL = DC_EVT_ASYNC;
// Enable DCAEVT1 as a one-shot trip source
// Note: DCxEVT1 events can be defined as one-shot.
// DCxEVT2 events can be defined as cycle-by-cycle.
// EPwm1Regs.TZSEL.bit.DCAEVT1 = 1;
EPwm1Regs.TZSEL.bit.DCAEVT1 = 0;
EPwm1Regs.TZSEL.bit.DCAEVT2 = 0;
EPwm1Regs.TZSEL.bit.DCBEVT1 = 0;
EPwm1Regs.TZSEL.bit.DCBEVT2 = 0;
EPwm1Regs.TZCTL.bit.DCAEVT1 = TZ_FORCE_HI;
EPwm1Regs.TZCTL.bit.DCAEVT2 = TZ_FORCE_LO;
EPwm1Regs.TZCTL.bit.DCBEVT1 = TZ_FORCE_LO;
EPwm1Regs.TZCTL.bit.DCBEVT2 = TZ_FORCE_HI;
EDIS;
主要参考spruge9d。
容易出错的地方是P65图的最上面部分,当然P62和P63部分内容也要仔细阅读。
所谓的CBC方式和OSHT方式没有仔细研究,但是他们到输出PWM是由TZCTL[TZA]等来实现的。
Digital Compare Events 事件也可以直接驱动PWM,但是是通过TZCTL[DCAEVT1/2]来实现的,这是要注意的地方。
思路是这样的,DCAH和DCBH和输入都选择COMP1OUT,产生四个事件,一个事件是DCAEVT1/2,另一个是DCBEVT1/2,然后有,DCAEVT1靠COMP1OUT高触发,DCAEVT2靠COMP1OUT低触发,然后有DACEVT1/2触发ePWM1A/B,不好处是没有死区,下一步想一下如何处理死区。

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

183

主题

8111

帖子

15

粉丝