TI中文支持网
TI专业的中文技术问题搜集分享网站

出现了诡异的现象,调试ePWM模块时TBCTR中的值居然超过了TBPRD的值!!!!!

出现了诡异的现象,调试ePWM模块时TBCTR中的值居然超过了TBPRD的值!!!!!

我的配置文件

EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //D2
EPwm1Regs.TBPHS.half.TBPHS = 0x0;
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //D5~D4
EPwm1Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm1Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm1Regs.TBCTL.bit.FREE_SOFT = 0x2; //D15~D14 Free run

EPwm1Regs.TBCTR = 0x0000;

EPwm1Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm1Regs.CMPA.all = 0xFFFF;
EPwm1Regs.CMPB = 0x0; //
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!
EPwm1Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm1Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm1Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm1Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm1Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm1Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm1Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)

//Dead-Band
EPwm1Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm1Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm1Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm1Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm1Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm1Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm1Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm1Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm1Regs.TZSEL.bit.OSHT1 = TZ_DISABLE; //D8
EPwm1Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9 //todo 由于要求是需要在当前脉冲停止以后在停止输出,所以要考虑一下如何处理,这个地方有TZ2,TZ3,TZ4
EPwm1Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm1Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm1Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm1Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm1Regs.TZCLR.bit.INT = 0x1;

EPwm1Regs.TZEINT.bit.CBC = 0x0;
EPwm1Regs.TZEINT.bit.OST = 0x1;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm1Regs.ETSEL.bit.INTEN = 0x1; //D3 使能ePWMx_INT中断
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm1Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm1Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm1Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; //D1~D0 单事件产生中断(单次)
EPwm1Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm1Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm2Regs.TBPHS.half.TBPHS = 0x0;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm2Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm2Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm2Regs.TBCTR = 0x0000;

EPwm2Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm2Regs.CMPA.all = 0xFFFF;
EPwm2Regs.CMPB = 0x0;

EPwm2Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm2Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm2Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm2Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm2Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm2Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm2Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm2Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm2Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm2Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm2Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm2Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm2Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm2Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm2Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm2Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm2Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm2Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm2Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm2Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm2Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm2Regs.TZCLR.bit.INT = 0x1;

EPwm2Regs.TZEINT.bit.CBC = 0x0;
EPwm2Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm2Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm2Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm2Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm2Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm2Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm2Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm2Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm2Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm3Regs.TBPHS.half.TBPHS = 0x0;
EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm3Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm3Regs.TBCTL.bit.PHSDIR = TB_UP; //D13
EPwm3Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm3Regs.TBCTR = 0x0000;

EPwm3Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm3Regs.CMPA.all = 0xFFFF;
EPwm3Regs.CMPB = 0x0;

EPwm3Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm3Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm3Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm3Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm3Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm3Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm3Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm3Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm3Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm3Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm3Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm3Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm3Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm3Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm3Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm3Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm3Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm3Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm3Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm3Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm3Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm3Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm3Regs.TZCLR.bit.INT = 0x1;

EPwm3Regs.TZEINT.bit.CBC = 0x0;
EPwm3Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm3Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm3Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm3Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm3Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm3Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm3Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm3Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm3Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

forever xu:

我的周期运行文件

void PrdUpdate( int32 *pPrd, //Prd对应指针 Uint16 uTon, //Ton时间 直接是对应的寄存器值 volatile struct EPWM_REGS * pPwm1, //PWM volatile struct EPWM_REGS * pPwm2, volatile struct EPWM_REGS * pPwm3){ int32 lTmp1; Uint16 uTmp2;

lTmp1 = _IQdiv(_IQ(1.0),(*pPrd)); //Q24 [1,20) lTmp1 = lTmp1 >> 12; //Q24 -> Q12 lTmp1 = lTmp1 * PERIOD_MAX_FRQ; //Q12 lTmp1 = lTmp1 >> 12; //Q12 -> Q0 uTmp2 = ((Uint32)lTmp1<<1)/(Uint32)3; //todo 需要测试一下运行时间

(*pPwm1).TBPRD = (Uint16)lTmp1; (*pPwm1).CMPA.half.CMPA = (Uint16)lTmp1 – uTon; (*pPwm1).CMPB = uTon;

(*pPwm2).TBPRD = (Uint16)lTmp1; (*pPwm2).CMPA.half.CMPA = (Uint16)lTmp1 – uTon; (*pPwm2).CMPB = uTon; (*pPwm2).TBPHS.half.TBPHS = uTmp2;

(*pPwm3).TBPRD = (Uint16)lTmp1; (*pPwm3).CMPA.half.CMPA = (Uint16)lTmp1 – uTon; (*pPwm3).CMPB = uTon; (*pPwm3).TBPHS.half.TBPHS = uTmp2;}

