我现在使用28335的ECAP捕获1MHZ的R232电平信号,在第四次捕获进入中断,计算高电平时间判断数据是0还是1。然后将结果放入32位变量中,再根据标识位获得有效数据。我在实际捕获中捕获的数据经常不准确,请问是什么原因造成的,该如何解决?
void SetCap1Mode(void)
{
// 这里加入了光耦隔离,取反
ECap1Regs.ECCTL1.bit.CAP1POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
// ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_ONESHOT; // One-shot
// ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; // Stop at 2 events
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
ECap1Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
interrupt void ISRCap1(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
t1= ECap1Regs.CAP1;
t2= ECap1Regs.CAP2;
t3= ECap1Regs.CAP3;
t4= ECap1Regs.CAP4;
if(t2-t1 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
// 判断标识位
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
// 获得有效数据
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
if(t4-t3 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
}
而且我发现,t3的值有时会小于t1的值,这样应该会造成数据顺序不对以及数据丢失的问题,这个是什么原因(计数器未溢出)???
mangui zhang:
首先通过buffer等将信号整形 这样干扰就比较小
然后多次捕获后 定时器肯定会溢出
这种情况你都要去判断 当溢出后需要+FFFF处理
我现在使用28335的ECAP捕获1MHZ的R232电平信号,在第四次捕获进入中断,计算高电平时间判断数据是0还是1。然后将结果放入32位变量中,再根据标识位获得有效数据。我在实际捕获中捕获的数据经常不准确,请问是什么原因造成的,该如何解决?
void SetCap1Mode(void)
{
// 这里加入了光耦隔离,取反
ECap1Regs.ECCTL1.bit.CAP1POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
// ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_ONESHOT; // One-shot
// ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; // Stop at 2 events
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
ECap1Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
interrupt void ISRCap1(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
t1= ECap1Regs.CAP1;
t2= ECap1Regs.CAP2;
t3= ECap1Regs.CAP3;
t4= ECap1Regs.CAP4;
if(t2-t1 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
// 判断标识位
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
// 获得有效数据
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
if(t4-t3 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
}
而且我发现,t3的值有时会小于t1的值,这样应该会造成数据顺序不对以及数据丢失的问题,这个是什么原因(计数器未溢出)???
Ze Long:
我现在把程序改了,中断里面只取记四个捕获寄存器的计数,然而还是有t1,t2,t3,t4不是按照时间顺序排列的问题,跟溢出应该没关系,因为有时候是四个数字某一个大一些,就大个百儿八十的,加了0xffffffff以后一样不对,发生频率也很高(计数器溢出的话耗时肯定不止10几20微秒吧)。
interrupt void ISRCap1(void){ CapArr[i] = ECap1Regs.CAP1; i++; CapArr[0][i] = ECap1Regs.CAP2; i++; CapArr[0][i] = ECap1Regs.CAP3; i++; CapArr[0][i] = ECap1Regs.CAP4; i++; if(i == 64) { ECap1Regs.ECEINT.bit.CEVT4 = 0; SensorCapComplete = 1; } //if(ECap1Regs.CAP1>ECap1Regs.CAP3) GPIOTIMER1 = ~GPIOTIMER1; PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; ECap1Regs.ECCLR.all=0xFFFF;//clare all flag}
单纯记64个数字,里面就会发生多次这个问题了,望大神解答啊,实在是查不出来了。
我现在使用28335的ECAP捕获1MHZ的R232电平信号,在第四次捕获进入中断,计算高电平时间判断数据是0还是1。然后将结果放入32位变量中,再根据标识位获得有效数据。我在实际捕获中捕获的数据经常不准确,请问是什么原因造成的,该如何解决?
void SetCap1Mode(void)
{
// 这里加入了光耦隔离,取反
ECap1Regs.ECCTL1.bit.CAP1POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP2POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CAP3POL = EC_FALLING;
ECap1Regs.ECCTL1.bit.CAP4POL = EC_RISING;
ECap1Regs.ECCTL1.bit.CTRRST1 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST2 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST3 = EC_ABS_MODE;
ECap1Regs.ECCTL1.bit.CTRRST4 = EC_ABS_MODE;
// ECap1Regs.ECCTL1.bit.CTRRST4 = EC_DELTA_MODE;
ECap1Regs.ECCTL1.bit.CAPLDEN = EC_ENABLE;
ECap1Regs.ECCTL1.bit.PRESCALE = EC_DIV1;
ECap1Regs.ECCTL2.bit.CAP_APWM = EC_CAP_MODE;
ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_CONTINUOUS;
// ECap1Regs.ECCTL2.bit.CONT_ONESHT = EC_ONESHOT; // One-shot
// ECap1Regs.ECCTL2.bit.STOP_WRAP = EC_EVENT2; // Stop at 2 events
ECap1Regs.ECCTL2.bit.SYNCO_SEL = EC_SYNCO_DIS;
ECap1Regs.ECCTL2.bit.SYNCI_EN = EC_DISABLE;
ECap1Regs.ECEINT.all=0x0000;//stop all interrupt
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
ECap1Regs.ECCTL2.bit.TSCTRSTOP = EC_RUN;// 启动
ECap1Regs.ECEINT.bit.CEVT4=1;// Enable cevt4 interrupt
}
interrupt void ISRCap1(void)
{
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
t1= ECap1Regs.CAP1;
t2= ECap1Regs.CAP2;
t3= ECap1Regs.CAP3;
t4= ECap1Regs.CAP4;
if(t2-t1 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
// 判断标识位
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
// 获得有效数据
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
if(t4-t3 > 75)
{
cratmp1 = (cratmp1 << 1) | 1;
}
// 0
else
{
cratmp1 <<= 1;
}
if(cratmp1 << 7 >> 19 == 0x1FFE)
{
craArr1[SensorGetNum] = cratmp1 & 0xFFF;
}
// PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
ECap1Regs.ECCLR.all=0xFFFF;//clare all flag
}
而且我发现,t3的值有时会小于t1的值,这样应该会造成数据顺序不对以及数据丢失的问题,这个是什么原因(计数器未溢出)???
qiang zhang:还好,你这个问题解决了吗?我想问一下