Part Number:TMS320F28069
PWM初始化部分:
void InitEPwm2Example() //滞后臂
{
//
// Setup TBCLK
//
EALLOW;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBPRD = period1; // Set timer period
// EPwm2Regs.TBPHS.all = 0;
EPwm2Regs.TBPHS.half.TBPHS = PHS; // Phase is 0
EPwm2Regs.TBPHS.half.TBPHSHR = 0; // Phase is 0
EPwm2Regs.CMPA.half.CMPA=272;
// EPwm2Regs.CMPB = 100;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm2Regs.TBCTR = 0x0000; // Clear counter
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
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.AQCTLB.bit.CAU = AQ_CLEAR;
// EPwm2Regs.AQCTLB.bit.PRD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION;
EPwm2Regs.DBCTL.bit.IN_MODE = 3;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBFED = db; //死区300ns
EPwm2Regs.DBRED = db;
EDIS;
EALLOW;
EPwm2Regs.HRCNFG.all = 0x0;
EPwm2Regs.HRCNFG.bit.EDGMODE = HR_BEP;
EPwm2Regs.HRCNFG.bit.CTLMODE = HR_PHS;
EPwm2Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO;
EPwm2Regs.HRCNFG.bit.SWAPAB=0;
EPwm2Regs.HRCNFG.bit.SELOUTB=0;
EPwm2Regs.HRCNFG.bit.AUTOCONV = 0;
EPwm2Regs.HRPCTL.bit.HRPE = 1;
EPwm2Regs.HRPCTL.bit.TBPHSHRLOADE = 1;
EDIS;
EALLOW;
EPwm2Regs.TZCTL.bit.TZA = 2;
EPwm2Regs.TZCTL.bit.TZB = 2;
EDIS;
}
应用部分:
PID_Value.pidvalue = 100.5;
EPwm2Regs.TBPHS.half.TBPHS = (Uint16) PID_Value.pidvalue;
EPwm2Regs.TBPHS.half.TBPHSHR =( (Uint16) (( (PID_Value.pidvalue – EPwm2Regs.TBPHS.half.TBPHS)*61+0.5))) <<8;
ryan zhao:
HRPWM移相,没有官方例程
,
Green Deng:
额,不好意思我没看出来你的问题是什么?或者要实现什么功能?
,
ryan zhao:
额,就是以上代码配置的HRPWM移相并没有实现,不知道有什么东西没配置。只实现了普通PWM的移相
,
Green Deng:
你好,我会咨询一下其他工程师,看一下代码是否有问题。
,
Green Deng:
高分辨率相移的话,不应该将高分辨率周期启用位 (HRPE) 置1
EPwm2Regs.HRPCTL.bit.HRPE = 0;