TI中文支持网
TI专业的中文技术问题搜集分享网站

2808CAP抗干扰怎么解决

现在碰到一个问题 ,我用2812的ECAP2做输入捕获中断,当外界有大电压电流产生是,输入捕获会进入中断。

//ecap 输入捕获中断

//初始化输入捕获
/*
设置ECap中断流程
1.关全局中断
2.停止ECap计数器
3.关Ecap中断
4.设置相关寄存器
5.清除中断标志位
6.开ECap中断
7.使能ECap计数器
8.开全局中断
*/
void InitECapture()
{
SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; // eCAP1
SysCtrlRegs.PCLKCR1.bit.ECAP2ENCLK = 1; // eCAP2
SysCtrlRegs.PCLKCR1.bit.ECAP3ENCLK = 1; // eCAP3
SysCtrlRegs.PCLKCR1.bit.ECAP4ENCLK = 1; // eCAP4

ECap2Regs.ECEINT.all = 0x0000;//关全局中断
ECap2Regs.ECCLR.all = 0xFFFF; //清除寄存器标志
ECap2Regs.ECCTL1.bit.CAPLDEN = 0;// Disable CAP1-CAP4 register 重载
ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0;// Make sure the counter is stopped
// Configure 外围 registers
ECap2Regs.ECCTL2.bit.CAP_APWM = 0; //0 ECAP模块在捕获模式下操作
ECap2Regs.ECCTL2.bit.CONT_ONESHT = 1; // One-shot
ECap2Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap2Regs.ECCTL1.bit.CAP1POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP2POL = FALL_EDGE;// Falling edge 返回 ECap2Regs.ECCTL1.bit.CAP3POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP4POL = FALL_EDGE;// Falling edge 返回
ECap2Regs.ECCTL1.bit.CTRRST1 = 1; //差分模式操作 捕获后复位计数器 ECap2Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; //使能同步输入
ECap2Regs.ECCTL2.bit.SYNCO_SEL =2; // 同步输出选择 把同步输入信号选为同步输出信号
ECap2Regs.ECCTL1.bit.CAPLDEN = 0; // 使能捕获单元

ECap2Regs.ECCTL1.bit.PRESCALE=0; //不分频
ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器开始
ECap2Regs.ECCTL2.bit.REARM = 1; // 单触发从新控制
ECap2Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap2Regs.ECEINT.bit.CEVT1 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT2 = 1; // 2 events = interrupt
ECap2Regs.ECEINT.bit.CEVT3 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT4 = 1; // 2 events = interrupt
}

