用TZ引脚接受外部输入过流信号来触发封锁PWM,但是很慢,经过排查,发现同步(Sync)貌似有问题,我用软件给OSHT置1就可以封锁,但是外部触发就是很慢,而且一点外部过流信号消失又会发出PWM,TZ配置如下:
EALLOW;
// CPU Halt Trip
EPwm1Regs.TZSEL.bit.CBC6=0x1;
EPwm2Regs.TZSEL.bit.CBC6=0x1;
EPwm3Regs.TZSEL.bit.CBC6=0x1;
EPwm1Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT
EPwm2Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT
EPwm3Regs.TZSEL.bit.OSHT1 = 1; //enable TZ1 for OSHT
// What do we want the OST/CBC events to do?
// TZA events can force EPWMxA
// TZB events can force EPWMxB
EPwm1Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low
EPwm1Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low
EPwm2Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low
EPwm2Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low
EPwm3Regs.TZCTL.bit.TZA = TZ_FORCE_LO; // EPWMxA will go low
EPwm3Regs.TZCTL.bit.TZB = TZ_FORCE_LO; // EPWMxB will go low
EDIS;
// Clear any spurious OV trip
EPwm1Regs.TZCLR.bit.OST = 1;
EPwm2Regs.TZCLR.bit.OST = 1;
EPwm3Regs.TZCLR.bit.OST = 1;
PWM配置如下:
#define PWM_INIT_MACRO(ch1,ch2,ch3,v) \
/* Setup Sync*/ \
(*ePWM[ch1]).TBCTL.bit.SYNCOSEL = 0; /* Pass through*/ \
(*ePWM[ch2]).TBCTL.bit.SYNCOSEL = 0; /* Pass through*/ \
(*ePWM[ch3]).TBCTL.bit.SYNCOSEL = 0; /* Pass through*/ \
\
/* Allow each timer to be sync'ed*/ \
(*ePWM[ch1]).TBCTL.bit.PHSEN = 1; \
(*ePWM[ch2]).TBCTL.bit.PHSEN = 1; \
(*ePWM[ch3]).TBCTL.bit.PHSEN = 1; \
\
/* Init Timer-Base Period Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).TBPRD = v.PeriodMax; \
(*ePWM[ch2]).TBPRD = v.PeriodMax; \
(*ePWM[ch3]).TBPRD = v.PeriodMax; \
\
/* Init Timer-Base Phase Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).TBPHS.half.TBPHS = 0; \
(*ePWM[ch2]).TBPHS.half.TBPHS = 0; \
(*ePWM[ch3]).TBPHS.half.TBPHS = 0; \
\
/* Init Timer-Base Control Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).TBCTL.all = PWM_INIT_STATE; \
(*ePWM[ch2]).TBCTL.all = PWM_INIT_STATE; \
(*ePWM[ch3]).TBCTL.all = PWM_INIT_STATE; \
\
/* Init Compare Control Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).CMPCTL.all = CMPCTL_INIT_STATE; \
(*ePWM[ch2]).CMPCTL.all = CMPCTL_INIT_STATE; \
(*ePWM[ch3]).CMPCTL.all = CMPCTL_INIT_STATE; \
\
/* Init Action Qualifier Output A Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).AQCTLA.all = AQCTLA_INIT_STATE; \
(*ePWM[ch2]).AQCTLA.all = AQCTLA_INIT_STATE; \
(*ePWM[ch3]).AQCTLA.all = AQCTLA_INIT_STATE; \
\
/* Init Dead-Band Generator Control Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).DBCTL.all = DBCTL_INIT_STATE; \
(*ePWM[ch2]).DBCTL.all = DBCTL_INIT_STATE; \
(*ePWM[ch3]).DBCTL.all = DBCTL_INIT_STATE; \
\
/* Init Dead-Band Generator for EPWM1-EPWM3*/ \
(*ePWM[ch1]).DBFED = v.Deadband; \
(*ePWM[ch1]).DBRED = v.Deadband; \
(*ePWM[ch2]).DBFED = v.Deadband; \
(*ePWM[ch2]).DBRED = v.Deadband; \
(*ePWM[ch3]).DBFED = v.Deadband; \
(*ePWM[ch3]).DBRED = v.Deadband; \
\
/* Init PWM Chopper Control Register for EPWM1-EPWM3*/ \
(*ePWM[ch1]).PCCTL.all = PCCTL_INIT_STATE; \
(*ePWM[ch2]).PCCTL.all = PCCTL_INIT_STATE; \
(*ePWM[ch3]).PCCTL.all = PCCTL_INIT_STATE; \
\
EALLOW; /* Enable EALLOW */ \
\
/* Init Trip Zone Select Register*/ \
(*ePWM[ch1]).TZSEL.all = TZSEL_INIT_STATE; \
(*ePWM[ch2]).TZSEL.all = TZSEL_INIT_STATE; \
(*ePWM[ch3]).TZSEL.all = TZSEL_INIT_STATE; \
\
EDIS; /* Disable EALLOW*/
基本上都是参考TI官方的程序做的,查了寄存器也看不出什么问题 |