出现了诡异的现象,调试ePWM模块时TBCTR中的值居然超过了TBPRD的值!!!!!

我的配置文件

EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //D2
EPwm1Regs.TBPHS.half.TBPHS = 0x0;
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //D5~D4
EPwm1Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm1Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm1Regs.TBCTL.bit.FREE_SOFT = 0x2; //D15~D14 Free run

EPwm1Regs.TBCTR = 0x0000;

EPwm1Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm1Regs.CMPA.all = 0xFFFF;
EPwm1Regs.CMPB = 0x0; //
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!
EPwm1Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm1Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm1Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm1Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm1Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm1Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm1Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)

//Dead-Band
EPwm1Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm1Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm1Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm1Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm1Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm1Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm1Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm1Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm1Regs.TZSEL.bit.OSHT1 = TZ_DISABLE; //D8
EPwm1Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9 //todo 由于要求是需要在当前脉冲停止以后在停止输出,所以要考虑一下如何处理,这个地方有TZ2,TZ3,TZ4
EPwm1Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm1Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm1Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm1Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm1Regs.TZCLR.bit.INT = 0x1;

EPwm1Regs.TZEINT.bit.CBC = 0x0;
EPwm1Regs.TZEINT.bit.OST = 0x1;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm1Regs.ETSEL.bit.INTEN = 0x1; //D3 使能ePWMx_INT中断
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm1Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm1Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm1Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; //D1~D0 单事件产生中断(单次)
EPwm1Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm1Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm2Regs.TBPHS.half.TBPHS = 0x0;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm2Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm2Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm2Regs.TBCTR = 0x0000;

EPwm2Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm2Regs.CMPA.all = 0xFFFF;
EPwm2Regs.CMPB = 0x0;

EPwm2Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm2Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm2Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm2Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm2Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm2Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm2Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm2Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm2Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm2Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm2Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm2Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm2Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm2Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm2Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm2Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm2Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm2Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm2Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm2Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm2Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm2Regs.TZCLR.bit.INT = 0x1;

EPwm2Regs.TZEINT.bit.CBC = 0x0;
EPwm2Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm2Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm2Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm2Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm2Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm2Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm2Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm2Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm2Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm3Regs.TBPHS.half.TBPHS = 0x0;
EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm3Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm3Regs.TBCTL.bit.PHSDIR = TB_UP; //D13
EPwm3Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm3Regs.TBCTR = 0x0000;

EPwm3Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm3Regs.CMPA.all = 0xFFFF;
EPwm3Regs.CMPB = 0x0;

EPwm3Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm3Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm3Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm3Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm3Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm3Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm3Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm3Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm3Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm3Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm3Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm3Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm3Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm3Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm3Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm3Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm3Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm3Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm3Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm3Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm3Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm3Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm3Regs.TZCLR.bit.INT = 0x1;

EPwm3Regs.TZEINT.bit.CBC = 0x0;
EPwm3Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm3Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm3Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm3Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm3Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm3Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm3Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm3Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm3Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

forever xu:

回复 forever xu:

请各位大大帮忙!

出现了诡异的现象,调试ePWM模块时TBCTR中的值居然超过了TBPRD的值!!!!!

我的配置文件

EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; //D2
EPwm1Regs.TBPHS.half.TBPHS = 0x0;
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //D5~D4
EPwm1Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm1Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm1Regs.TBCTL.bit.FREE_SOFT = 0x2; //D15~D14 Free run

