Hello,
I have been trying to implement this input capture functionality to measure the high time and low time of a continuous 1 Hz square wave with 50% duty cycle. Just to make it simple I started out with this.
I am able to trigger the interrupt on a rising edge. But for some reason, the interrupt won't trigger on a falling edge. Whenever I set CM to input capture both edges, the interrupt would only trigger on a rising edge.
I am using TA0.1. Please help. Below is my code and the ISR
void EnableCaptureTA01(void) { GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P1, GPIO_PIN2 ); Timer_A_initContinuousModeParam initContParam = {0}; initContParam.clockSource = TIMER_A_CLOCKSOURCE_ACLK; initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1; initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; initContParam.timerClear = TIMER_A_DO_CLEAR; Timer_A_initContinuousMode(TIMER_A0_BASE, &initContParam); Timer_A_startCounter(TIMER_A0_BASE, TIMER_A_CONTINUOUS_MODE); Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1); Timer_A_initCaptureModeParam initCapParam = {0}; initCapParam.captureRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1; initCapParam.captureMode = TIMER_A_CAPTUREMODE_RISING_AND_FALLING_EDGE; initCapParam.captureInputSelect = TIMER_A_CAPTURE_INPUTSELECT_CCIxA; initCapParam.synchronizeCaptureSource = TIMER_A_CAPTURE_SYNCHRONOUS; initCapParam.captureInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE; initCapParam.captureOutputMode = TIMER_A_OUTPUTMODE_OUTBITVALUE; Timer_A_initCaptureMode(TIMER_A0_BASE, &initCapParam); }//end void EnableCaptureTA01(void) void TIMERA0ISR (void) { uint8_t integerArray[10]; //uint8_t integerArray[10]; //Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1); switch(__even_in_range(TA0IV,0x0E)) { case 0x0: break; case 0x2: Timer_A_clearCaptureCompareInterrupt(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1); GPIO_toggleOutputOnPin(GPIO_PORT_P4, GPIO_PIN7); Edge= Timer_A_getCaptureCompareCount(TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1); UINT32ToASCII(Edge, integerArray); WriteUARTA1("\n\rEdge = "); WriteUARTA1(integerArray); Time = (double)(Edge- PreviousEdge); if(Time < 0) { Time = Time + 65535; } Time = (Time + 1) / ACLKValue; DoubleToASCII(Time, 3, integerArray); WriteUARTA1("\n\rTime = "); WriteUARTA1(integerArray); PreviousEdge = Edge; if(TIMER_A_CAPTURE_OVERFLOW == Timer_A_getCaptureCompareInterruptStatus (TIMER_A0_BASE, TIMER_A_CAPTURECOMPARE_REGISTER_1, TIMER_A_CAPTURE_OVERFLOW )) { WriteUARTA1("\n\rOverflow occurred "); } break; case 0x4: break; case 0x6: break; case 0x8: break; case 0xA: break; case 0xC: break; default: break; }//end switch(__even_in_range(TA0IV,0x0E)) }//end void TIMERA0ISR (void)
Here is the output from my terminal. Since the squarewave is 1 HZ, and I have set the capture to both edges, I'd expect a .5 sec high and .5 sec low time. But I'm just getting the entire period
because the interrupt triggers only on the rising edge. Am I missing anything? Thanks a lot
Edge = 14264
Time = 1.000
Edge = 47033
Time = 1.000
Edge = 14267
Time = 1.000
Edge = 47036
Time = 1.000
Edge = 14268
Time = 1.000
Edge = 47038
Time = 1.000
Edge = 14271
Time = 1.000
Edge = 47040
Time = 1.000
Edge = 14272
Time = 1.000
Edge = 47041
Time = 1.000
AJ