我现在用信号发生器给50Hz的方波,然后用eCAP1捕获上升沿,捕获后立刻让EPWM1捕获后发SPWM波。
现在用仿真器调试,第一次能够实现捕获上升沿立即发SPWM;但suspend暂停之后再继续,发现SPWM就不是在上升沿发送了。
是不是和我在eCAP中断服务程序里写了EPwm1Regs.ETSEL.bit.INTEN = 1;这样PWM中断在suspend时就打开了,故无法保证是在上升沿的时候进入eCAP中断然后再使能SPWM了?
现在做H桥逆变,双极性调制,死区互补,我想开始时不发SPWM波,当捕获到正弦波过零点时才发SPWM,这部分程序该如何写?我现在的方法就是把EPwm1Regs.ETSEL.bit.INTEN = 1写在在eCAP中断服务程序里了,不知道这样是否正确,请前辈指点应该怎样来写呢?希望帮忙看看,非常感谢!
interrupt void ECAP1_INT_ISR(void) // ECAP-1
{
Num=0;
EPwm1Regs.CMPA.half.CMPA =sinetable[Num];
EPwm2Regs.CMPA.half.CMPA =sinetable[Num];
EPwm1Regs.ETSEL.bit.INTEN = 1;
{
Num=0;
EPwm1Regs.CMPA.half.CMPA =sinetable[Num];
EPwm2Regs.CMPA.half.CMPA =sinetable[Num];
EPwm1Regs.ETSEL.bit.INTEN = 1;
capcount++;
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
interrupt void EPWM1_INT_ISR(void) // EPWM-1
{
Num++;
if(Num==tablesize)
Num=0;
EPwm1Regs.CMPA.half.CMPA =sinetable[Num];
EPwm2Regs.CMPA.half.CMPA =sinetable[Num];
{
Num++;
if(Num==tablesize)
Num=0;
EPwm1Regs.CMPA.half.CMPA =sinetable[Num];
EPwm2Regs.CMPA.half.CMPA =sinetable[Num];
EPwm1Regs.ETCLR.bit.INT = 1; //清除ePWM_INT1中断 标志位
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;//允许响应同组其他中断:写1清0,对第3位操作,表示INT3中断处理完成,开中断INT3,允许下一次PIE中断
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;//允许响应同组其他中断:写1清0,对第3位操作,表示INT3中断处理完成,开中断INT3,允许下一次PIE中断
}
//eCAP1模块的配置
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt禁止所有中断
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag清除所有中断标志位
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_DISABLE; //等于0,配置时先禁止在捕获事件中加载CAP1-4的时间;(使能:事件触发时,把定时器的值加载到捕获寄存器中)
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_FREEZE; //等于0,配置时先禁止
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag清除所有中断标志位
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_DISABLE; //等于0,配置时先禁止在捕获事件中加载CAP1-4的时间;(使能:事件触发时,把定时器的值加载到捕获寄存器中)
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_FREEZE; //等于0,配置时先禁止
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1; //不分频
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; //CAP模式(如果用APWM模式则写1)
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; //EC_CONTINUOUS:等于0,连续模式
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE; //CAP模式(如果用APWM模式则写1)
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS; //EC_CONTINUOUS:等于0,连续模式
ECap1Regs.ECCTL1.bit.CAP1POL = EC_RISING; //等于0,CAP1上升沿捕捉
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING;
//ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE; //EC_DELTA_MODE:等于1,相当于event 1触发interrupt后,重置计数器
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE; //EC_ABS_MODE:在CAP1事件中不重置计数器(连续模式)
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_DELTA_MODE; //EC_ABS_MODE:在CAP1事件中不重置计数器(连续模式)
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE; //禁用同步输入选项
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; //禁止同步输出信号
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS; //禁止同步输出信号
ECap1Regs.ECCTL2.bit.STOP_WRAP = 0; // Stop at Event 1
ECap1Regs.ECEINT.bit.CEVT1=1;//只用 Event 1 产生 interrupt
ECap1Regs.ECEINT.bit.CEVT1=1;//只用 Event 1 产生 interrupt