EPwm1Regs.TBCTR = 0x0000;

EPwm1Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm1Regs.CMPA.all = 0xFFFF;
EPwm1Regs.CMPB = 0x0; //
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!
EPwm1Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm1Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm1Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm1Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm1Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm1Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm1Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm1Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm1Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)

//Dead-Band
EPwm1Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm1Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm1Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm1Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm1Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm1Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm1Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm1Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm1Regs.TZSEL.bit.OSHT1 = TZ_DISABLE; //D8
EPwm1Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9 //todo 由于要求是需要在当前脉冲停止以后在停止输出,所以要考虑一下如何处理,这个地方有TZ2,TZ3,TZ4
EPwm1Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm1Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm1Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm1Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm1Regs.TZCLR.bit.INT = 0x1;

EPwm1Regs.TZEINT.bit.CBC = 0x0;
EPwm1Regs.TZEINT.bit.OST = 0x1;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm1Regs.ETSEL.bit.INTEN = 0x1; //D3 使能ePWMx_INT中断
EPwm1Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm1Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm1Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm1Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; //D1~D0 单事件产生中断(单次)
EPwm1Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm1Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm2Regs.TBPHS.half.TBPHS = 0x0;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm2Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm2Regs.TBCTL.bit.PHSDIR = TB_DOWN; //D13
EPwm2Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm2Regs.TBCTR = 0x0000;

EPwm2Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm2Regs.CMPA.all = 0xFFFF;
EPwm2Regs.CMPB = 0x0;

EPwm2Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm2Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm2Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm2Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm2Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm2Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm2Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm2Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm2Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm2Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm2Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm2Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm2Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm2Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm2Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm2Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm2Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm2Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm2Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm2Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm2Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm2Regs.TZCLR.bit.INT = 0x1;

EPwm2Regs.TZEINT.bit.CBC = 0x0;
EPwm2Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm2Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm2Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm2Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm2Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm2Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm2Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm2Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm2Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

//——————————————————
//—– ePWM2 —————————————-
//——————————————————
//Time-Base
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; //D1~D0
EPwm3Regs.TBCTL.bit.PHSEN = TB_ENABLE; //D2
EPwm3Regs.TBPHS.half.TBPHS = 0x0;
EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW; //D3
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; //D5~D4
EPwm3Regs.TBCTL.bit.SWFSYNC = 0x0; //D6 软件强制同步位,不同步
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; //D9~D7
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1; //D12~D10
EPwm3Regs.TBCTL.bit.PHSDIR = TB_UP; //D13
EPwm3Regs.TBCTL.bit.FREE_SOFT = 0x0; //D15~D14 Free run

EPwm3Regs.TBCTR = 0x0000;

EPwm3Regs.TBPRD = STEPPER_PWM_PRD;
//Counter-Compare
//EPwm1Regs.CMPCTL.all = 0x0000;
EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm3Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm3Regs.CMPA.all = 0xFFFF;
EPwm3Regs.CMPB = 0x0;

EPwm3Regs.AQCSFRC.bit.CSFA = 0x1; //D1~D0
EPwm3Regs.AQCSFRC.bit.CSFB = 0x1; //D3~D2
//Action-Qualifier
EPwm3Regs.AQCTLA.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLA.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLA.bit.CAU = AQ_SET; //D5~D4 递增计数过程等于比较值 输出高 (高压管)
EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR; //D7~D6 递减计数过程等于比较值 输出低 (高压管)
EPwm3Regs.AQCTLA.bit.CBU = AQ_NO_ACTION; //D9~D8 ePWMxA对B不响应
EPwm3Regs.AQCTLA.bit.CBD = AQ_NO_ACTION; //D11~D10 ePWMxA对B不响应

