I am using eCAP module to get wheel speed , by looking in the data i could see random frequent data spike even we areRC filter and low pass filter in algorithm.here i am using eCAP with interrupt.I am attaching my code.
eCAP register 4 is used and eCAP interrupt evt1 & evt4 are enabled. i am using 4 eCAP pulse to calculate speed.Do we need to clear the overflow of the eCAP counter? , do we need to use FIQ for eCAP? as i am also using RTI along with it for every 25 ms.
void calculate_speed()
{
volatile uint32 temp1, temp2,temp21,temp22;
temp1 = c1;
temp2 = c4;
if(temp2>temp1)
{
T = temp2 - temp1;
fwspeed =(1308.3*180.00*100.00)/T; //Rad/sec
}
}
void ecapNotification(ecapBASE_t *ecap, uint16 flags)
{
if(ecap == ecapREG4){
count++;
if(count%2 == 1)
{
c1 = ecapGetCAP1(ecapREG4);
pulsesf++;
flag = 0;
}
else if(count%2 == 0)
{
c4 = ecapGetCAP4(ecapREG4);
count = 0;
flag = 1;
}
}
}
int main(){
_enable_interrupt_();
_enable_IRQ();
ecapInit();
while(1){
if(flag==1){
_disable_IRQ();
calculate_speed();
_enable_IRQ();
}
}