EPwm1Regs.TBPRD = 6000; // Set timer period
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
// Setup TBCLK
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up,增计数模式
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // 禁止相位寄存器加载
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV4; // 预分频系数为2*2=4
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV4; // 预分频系数为2^2=4
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // 双缓冲操作,所有的写操作通过CPU访问映射寄存器
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; //当时间基准计数器等于0(TBCTR=0X0000)时加载
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Setup compare
EPwm1Regs.CMPA.half.CMPA = 3000; //设置比较值
// Set actions
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; //TBCTR与CMPA在up计数时相等使输出置高
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR; //CTR=CAD事件时将EPWM1A置低
EPwm1Regs.AQCTLB.bit.CAU = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLB.bit.CAD = AQ_SET;
// Active Low PWMs - Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;//允许死区对于ePWM1A输出的上升沿延迟
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_LO; //主低模式
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL; //EPWMxA IN是下降边沿和上升沿延迟的输入源
EPwm1Regs.DBRED = 0x3ff; //上升边沿延迟计数,10位计数器
EPwm1Regs.DBFED = 0; //下降边沿延迟计数,10位计数器
EPwm1_DB_Direction = DB_UP;
// Interrupt where we will change the Deadband
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // 使能事件,TBCTR=0X0000
EPwm1Regs.ETSEL.bit.INTEN = 1; // 使能INT中断
EPwm1Regs.ETPS.bit.INTPRD = ET_3RD; // 第三个事件发生时中断 |