请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。尊敬的 Arsalan:
抱歉、可能我误解了您要尝试实施的内容。 我认为您只想将 CTROVF 用作当前 ISR 的中断源。
相反、让我们保留该 ISR 中原始设置、该 ISR 在 CEVT3上触发、并启用 CTROVF。 所有您需要做的事情、因为我们已经将以下位更改为1。
// bit 15-8 0's: reserved
// bit 7 0: CTR=CMP, 0 = compare interrupt disabled
// bit 6 0: CTR=PRD, 0 = period interrupt disabled
// bit 5 1: CTROVF, 0 = overflow interrupt disabled
// bit 4 0: CEVT4, 0 = event 4 interrupt disabled
// bit 3 1: CEVT3, 1 = event 3 interrupt enabled
// bit 2 0: CEVT2, 0 = event 2 interrupt disabled
// bit 1 0: CEVT1, 0 = event 1 interrupt disabled
// bit 0 0: reserved
然后、在 ISR 中、如果 ISR 被 CTROVF 事件触发、我们可以检查 if 语句中的标志、如下所示、并重新启用捕获:
interrupt void eCAP1_isr(void)
{
ECap1Regs.ECCLR.bit.INT = 1; // Clear the ECAP1 interrupt flag
ECap1Regs.ECCLR.bit.CEVT3 = 1; // Clear the CEVT3 flag
if(ECap1Regs.ECFLG.bit.CTROVF == 1) // Inserted code here
{
// This will clear the over flow flag, then rearm for another capture
ECap1Regs.ECCLR.bit.CTROVF = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
}else
{
// Calculate the PWM duty period (rising edge to falling edge)
PWM_Duty = (int32)ECap1Regs.CAP2 - (int32)ECap1Regs.CAP1;
// Calculate the PWM period (rising edge to rising edge)
PWM_Period = (int32)ECap1Regs.CAP3 - (int32)ECap1Regs.CAP1;
// ECap1Regs.ECCLR.bit.CTROVF = 1;
ECap1Regs.ECCTL2.bit.REARM = 1;
EPwm1Regs.TBPRD = TPWM;
EPwm2Regs.TBPRD = TPWM;
EPwm1Regs.CMPA.half.CMPA = ((int32)NEW_Duty); // 50% duty cycle first
EPwm1Regs.CMPB = ((int32)NEW_Duty);
EPwm2Regs.CMPA.half.CMPA = ((int32)NEW_Duty); // 50% duty cycle first
EPwm2Regs.CMPB = ((int32)NEW_Duty);
EPwm1Regs.TBCTL.bit.SYNCOSEL = 1; // generate a syncout if CTR = 0
EPwm2Regs.TBCTL.bit.PHSEN = 1; // enable phase shift for ePWM2
EPwm2Regs.TBCTL.bit.SYNCOSEL = 0; // syncin = syncout
EPwm2Regs.TBPHS.half.TBPHS = TPWM; // 1/3 phase shift
}
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; // Must acknowledge the PIE group 4
}
仅当没有 CTRVF 状态时才执行 ELSE 语句。
此致!
mA