//Time Base SubModule Register
(*ePWM[n+1]).TBCTL.bit.PRDLD = TB_SHADOW;//SHADOW模式
(*ePWM[n+1]).TBPRD = period-1; //
(*ePWM[n+1]).TBPHS.half.TBPHS = 0; //
(*ePWM[n+1]).TBCTR = 0; //
(*ePWM[n+1]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //增计数模式
(*ePWM[n+1]).TBCTL.bit.PHSEN = TB_ENABLE;//
(*ePWM[n+1]).TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Sync "flow through" mode 0
//These bits select the source of the EPWMxSYNCO signal.
(*ePWM[n+1]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[n+1]).TBCTL.bit.CLKDIV = TB_DIV1; //
// Counter compare submodule registers
(*ePWM[n+1]).CMPA.half.CMPA = period + 10; // Initial value
(*ePWM[n+1]).CMPB = 20; // Initial value
(*ePWM[n+1]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[n+1]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Action Qualifier SubModule Registers
(*ePWM[n+1]).AQCTLA.bit.CAU = AQ_SET;
(*ePWM[n+1]).AQCTLA.bit.CBU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.PRD = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.CBU = AQ_SET;
(*ePWM[n+1]).AQCTLB.bit.CAU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.PRD = AQ_CLEAR;
这里面CMPA的值period + 10,大于了TBPRD的周期值,那么这个比较值还起作用吗?如果不起作用,接下来的AQCTLA的设置是什么功能?如果起作用,其是怎么动作的呢?
Victor Zheng:
PWM的CMPA的值大于周期值因该是无效的。这是哪里来的程序
//Time Base SubModule Register
(*ePWM[n+1]).TBCTL.bit.PRDLD = TB_SHADOW;//SHADOW模式
(*ePWM[n+1]).TBPRD = period-1; //
(*ePWM[n+1]).TBPHS.half.TBPHS = 0; //
(*ePWM[n+1]).TBCTR = 0; //
(*ePWM[n+1]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //增计数模式
(*ePWM[n+1]).TBCTL.bit.PHSEN = TB_ENABLE;//
(*ePWM[n+1]).TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Sync "flow through" mode 0
//These bits select the source of the EPWMxSYNCO signal.
(*ePWM[n+1]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[n+1]).TBCTL.bit.CLKDIV = TB_DIV1; //
// Counter compare submodule registers
(*ePWM[n+1]).CMPA.half.CMPA = period + 10; // Initial value
(*ePWM[n+1]).CMPB = 20; // Initial value
(*ePWM[n+1]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[n+1]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Action Qualifier SubModule Registers
(*ePWM[n+1]).AQCTLA.bit.CAU = AQ_SET;
(*ePWM[n+1]).AQCTLA.bit.CBU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.PRD = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.CBU = AQ_SET;
(*ePWM[n+1]).AQCTLB.bit.CAU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.PRD = AQ_CLEAR;
这里面CMPA的值period + 10,大于了TBPRD的周期值,那么这个比较值还起作用吗?如果不起作用,接下来的AQCTLA的设置是什么功能?如果起作用,其是怎么动作的呢?
Martin Yu:
CMPA肯定不起作用,也许是特意初始化的时候不需要发生比较事件,注意查看下后面是否有对该寄存器进行再次配置的。
//Time Base SubModule Register
(*ePWM[n+1]).TBCTL.bit.PRDLD = TB_SHADOW;//SHADOW模式
(*ePWM[n+1]).TBPRD = period-1; //
(*ePWM[n+1]).TBPHS.half.TBPHS = 0; //
(*ePWM[n+1]).TBCTR = 0; //
(*ePWM[n+1]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //增计数模式
(*ePWM[n+1]).TBCTL.bit.PHSEN = TB_ENABLE;//
(*ePWM[n+1]).TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Sync "flow through" mode 0
//These bits select the source of the EPWMxSYNCO signal.
(*ePWM[n+1]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[n+1]).TBCTL.bit.CLKDIV = TB_DIV1; //
// Counter compare submodule registers
(*ePWM[n+1]).CMPA.half.CMPA = period + 10; // Initial value
(*ePWM[n+1]).CMPB = 20; // Initial value
(*ePWM[n+1]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[n+1]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Action Qualifier SubModule Registers
(*ePWM[n+1]).AQCTLA.bit.CAU = AQ_SET;
(*ePWM[n+1]).AQCTLA.bit.CBU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.PRD = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.CBU = AQ_SET;
(*ePWM[n+1]).AQCTLB.bit.CAU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.PRD = AQ_CLEAR;
这里面CMPA的值period + 10,大于了TBPRD的周期值,那么这个比较值还起作用吗?如果不起作用,接下来的AQCTLA的设置是什么功能?如果起作用,其是怎么动作的呢?
RUOF MA:
回复 Martin Yu:
谢谢两位,它后面的代码是这样的,
// Cycle-by-cycle shutdown mechanism configuration
EALLOW; //=========================================================================== // Define an event (DCAEVT1) based on Comparator 1 Output (*ePWM[n+1]).DCTRIPSEL.bit.DCAHCOMPSEL = DC_COMP1OUT; // DCAH = Comparator 1 output
(*ePWM[n+1]).TZDCSEL.bit.DCAEVT1 = TZ_DCAH_HI; // DCAEVT1 = DCAH high(will become active // as Comparator output goes high)
(*ePWM[n+1]).DCACTL.bit.EVT1SRCSEL = DC_EVT_FLT; // DCAEVT1 = DC_EVT_FLT (filtered)
(*ePWM[n+1]).DCACTL.bit.EVT1FRCSYNCSEL = DC_EVT_ASYNC; // Take async path
// Enable DCAEVT1 as a one-shot source
(*ePWM[n+1]).TZSEL.bit.DCAEVT1 = 1; // Enable One-Shot Trip
// Following code for the sync mechanism based on the same trigger event – COMPxOUT
(*ePWM[n+1]).DCACTL.bit.EVT1SYNCE = 1; // Sync enabled
// What do we want the DCAEVT1 event to do? – Initial Configuration
(*ePWM[n+1]).TZCTL.bit.TZA = TZ_NO_CHANGE; // EPWMxA – no change
(*ePWM[n+1]).TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB – go low
后面只对EPWM2B作用了,难道标红的语句对EPWM2A也有操作吗?求解答,非常感谢
//Time Base SubModule Register
(*ePWM[n+1]).TBCTL.bit.PRDLD = TB_SHADOW;//SHADOW模式
(*ePWM[n+1]).TBPRD = period-1; //
(*ePWM[n+1]).TBPHS.half.TBPHS = 0; //
(*ePWM[n+1]).TBCTR = 0; //
(*ePWM[n+1]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //增计数模式
(*ePWM[n+1]).TBCTL.bit.PHSEN = TB_ENABLE;//
(*ePWM[n+1]).TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Sync "flow through" mode 0
//These bits select the source of the EPWMxSYNCO signal.
(*ePWM[n+1]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[n+1]).TBCTL.bit.CLKDIV = TB_DIV1; //
// Counter compare submodule registers
(*ePWM[n+1]).CMPA.half.CMPA = period + 10; // Initial value
(*ePWM[n+1]).CMPB = 20; // Initial value
(*ePWM[n+1]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[n+1]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Action Qualifier SubModule Registers
(*ePWM[n+1]).AQCTLA.bit.CAU = AQ_SET;
(*ePWM[n+1]).AQCTLA.bit.CBU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.PRD = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.CBU = AQ_SET;
(*ePWM[n+1]).AQCTLB.bit.CAU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.PRD = AQ_CLEAR;
这里面CMPA的值period + 10,大于了TBPRD的周期值,那么这个比较值还起作用吗?如果不起作用,接下来的AQCTLA的设置是什么功能?如果起作用,其是怎么动作的呢?
Johnson Chen1:
回复 RUOF MA:
楼主你好,
这样初始化的目的只是为了保证CMPA和CMPB比较事件发生不了,因此PWM输出将不会翻转,从而PWM输出保持在你希望的状态。
之后程序会根据算法来更新比较值CMPA或者CMPB,
//Time Base SubModule Register
(*ePWM[n+1]).TBCTL.bit.PRDLD = TB_SHADOW;//SHADOW模式
(*ePWM[n+1]).TBPRD = period-1; //
(*ePWM[n+1]).TBPHS.half.TBPHS = 0; //
(*ePWM[n+1]).TBCTR = 0; //
(*ePWM[n+1]).TBCTL.bit.CTRMODE = TB_COUNT_UP; //增计数模式
(*ePWM[n+1]).TBCTL.bit.PHSEN = TB_ENABLE;//
(*ePWM[n+1]).TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Sync "flow through" mode 0
//These bits select the source of the EPWMxSYNCO signal.
(*ePWM[n+1]).TBCTL.bit.HSPCLKDIV = TB_DIV1;
(*ePWM[n+1]).TBCTL.bit.CLKDIV = TB_DIV1; //
// Counter compare submodule registers
(*ePWM[n+1]).CMPA.half.CMPA = period + 10; // Initial value
(*ePWM[n+1]).CMPB = 20; // Initial value
(*ePWM[n+1]).CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWAMODE = CC_SHADOW;
(*ePWM[n+1]).CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
(*ePWM[n+1]).CMPCTL.bit.SHDWBMODE = CC_SHADOW;
// Action Qualifier SubModule Registers
(*ePWM[n+1]).AQCTLA.bit.CAU = AQ_SET;
(*ePWM[n+1]).AQCTLA.bit.CBU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLA.bit.PRD = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.CBU = AQ_SET;
(*ePWM[n+1]).AQCTLB.bit.CAU = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.ZRO = AQ_CLEAR;
(*ePWM[n+1]).AQCTLB.bit.PRD = AQ_CLEAR;
这里面CMPA的值period + 10,大于了TBPRD的周期值,那么这个比较值还起作用吗?如果不起作用,接下来的AQCTLA的设置是什么功能?如果起作用,其是怎么动作的呢?
Martin Yu:
回复 RUOF MA:
楼至,这段是数字比较模块的初始化配置文件,跟比较寄存器配置(PWM占空比改变)无关,楼主主要找下主循环开始之前的启动动作时是否有对CMPAHR是否有重新赋值的。