Hello,
I am trying to configure eCAP module on TMS320F28027 in Rising/Falling edge Delta timing mode in order to calculate the pulse width.
However, only one of the interrupts (CEVT2 @ ecap2_isr) routine gets triggered and it gets triggered only once. Please refer to the code snippet below. Any thoughts?
interrupt void ecap1_isr(void)
{
printf("\n\r In ECAP1 ISR\n\r");
// Read CAP1 time base counter at CEVT1
cap_t1 = CAP_getCap1(myCap);
// Clear eCAP Interrupt
CAP_clearInt(myCap, CAP_Int_Type_CEVT1);
// Reenable CAP1
CAP_rearm(myCap);
printf("\n\r Cleared CEVT1 INT \n\r");
}
interrupt void ecap2_isr(void)
{
printf("\n\r In ECAP2 ISR\n\r");
// Read CAP2 time base counter at CEVT2
cap_t2 = CAP_getCap2(myCap);
// Calculate pulse width
cap_period = cap_t2 - cap_t1;
printf("%d, ", cap_period);
printf("%d Hz \n\r", (40000000/cap_period));
// Clear eCAP Interrupt
CAP_clearInt(myCap, CAP_Int_Type_CEVT2);
// Reenable CAP1
CAP_rearm(myCap);
// Clear PIE Interrupt
PIE_clearInt(myPie, PIE_GroupNumber_4);
printf("\n\r Cleared CEVT2 INT \n\r");
}
void cap_init()
{
// Register interrupt handlers in the PIE vector table
PIE_registerPieIntHandler(myPie, PIE_GroupNumber_4, PIE_SubGroupNumber_1, (intVec_t)&ecap1_isr);
PIE_registerPieIntHandler(myPie, PIE_GroupNumber_4, PIE_SubGroupNumber_1, (intVec_t)&ecap2_isr);
// eCAP1 on GPIO5
GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Enable);
GPIO_setQualification(myGpio, GPIO_Number_5, GPIO_Qual_Sync);
GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_ECAP1);
CLK_enableEcap1Clock(myClk);
// Disable all eCAP interrupts
CAP_disableInt(myCap, CAP_Int_Type_All);
// Clear all eCAP interupt flags
CAP_clearInt(myCap, CAP_Int_Type_All);
// Disable CAP1-CAP4 register loads
CAP_disableCaptureLoad(myCap);
// Ensure counter is stopped
CAP_disableTimestampCounter(myCap);
// Configure CAPx for Capture mode
CAP_setModeCap(myCap);
// Configure peripheral registers
//CAP_setCapOneShot(myCap);
CAP_setCapContinuous(myCap);
// Set MOD4 Stop/Wrap value
CAP_setStopWrap(myCap, CAP_Stop_Wrap_CEVT2);
// Rising Edge
CAP_setCapEvtPolarity(myCap, CAP_Event_1, CAP_Polarity_Rising);
// Falling Edge
CAP_setCapEvtPolarity(myCap, CAP_Event_2, CAP_Polarity_Falling);
// Reset capture event 1
CAP_setCapEvtReset(myCap, CAP_Event_1, CAP_Reset_Enable);
// Reset capture event 2
CAP_setCapEvtReset(myCap, CAP_Event_2, CAP_Reset_Enable);
// Enable sync in
//CAP_enableSyncIn(myCap);
// Pass-through
CAP_setSyncOut(myCap, CAP_SyncOut_Disable);
// Enable CAP1-CAP4 register loads
CAP_enableCaptureLoad(myCap);
// Enable CAP CEVT1 counter
CAP_enableTimestampCounter(myCap);
// Arm one-shot
CAP_rearm(myCap);
// Enable CAP1-CAP4 register loads
CAP_enableCaptureLoad(myCap);
// Enable interrupt on CEVT1
CAP_enableInt(myCap, CAP_Int_Type_CEVT1);
// Enable interrupt on CEVT2
CAP_enableInt(myCap, CAP_Int_Type_CEVT2);
}