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

F28035ECAP捕获模块问题

ECAP捕获模块配置程序
void InitECapture()
{
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
// Configure peripheral registers
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // 0:连续模式 1:单次模式
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP4POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // 0:在CAP1捕获后不重置计数;1:在CAP1捕获后重置计数
ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Enable sync in:禁止同步信号加载
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; // Pass through:10或11:屏蔽同步信号输出
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter 0:计数器停止;1:计数器计数
//ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot 单次模式重加载控制
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
//ECap1Regs.ECEINT.bit.CEVT4 = 1; // 4 events = interrupt
//ECap1Regs.ECEINT.bit.CEVT3 = 1;
//ECap1Regs.ECEINT.bit.CEVT2 = 1;
ECap1Regs.ECEINT.bit.CEVT1 = 1;
}
__interrupt void ecap1_isr(void)
{
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation
//========================================
ECap1_Tst1 = ECap1Regs.CAP1; // Fetch Time-Stamp captured at t1
ECap1_Tst2 = ECap1Regs.CAP2; // Fetch Time-Stamp captured at t2
ECap1_Tst3 = ECap1Regs.CAP3; // Fetch Time-Stamp captured at t3
ECap1_Tst4 = ECap1Regs.CAP4; // Fetch Time-Stamp captured at t4
Period1 = ECap1_Tst1+ECap1_Tst2; // Calculate 1st period
Period2 = ECap1_Tst3-ECap1_Tst4; // Calculate 2nd period
//Period3 = ECap1_Tst3-ECap1_Tst2; // Calculate 3rd perio
Frequency=1/Period1;
ECap1PassCount++;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
//ECap1Regs.ECCLR.bit.CEVT2 = 1;
//ECap1Regs.ECCLR.bit.CEVT3 = 1;
//ECap1Regs.ECCLR.bit.CEVT4 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
//ECap1Regs.ECCTL2.bit.REARM = 1;
// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
上述程序配置情况:CAP1-4上升沿捕获,捕获后重新计数,使能中断CEVT1
问题:
一、1.F28035系统时钟配置60MHz,捕获信号发生器1Hz方波时,CAP1-4计数值误差很大

2.捕获信号发生器100Hz方波时,CAP1-4计数值烂到炸,应该为600,000
请问,本身就这样还是程序配置的问题?F28035ECAP模块能捕获的方波的最大频率是多少?
二、疑问CAP1-4必须都用,就不能只用一个或两个吗?我刚才试了一下只配置CAP1-2,其他CAP3-4所有配置都屏蔽掉,还是走完四个边沿才进CAP1中断

Jun Zhang10:

好好看完ECAP的部分就能找到答案了,如果找不到再看一遍。

ECAP捕获模块配置程序
void InitECapture()
{
ECap1Regs.ECEINT.all = 0x0000; // Disable all capture interrupts
ECap1Regs.ECCLR.all = 0xFFFF; // Clear all CAP interrupt flags
ECap1Regs.ECCTL1.bit.CAPLDEN = 0; // Disable CAP1-CAP4 register loads
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; // Make sure the counter is stopped
// Configure peripheral registers
ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0; // 0:连续模式 1:单次模式
ECap1Regs.ECCTL2.bit.STOP_WRAP = 3; // Stop at 4 events
ECap1Regs.ECCTL1.bit.CAP1POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP2POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CAP3POL = 1; // Falling edge
ECap1Regs.ECCTL1.bit.CAP4POL = 1; // Rising edge
ECap1Regs.ECCTL1.bit.CTRRST1 = 1; // 0:在CAP1捕获后不重置计数;1:在CAP1捕获后重置计数
ECap1Regs.ECCTL1.bit.CTRRST2 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST3 = 1; // Difference operation
ECap1Regs.ECCTL1.bit.CTRRST4 = 1; // Difference operation
ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; // Enable sync in:禁止同步信号加载
ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; // Pass through:10或11:屏蔽同步信号输出
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable capture units
ECap1Regs.ECCTL2.bit.TSCTRSTOP = 1; // Start Counter 0:计数器停止;1:计数器计数
//ECap1Regs.ECCTL2.bit.REARM = 1; // arm one-shot 单次模式重加载控制
ECap1Regs.ECCTL1.bit.CAPLDEN = 1; // Enable CAP1-CAP4 register loads
//ECap1Regs.ECEINT.bit.CEVT4 = 1; // 4 events = interrupt
//ECap1Regs.ECEINT.bit.CEVT3 = 1;
//ECap1Regs.ECEINT.bit.CEVT2 = 1;
ECap1Regs.ECEINT.bit.CEVT1 = 1;
}
__interrupt void ecap1_isr(void)
{
// Cap input is syc'ed to SYSCLKOUT so there may be
// a +/- 1 cycle variation
//========================================
ECap1_Tst1 = ECap1Regs.CAP1; // Fetch Time-Stamp captured at t1
ECap1_Tst2 = ECap1Regs.CAP2; // Fetch Time-Stamp captured at t2
ECap1_Tst3 = ECap1Regs.CAP3; // Fetch Time-Stamp captured at t3
ECap1_Tst4 = ECap1Regs.CAP4; // Fetch Time-Stamp captured at t4
Period1 = ECap1_Tst1+ECap1_Tst2; // Calculate 1st period
Period2 = ECap1_Tst3-ECap1_Tst4; // Calculate 2nd period
//Period3 = ECap1_Tst3-ECap1_Tst2; // Calculate 3rd perio
Frequency=1/Period1;
ECap1PassCount++;
ECap1Regs.ECCLR.bit.CEVT1 = 1;
//ECap1Regs.ECCLR.bit.CEVT2 = 1;
//ECap1Regs.ECCLR.bit.CEVT3 = 1;
//ECap1Regs.ECCLR.bit.CEVT4 = 1;
ECap1Regs.ECCLR.bit.INT = 1;
//ECap1Regs.ECCTL2.bit.REARM = 1;
// Acknowledge this interrupt to receive more interrupts from group 4
PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;
}
上述程序配置情况:CAP1-4上升沿捕获,捕获后重新计数,使能中断CEVT1
问题:
一、1.F28035系统时钟配置60MHz,捕获信号发生器1Hz方波时,CAP1-4计数值误差很大

2.捕获信号发生器100Hz方波时,CAP1-4计数值烂到炸,应该为600,000
请问,本身就这样还是程序配置的问题?F28035ECAP模块能捕获的方波的最大频率是多少?
二、疑问CAP1-4必须都用,就不能只用一个或两个吗?我刚才试了一下只配置CAP1-2,其他CAP3-4所有配置都屏蔽掉,还是走完四个边沿才进CAP1中断

mangui zhang:

首先你送入的方波最好做一下整形处理     

然后确定你配置的时钟等和你理解的完全一致     

两次捕获的值做差  注意计数器溢出情况

赞(0)
未经允许不得转载:TI中文支持网 » F28035ECAP捕获模块问题
分享到: 更多 (0)