EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
EPwm1Regs.TBSTS.all=0;
EPwm1Regs.TBPHS.half.TBPHS=0;
EPwm1Regs.TBCTR=0;
EPwm1Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
EPwm1Regs.CMPA.half.CMPA =SP/2; //计算结果为3750
EPwm1Regs.CMPB=0;
EPwm1Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
EPwm1Regs.AQCTLB.all=0;
EPwm1Regs.AQSFRC.all=0;
EPwm1Regs.AQCSFRC.all=0;
EPwm1Regs.DBCTL.all=0xb; // EPWMxB is inverted
EPwm1Regs.DBRED=0;
EPwm1Regs.DBFED=0;
EPwm1Regs.TZSEL.all=0;
EPwm1Regs.TZCTL.all=0;
EPwm1Regs.TZEINT.all=0;
EPwm1Regs.TZ**.all=0;
EPwm1Regs.TZCLR.all=0;
EPwm1Regs.TZFRC.all=0;
EPwm1Regs.ETSEL.all=0; // Interrupt when TBCTR = 0x0000
EPwm1Regs.ET**.all=0;
EPwm1Regs.ETCLR.all=0;
EPwm1Regs.ETFRC.all=0;
EPwm1Regs.PCCTL.all=0;
EPwm1Regs.TBCTL.all=0x0010+TBCTLVAL; // Enable Timer
EPwm1Regs.TBPRD=SP;
以上是关于EPWM1模块的配置,epwm2、3、4等如法**制。
1、关于寄存器位定义的问题
EPwm1Regs.TBCTR.all=0;
---
EPwm1Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
(前面那条语句的意思是对该寄存器的所有位写0,那么按照TBCTR寄存器的配置在CTRMODE字段选择的基数模式为增计数。
但后面那条语句中的注释又说明计数方式是增减计数。这是为什么呢?)
EPwm1Regs.CMPCTL.all=0x50; // Immediate mode for CMPA and CMPB
EPwm1Regs.AQCTLA.all=0x60; // EPWMxA = 1 when CTR=CMPA and counter inc
// EPWMxA = 0 when CTR=CMPA and counter dec
EPwm1Regs.DBCTL.all=0xb; // EPWMxB is inverted
这三句配置语句如果按照注释所要实现的功能来看,以CMPCTL、AQCTLA、DBCTL的各位功能,0x50,0x60,0xb分别是
按照不同的起止顺序配置各位,比如有的从低位开始,有的从高位开始。这是为什么呢? |