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); } }