I am using the ECAP module to read the frequency output of a sensor, but the capture count value is inconsistent with the frequency input after calculating the frequency to discard any out of input range values, which worked with a function generator but not on the actual sensor.
I am currently using only one capture event on the rising edge, although before I was using 2/4 rising and 1/3 falling, and taking the difference between 4 and 2 to find the count. Using multiple events did not help, as all of the counts were inconsistent. I have scoped the input frequency and it is a pretty clean square wave, so I am wondering if I am missing something in my configuration. I am reading the count on a 20kHz EPWM isr instead of a ECAP isr to not intefere with my spi interrupt timing.
Here is my config function:
void configureECAP() {
// Disable ,clear all capture flags and interrupts
//
ECAP_disableInterrupt(ECAP1_BASE,
(ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
ECAP_ISR_SOURCE_COUNTER_PERIOD |
ECAP_ISR_SOURCE_COUNTER_COMPARE));
ECAP_clearInterrupt(ECAP1_BASE,
(ECAP_ISR_SOURCE_CAPTURE_EVENT_1 |
ECAP_ISR_SOURCE_COUNTER_OVERFLOW |
ECAP_ISR_SOURCE_COUNTER_PERIOD |
ECAP_ISR_SOURCE_COUNTER_COMPARE));
//REMOVED EXTRA EVENTS
//
ECAP_disableTimeStampCapture(ECAP1_BASE);
//
ECAP_stopCounter(ECAP1_BASE);
ECAP_enableCaptureMode(ECAP1_BASE);
ECAP_setCaptureMode(ECAP1_BASE, ECAP_CONTINUOUS_CAPTURE_MODE, ECAP_EVENT_1);
ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_1, ECAP_EVNT_RISING_EDGE);
ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_1);
XBAR_setInputPin(XBAR_INPUT7, 29);
ECAP_enableLoadCounter(ECAP1_BASE);
ECAP_setSyncOutMode(ECAP1_BASE, ECAP_SYNC_OUT_DISABLED);
ECAP_startCounter(ECAP1_BASE);
//ECAP_reArm(ECAP1_BASE); //ADDED
ECAP_enableTimeStampCapture(ECAP1_BASE);
}