Part Number:TMS320F280039C
TMS320F280039: EPWM3的PWM输出禁用了死区功能,PWM3A和PWM3B两个的占空比设置为不同的值时,发现占空比按CPMA设置的来与CPMB无关,
EPwm3Regs.CMPA.bit.CMPA = 1500;
EPwm3Regs.CMPB.bit.CMPB = 500;设置的CMPB的值的对应管脚的占空比没有变化。
// 事件触发模块寄存器初始化
EPwm3Regs.ETSEL.all = 0x0000; // Disable SOCA to ADC, Disable EPWMx_INT and INTSEL.
//bit15 0: SOCBEN, 0 = disable SOCB
//bit14-12 000: SOCBSEL, don't care
//bit11 0: SOCAEN, 1 = enable SOCA, 0 = disable
//bit10-8 000: SOCASEL, EPWMxSOCA selection, 000 = reserved,
//001 => TBCTR=0, 010 => TBCTR=TBPRD, 011 = reserved
//100 = CMPA inc, 101 = CMPA dec, 110 = CMPB inc, 111 = CMPB dec.
//bit7-4 0000: reserved
//bit3 0: INTEN, EPWMx_INT, 0 = disable interrupt, 1 = enable
//bit2-0 000: INTSEL, 000 = Reserved, 001 -> TBCTR=0;
//010 -> TBCTR=TBPRD; 011 = Reserved; 100 = CMPA Up,
//101 = CMPA Down; 110 = CMPB Up; 111 = CMPB down.
EPwm3Regs.ETPS.all = 0x0000; //
//bit15-14 00: EPWMxSOCB, read-only
//bit13-12 00: SOCBPRD, 00 = disable, 01,10,11=generate EPWMxSOCB pulse on the 1/2/3 event.
//bit11-10 00: EPWMxSOCA, read-only
//bit9-8 00: SOCAPRD, 00 = disable, 01,10,11=generate EPWMxSOCA pulse on the 1/2/3 event.
//bit7-4 0000: reserved
//bit3-2 00: INTCNT, read-only
//bit1-0 00: INTPRD, 00 = disable, 01,10,11=generate EPWMx_INT on the 1/2/3 event.
EALLOW;
EPwm3Regs.TBPRD = 3061-1; //频率19.6k
EPwm3Regs.CMPA.bit.CMPA = 0; //占空比
EPwm3Regs.TBPHS.bit.TBPHS = 0x0000; // Phase is 0
EPwm3Regs.TBCTR = 0x0000; // Clear counter
EPwm3Regs.CMPB.bit.CMPB= 0x0000;
//对其模式PWM频率计算 T_PWM =2 x TBPRD x T_TBCLK
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up down 中央对其模式
EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase loading
EPwm3Regs.TBCTL.bit.SYNCOSEL = 0x0;
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT;
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;
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;
#if 1
//见P54 —–>Figure 31. Configuration Options for the Dead-Band Submodule
//这里采用CPMA做源,PWMxB的输出是PWMxA的取反
EPwm3Regs.DBCTL.bit.IN_MODE = DBA_ALL; //S5 = 0; S4 = 0
EPwm3Regs.DBCTL.bit.OUT_MODE =DB_DISABLE;//DB_FULL_ENABLE;// DB_DISABLE;//DB_FULL_ENABLE; //S1 = 1; S0 = 1
EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;//DB_ACTV_HIC; //S3 = 1; S2 = 0
#endif
//设置PWM输出极性,当TB计数到达CMPA时,PWM输出的高低电平确定
EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;//AQ_SET; 当计数值达到CMPA时PWM模块的动作
EPwm3Regs.AQCTLA.bit.CAD = AQ_NO_ACTION;//AQ_CLEAR; 本程序只有CAU并无CAD除非是中央对齐模式
EPwm3Regs.AQCTLA.bit.ZRO = AQ_SET;//AQ_TOGGLE;//AQ_CLEAR; 自己添加
EPwm3Regs.AQCTLB.bit.CAU =AQ_CLEAR;// AQ_CLEAR;//AQ_SET; 当计数值达到CMPA时PWM模块的动作
EPwm3Regs.AQCTLB.bit.CAD = AQ_NO_ACTION;//AQ_CLEAR; 本程序只有CAU并无CAD除非是中央对齐模式
EPwm3Regs.AQCTLB.bit.ZRO = AQ_SET;//AQ_SET;//AQ_TOGGLE;//AQ_CLEAR; 自己添加
//P57 设置死区, 互补模式下,需要设置死区
EPwm3Regs.DBFED.all = C_MAX_DB; // Dead band duration for FED
EPwm3Regs.DBRED.all = C_MAX_DB; // Dead band duration for RED
EDIS;
Yale Li:
您好,CMPA和CMPB并不是与ePWMA和ePWMB对应的,这两个是比较事件。
您的代码中两路PWM采用的是相同的配置,都使用在上升时的CMPA作为比较事件进行动作。注释中也有相应描述。
另外请您使用我们在C2000WARE中提供的例程。