文章目录
怎么调整周期频率,怎么调整占空比,怎么调整相位,怎么设置死区,今天做了这些,mark一下。
EPWM实验相关注意事项
一、 EPWM中断配置
//使能对应的寄存器
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event
//配置对应的中断服务函数
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.EPWM1_INT = &epwm1_timer_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
//中断服务函数编写
//清楚标志位
interrupt void epwm1_timer_isr(void)
{
static Uint16 cnt=0;
cnt++;
if(cnt==5000)
{
cnt=0;
LED3_TOGGLE;
}
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.bit.ACK3 = 1;
}
二、 EPWM外设使用
- 周期设置
1.确定工作时钟,通过主频分频得到,HSPCLKDIV和CLKDIV确定分频比后的时钟就是EPWM的工作时钟。 - 计数方式
向上计数,向下计数,先向上计数在向下计数 - 动作方式
计数到0动作、计数到最大值动作、向上计数中到阈值动作、向下计数中道阈值动作
struct AQCTL_BITS { // bits description
Uint16 ZRO:2; // 1:0 Action Counter = Zero
Uint16 PRD:2; // 3:2 Action Counter = Period
Uint16 CAU:2; // 5:4 Action Counter = Compare A up
Uint16 CAD:2; // 7:6 Action Counter = Compare A down
Uint16 CBU:2; // 9:8 Action Counter = Compare B up
Uint16 CBD:2; // 11:10 Action Counter = Compare B down
Uint16 rsvd:4; // 15:12 reserved
}; - 死区设置
输入模式配置、双脉冲死区确定(互补、单独死区设置)、上升沿下降沿死区时间
// Active Low PWMs - Setup Deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HI;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = 2000;
EPwm1Regs.DBFED = 0;