This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

eCAP Capture Events always sets all CAPx registers

Other Parts Discussed in Thread: LAUNCHXL2-TMS57012, HALCOGEN, TMS570LS1224

Hallo all,

I try to meassrue a frequency in the range of 100 to 500 Hz with a LAUNCHXL2-TMS57012 (TMS570LS1224 Controller). My code is based on example code provided by HALCOGEN (see below).

When the ecapInt_CEVT3 event triggers an interrupt, always all three capture registers CAP1, CAP2, CAP3 have the same value. Therfore I added ecapInt_CEVT1 and ecapInt_CEVT2 to debug the problem. On every Capture event I see in the debugger, that values of the TSCTR and CAP1, CAP2, CAP3 are increasing but they always have the same value. CAP4 remains 0.

Any Ideas what I'm doing wrong?

void main(void)
{
/* USER CODE BEGIN (3) */

	_enable_interrupt_();
	
	/* Configure ECAP1 */
	/* Configure Event 1 to Capture the rising edge */
	ecapSetCaptureEvent1(ecapREG1, RISING_EDGE, RESET_DISABLE);

	/* Configure Event 2 to Capture the falling edge */
	ecapSetCaptureEvent2(ecapREG1, FALLING_EDGE, RESET_DISABLE);

	/* Configure Event 3 to Capture the rising edge with reset counter enable */
	ecapSetCaptureEvent3(ecapREG1, RISING_EDGE, RESET_ENABLE);

	/* Set Capure mode as Continuous and Wrap event as CAP3  */
	ecapSetCaptureMode(ecapREG1, CONTINUOUS, CAPTURE_EVENT3);

	/* Start counter */
	ecapStartCounter(ecapREG1);

	/* Enable Loading on Capture */
	ecapEnableCapture(ecapREG1);

	/* Enable Interrupt for CAP3 event */
	ecapEnableInterrupt(ecapREG1, ecapInt_CEVT1|ecapInt_CEVT2|ecapInt_CEVT3);
	
    /*  ... run forever  */
    while(1);
	
/* USER CODE END */	
}

void ecapNotification(ecapBASE_t *ecap,uint16 flags)
{
	uint32 cap1, cap2, cap3;
	float64 duty, period;

        if( flags & ecapInt_CEVT1 ) {

            printf("just for debugging purpose");
        }

        if( flags & ecapInt_CEVT2 ) {

            printf("just for debugging purpose");

        }

        if( flags & ecapInt_CEVT3 ) {

	   cap1 = ecapGetCAP1(ecapREG1);
	   cap2 = ecapGetCAP2(ecapREG1);
	   cap3 = ecapGetCAP3(ecapREG1);

	   duty = (cap2 - cap1)*1000/VCLK4_FREQ;
	   period = (cap3 - cap1)*1000/VCLK4_FREQ;

	   printf("Duty = %fns\n", duty);
	   printf("Period = %fns\n\n", period);
        }

}

  • Hi Jens,

      Have you tried to put a breakpoint in your ecapNotification()? Once the ISR is entered, have you observed differences between CAP1, CAP2 and CAP3? It takes some time to refresh the register window in real time in the debugger. the debugger needs to scan instructions via the JTAG interface to read out the register values. If you have a fast switching input then perhaps this is the reason that you tend to see CAP1/2/3 being the same.

      The only difference I see between yours and the HalCoGen example is on the interrupt where you enable interrupt for all three events. Can you try just enabling ecapInt_CEV3 and see if it makes a difference?

    /* Enable Interrupt for CAP3 event */
        ecapEnableInterrupt(ecapREG1, ecapInt_CEVT1|ecapInt_CEVT2|ecapInt_CEVT3);
  • Hello Charles,
    thnak you very much fpr your reply. You are right it is a "Debugger Problem". After I set the FREE_SOFT Bits in the ECCTL1 Register to 0x03 (Run Free) its works like expected. With the default value 0x00 the counter seemst to stop while hold in the debugger which seems to cause the unexpected behavior.

    Kind regards
    Jens