EPwm3Regs.AQCTLB.bit.ZRO = AQ_NO_ACTION; //D1~D0
EPwm3Regs.AQCTLB.bit.PRD = AQ_NO_ACTION; //D3~D2
EPwm3Regs.AQCTLB.bit.CAU = AQ_NO_ACTION; //D5~D4 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CAD = AQ_NO_ACTION; //D7~D6 ePWMxB对A不响应
EPwm3Regs.AQCTLB.bit.CBU = AQ_CLEAR; //D9~D8 递增计数过程等于比较值 输出低 (低管)
EPwm3Regs.AQCTLB.bit.CBD = AQ_SET; //D11~D10 递减计数过程等于比较值 输出高 (低管)
//Action-Qualifier CONTINUOUS Software Force Register CONTINUOUS!

//Dead-Band
EPwm3Regs.DBCTL.all = 0x0000;//禁止芯片自带死区功能
//PWM-Chopper
EPwm3Regs.PCCTL.all = 0x0000;//禁止PWM chopping function
//Trip-Zone
asm(" EALLOW");
EPwm3Regs.TZSEL.bit.CBC1 = TZ_DISABLE;//D0
EPwm3Regs.TZSEL.bit.CBC2 = TZ_DISABLE;//D1
EPwm3Regs.TZSEL.bit.CBC3 = TZ_DISABLE;//D2
EPwm3Regs.TZSEL.bit.CBC4 = TZ_DISABLE;//D3
EPwm3Regs.TZSEL.bit.CBC5 = TZ_DISABLE;//D4
EPwm3Regs.TZSEL.bit.CBC6 = TZ_DISABLE;//D5
EPwm3Regs.TZSEL.bit.OSHT1 = TZ_DISABLE;//D8
EPwm3Regs.TZSEL.bit.OSHT2 = TZ_DISABLE;//D9
EPwm3Regs.TZSEL.bit.OSHT3 = TZ_DISABLE;//D10
EPwm3Regs.TZSEL.bit.OSHT4 = TZ_DISABLE;//D11
EPwm3Regs.TZSEL.bit.OSHT5 = TZ_DISABLE;//D12
EPwm3Regs.TZSEL.bit.OSHT6 = TZ_DISABLE;//D13

EPwm3Regs.TZCTL.bit.TZA = TZ_FORCE_LO;//强制低
EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO;//强制低

EPwm3Regs.TZCLR.bit.INT = 0x1;

EPwm3Regs.TZEINT.bit.CBC = 0x0;
EPwm3Regs.TZEINT.bit.OST = 0x0;//使能TZ中断

asm(" EDIS");
//Event-Trigger
EPwm3Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; //D2~D0 ePWMx_INT中断选择 1为下溢中断
EPwm3Regs.ETSEL.bit.INTEN = 0x0; //D3 使能ePWMx_INT中断
EPwm3Regs.ETSEL.bit.SOCASEL = ET_CTR_ZERO; //D10~D8 EPWM启动A组AD功能保留
EPwm3Regs.ETSEL.bit.SOCAEN = 0x0; //D11 禁止EPWM启动A组AD
EPwm3Regs.ETSEL.bit.SOCBSEL = ET_CTR_PRD; //D14~D12 EPWM启动B组AD功能保留
EPwm3Regs.ETSEL.bit.SOCBEN = 0x0; //D15 禁止EPWM启动B组AD

EPwm3Regs.ETPS.bit.INTPRD = ET_DISABLE; //D1~D0 单事件产生中断(单次)
EPwm3Regs.ETPS.bit.SOCAPRD = ET_DISABLE; //D9~D8 禁止
EPwm3Regs.ETPS.bit.SOCBPRD = ET_DISABLE; //D13~D12 禁止

Eric Ma:

回复 forever xu:

(*pPwm3).TBPRD = (Uint16)lTmp1;

你把改周期寄存器的代码都给屏蔽掉,用固定的周期寄存器测试。

有可能是你修改周期寄存器,把周期改小了,导致显示出现这样的问题。

ERIC

赞(0)
未经允许不得转载:TI中文支持网 » 出现了诡异的现象,调试ePWM模块时TBCTR中的值居然超过了TBPRD的值!!!!!
分享到: 更多 (0)