interrupt void ecap2_isr(void)
{
Uint32 ECap2RegsCAP1Value;
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation

// ECap2IntCount++;
// ECap2PassCount++;

if((ECap2Regs.ECFLG.bit.CEVT1 ==1)&&(ECap2Regs.ECFLG.bit.INT ==1))
{
GPIO_LED=1;
ECap2Regs.ECFLG.bit.CEVT1 =0;
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除
scia_xmit(0x54);
delay_loop();
scia_xmit(VOLValue/256);
delay_loop();
scia_xmit(VOLValue%256);
delay_loop();
scia_xmit(CurrValue/256);
delay_loop();
scia_xmit(CurrValue%256);
delay_loop();
ECap2RegsCAP1Value=ECap2Regs.CAP1/100000;
scia_xmit(ECap2RegsCAP1Value /256); //动作时间 delay_loop();
scia_xmit(ECap2RegsCAP1Value %256);
delay_loop();
scia_xmit(0x45);
delay_loop();
GPIO_LED=0;
}
else if(ECap2Regs.ECFLG.bit.CEVT3 ==1)
{
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除

}

// ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器停止

ECap2Regs.ECCLR.all = 0xff;
ECap2Regs.ECCLR.bit.INT = 1;
ECap2Regs.ECCTL2.bit.REARM = 1;

// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}

初始化代码和中断服务程序如下

囧:

可以使能GPIO input qualification, 这个功能无论你mapping成什么外设都有

现在碰到一个问题 ,我用2812的ECAP2做输入捕获中断,当外界有大电压电流产生是,输入捕获会进入中断。

//ecap 输入捕获中断

//初始化输入捕获
/*
设置ECap中断流程
1.关全局中断
2.停止ECap计数器
3.关Ecap中断
4.设置相关寄存器
5.清除中断标志位
6.开ECap中断
7.使能ECap计数器
8.开全局中断
*/
void InitECapture()
{
SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; // eCAP1
SysCtrlRegs.PCLKCR1.bit.ECAP2ENCLK = 1; // eCAP2
SysCtrlRegs.PCLKCR1.bit.ECAP3ENCLK = 1; // eCAP3
SysCtrlRegs.PCLKCR1.bit.ECAP4ENCLK = 1; // eCAP4

ECap2Regs.ECEINT.all = 0x0000;//关全局中断
ECap2Regs.ECCLR.all = 0xFFFF; //清除寄存器标志
ECap2Regs.ECCTL1.bit.CAPLDEN = 0;// Disable CAP1-CAP4 register 重载
ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0;// Make sure the counter is stopped
// Configure 外围 registers
ECap2Regs.ECCTL2.bit.CAP_APWM = 0; //0 ECAP模块在捕获模式下操作
ECap2Regs.ECCTL2.bit.CONT_ONESHT = 1; // One-shot
ECap2Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap2Regs.ECCTL1.bit.CAP1POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP2POL = FALL_EDGE;// Falling edge 返回 ECap2Regs.ECCTL1.bit.CAP3POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP4POL = FALL_EDGE;// Falling edge 返回
ECap2Regs.ECCTL1.bit.CTRRST1 = 1; //差分模式操作 捕获后复位计数器 ECap2Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; //使能同步输入
ECap2Regs.ECCTL2.bit.SYNCO_SEL =2; // 同步输出选择 把同步输入信号选为同步输出信号
ECap2Regs.ECCTL1.bit.CAPLDEN = 0; // 使能捕获单元

ECap2Regs.ECCTL1.bit.PRESCALE=0; //不分频
ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器开始
ECap2Regs.ECCTL2.bit.REARM = 1; // 单触发从新控制
ECap2Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap2Regs.ECEINT.bit.CEVT1 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT2 = 1; // 2 events = interrupt
ECap2Regs.ECEINT.bit.CEVT3 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT4 = 1; // 2 events = interrupt
}

interrupt void ecap2_isr(void)
{
Uint32 ECap2RegsCAP1Value;
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation

// ECap2IntCount++;
// ECap2PassCount++;

if((ECap2Regs.ECFLG.bit.CEVT1 ==1)&&(ECap2Regs.ECFLG.bit.INT ==1))
{
GPIO_LED=1;
ECap2Regs.ECFLG.bit.CEVT1 =0;
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除
scia_xmit(0x54);
delay_loop();
scia_xmit(VOLValue/256);
delay_loop();
scia_xmit(VOLValue%256);
delay_loop();
scia_xmit(CurrValue/256);
delay_loop();
scia_xmit(CurrValue%256);
delay_loop();
ECap2RegsCAP1Value=ECap2Regs.CAP1/100000;
scia_xmit(ECap2RegsCAP1Value /256); //动作时间 delay_loop();
scia_xmit(ECap2RegsCAP1Value %256);
delay_loop();
scia_xmit(0x45);
delay_loop();
GPIO_LED=0;
}
else if(ECap2Regs.ECFLG.bit.CEVT3 ==1)
{
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除

}

// ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器停止

ECap2Regs.ECCLR.all = 0xff;
ECap2Regs.ECCLR.bit.INT = 1;
ECap2Regs.ECCTL2.bit.REARM = 1;

// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}

初始化代码和中断服务程序如下

mangui zhang:

送入捕获引脚的信号必须做整形  隔离等处理

避免脉冲等干扰

现在碰到一个问题 ,我用2812的ECAP2做输入捕获中断,当外界有大电压电流产生是,输入捕获会进入中断。

//ecap 输入捕获中断

//初始化输入捕获
/*
设置ECap中断流程
1.关全局中断
2.停止ECap计数器
3.关Ecap中断
4.设置相关寄存器
5.清除中断标志位
6.开ECap中断
7.使能ECap计数器
8.开全局中断
*/
void InitECapture()
{
SysCtrlRegs.PCLKCR1.bit.ECAP1ENCLK = 1; // eCAP1
SysCtrlRegs.PCLKCR1.bit.ECAP2ENCLK = 1; // eCAP2
SysCtrlRegs.PCLKCR1.bit.ECAP3ENCLK = 1; // eCAP3
SysCtrlRegs.PCLKCR1.bit.ECAP4ENCLK = 1; // eCAP4

ECap2Regs.ECEINT.all = 0x0000;//关全局中断
ECap2Regs.ECCLR.all = 0xFFFF; //清除寄存器标志
ECap2Regs.ECCTL1.bit.CAPLDEN = 0;// Disable CAP1-CAP4 register 重载
ECap2Regs.ECCTL2.bit.TSCTRSTOP = 0;// Make sure the counter is stopped
// Configure 外围 registers
ECap2Regs.ECCTL2.bit.CAP_APWM = 0; //0 ECAP模块在捕获模式下操作
ECap2Regs.ECCTL2.bit.CONT_ONESHT = 1; // One-shot
ECap2Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap2Regs.ECCTL1.bit.CAP1POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP2POL = FALL_EDGE;// Falling edge 返回 ECap2Regs.ECCTL1.bit.CAP3POL = RISI_EDGE;// Rising edge 动作
ECap2Regs.ECCTL1.bit.CAP4POL = FALL_EDGE;// Falling edge 返回
ECap2Regs.ECCTL1.bit.CTRRST1 = 1; //差分模式操作 捕获后复位计数器 ECap2Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation ECap2Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation ECap2Regs.ECCTL2.bit.SYNCI_EN = 0; //使能同步输入
ECap2Regs.ECCTL2.bit.SYNCO_SEL =2; // 同步输出选择 把同步输入信号选为同步输出信号
ECap2Regs.ECCTL1.bit.CAPLDEN = 0; // 使能捕获单元

ECap2Regs.ECCTL1.bit.PRESCALE=0; //不分频
ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器开始
ECap2Regs.ECCTL2.bit.REARM = 1; // 单触发从新控制
ECap2Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
ECap2Regs.ECEINT.bit.CEVT1 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT2 = 1; // 2 events = interrupt
ECap2Regs.ECEINT.bit.CEVT3 = 1; // 1 events = interrupt
ECap2Regs.ECEINT.bit.CEVT4 = 1; // 2 events = interrupt
}

interrupt void ecap2_isr(void)
{
Uint32 ECap2RegsCAP1Value;
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation

// ECap2IntCount++;
// ECap2PassCount++;

if((ECap2Regs.ECFLG.bit.CEVT1 ==1)&&(ECap2Regs.ECFLG.bit.INT ==1))
{
GPIO_LED=1;
ECap2Regs.ECFLG.bit.CEVT1 =0;
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除
scia_xmit(0x54);
delay_loop();
scia_xmit(VOLValue/256);
delay_loop();
scia_xmit(VOLValue%256);
delay_loop();
scia_xmit(CurrValue/256);
delay_loop();
scia_xmit(CurrValue%256);
delay_loop();
ECap2RegsCAP1Value=ECap2Regs.CAP1/100000;
scia_xmit(ECap2RegsCAP1Value /256); //动作时间 delay_loop();
scia_xmit(ECap2RegsCAP1Value %256);
delay_loop();
scia_xmit(0x45);
delay_loop();
GPIO_LED=0;
}
else if(ECap2Regs.ECFLG.bit.CEVT3 ==1)
{
ECap2Regs.ECCLR.bit.INT = 1; //全局中断清除
ECap2Regs.ECCLR.bit.CEVT1 = 1; //输入捕获1中断清除

}

// ECap2Regs.ECCTL2.bit.TSCTRSTOP = EC_STOP; //计数器停止

ECap2Regs.ECCLR.all = 0xff;
ECap2Regs.ECCLR.bit.INT = 1;
ECap2Regs.ECCTL2.bit.REARM = 1;

// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}

初始化代码和中断服务程序如下

Hardy Zhou:

回复 mangui zhang:

input qualification调整,如果可以,捕获输入信号接高频电容滤波,地层layout重新设计

赞(0)
未经允许不得转载:TI中文支持网 » 2808CAP抗干扰怎么解决
分享到: 更多 (0)