// Configure ePWM1
// Setup TBCLK
EPwm1Regs.TBPRD = EPWM_TIMER_TBPRD; // Set timer period 1500/2 TBCLKs
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Set Compare values
EPwm1Regs.CMPA.half.CMPA = EPWM_CMPAB; // Set compare A value
// EPwm1Regs.CMPB = EPWM_CMPAB; // Set Compare B value
// Setup counter mode
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up down
EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE; // enable phase loading use for sync
EPwm1Regs.TBCTL.bit.PHSDIR=TB_UP;
EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_IN;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV2+TB_DIV4+TB_DIV4; // TBClock ratio = SYSCLKOUT/(2*HSPCLKDIV*
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; // 2^CLKDIV)
// Setup shadowing
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
// EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load on Zero
// EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set PWM1A on event A, up count
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; // Clear PWM1A on event A, down count
// EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; //Clear PWM1B on event A, up count
// EPwm1Regs.AQCTLB.bit.CAD = AQ_SET; // Set PWM1B on event A, down count
// Set DeadBand
EPwm1Regs.DBCTL.bit.IN_MODE=DBA_ALL;
EPwm1Regs.DBCTL.bit.POLSEL=DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.OUT_MODE=DB_FULL_ENABLE;
EPwm1Regs.DBRED=Dbred; // Dead-band rising edge delay
EPwm1Regs.DBFED=Dbfed; // Dead-band falling edge delay
// Set Trip Zone
EPwm1Regs.TZSEL.bit.OSHT1=TZ_ENABLE;
EPwm1Regs.TZCTL.bit.TZA=TZ_FORCE_LO;
EPwm1Regs.TZCTL.bit.TZB=TZ_FORCE_LO;
// Interrupt where we will change the Compare Values
EPwm1Regs.ETSEL.bit.SOCBSEL= ET_CTR_ZERO; // Select start ADC (EPWMxSOCB) on Zero event
EPwm1Regs.ETSEL.bit.SOCBEN= Enable; // Enable
EPwm1Regs.ETPS.bit.SOCBPRD=ET_1ST;
复制代码
主要注意的就是EPWM的死区子模块。由比较器产生A,B个比较信号进入动作限定子模块,并且出来EPWMxA(1)与EPWMxB(1)两路信号,然后进入死区模块。对于死区模块是双输入双输出的,输入为EPWMxA(1)与EPWMxB(1),输出为EPWMxA(2)与EPWMxB(2),其中(2)的信号可以由(1)的其中一个或者两个共同产生。对于我的使用时为了产生SVPWM去控制IPM,因此需要互补信号,只要用EPWMxA(1)去产生EPWMxA(2)与EPWMxB(2)。
|