Tool/software:
Hello,
I would like to use the eCAP module to measure the time delay between the falling edge of a PWM signal generated by the MCU and an external signal connected to a pin.
The way I approached this was by configuring the eCAP module to take its input on the pin via the Input Xbar, and to reset its counter on ePWM module CNT = CMPB event.
The issue that I am facing is that the eCAP get triggered almost instantly (11 sysclk ticks = 91ns) after the sync event, but the actual signal on the pin happens somewhere around 10us after. I do not understand what is the cause for this behaviour.
If I do not sync the eCAP module with the ePWM module, and measure the period and duty of the external signals, I get accurate capture results. Based on this I conclude that there is no glitch which would falsly trigger the eCAP modules.
I also tried enabling all four capture registers to see what they capture and to my suprise they all get loaded with 11 systicks. I dont understand how can this happen since only one register should get loaded per event.
I am wondering if the issue could be in the fact that I am using CNT = CMPB signal as the ePWM syncout signal to reset the eCAP counter, but i have the ePWM module in up-down counting mode and hence, CNT = CMPB happens twice in one period.
Here is my eCAP initialization sequence:
// Variables =========================================================================================================== #define eCAP1_Pin 5 // GPIO5 uporabim kot input za eCAP1 modul. #define eCAP1_PinConfig GPIO_5_GPIO5 // pin 5 funkcionalnost je GPIO. #define eCAP1_XBAR_INPUT_LINE XBAR_INPUT1 // Izbere Input Xbar linijo preko katere povežem pin in eCAP1 modul. #define eCAP1_InputMuxIndex #define eCAP1_PRESCALER 0U // Ne prescalam vhoda. // Function definitions =============================================================================================== void MyECAP1_init(void) { // Konfiguriram izbran GPIO pin za eCAP1 vhod GPIO_setPinConfig(eCAP1_PinConfig); GPIO_setDirectionMode(eCAP1_Pin, GPIO_DIR_MODE_IN); GPIO_setPadConfig(eCAP1_Pin, GPIO_PIN_TYPE_STD); GPIO_setQualificationMode(eCAP1_Pin, GPIO_QUAL_6SAMPLE); // Povežem izbran pin na input xBar. XBAR_setInputPin(INPUTXBAR_BASE, eCAP1_XBAR_INPUT_LINE, eCAP1_Pin); // Izberem ustrezeno input xBar linijo v eCAP1 input muxu. ECAP_selectECAPInput(ECAP1_BASE, ECAP_INPUT_INPUTXBAR1); // Konfiguriram polariteto in event qualifier ECAP_setEventPrescaler(ECAP1_BASE, eCAP1_PRESCALER); // Nastavim prescaler. ECAP_setEmulationMode(ECAP1_BASE, ECAP_EMULATION_FREE_RUN ); // Omogocim neprekinjeno delovanje tudi ob SW breakpointih. ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_1, ECAP_EVNT_FALLING_EDGE); ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_2, ECAP_EVNT_FALLING_EDGE); ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_3, ECAP_EVNT_FALLING_EDGE); ECAP_setEventPolarity(ECAP1_BASE, ECAP_EVENT_4, ECAP_EVNT_FALLING_EDGE); ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_1); // Prvi event resetira števec. ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_2); // Prvi event resetira števec. ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_3); // Prvi event resetira števec. ECAP_enableCounterResetOnEvent(ECAP1_BASE, ECAP_EVENT_4); // Prvi event resetira števec. ECAP_enableTimeStampCapture(ECAP1_BASE); // Omogočim, da se zajame vrednost števca ob nastanku eventa. ECAP_enableCaptureMode(ECAP1_BASE); // Omogočim delovanje v capture in ne APWM režimu. ECAP_setCaptureMode(ECAP1_BASE, ECAP_CONTINUOUS_CAPTURE_MODE, ECAP_EVENT_4); ECAP_setSyncInPulseSource(ECAP1_BASE, ECAP_SYNC_IN_PULSE_SRC_SYNCOUT_EPWM2); // Nastavim vir SyncIn pulza. ECAP_enableLoadCounter(ECAP1_BASE); // Omogocim nalaganje vrednosti v stevec ob syncin pulzu. ECAP_setPhaseShiftCount(ECAP1_BASE, 0U); // Nastavim vrednost s katere zacne stevec ob SyncIn pulzu. EPWM_enableSyncOutPulseSource(EPWM2_BASE, EPWM_SYNC_OUT_PULSE_ON_CNTR_ZERO); // Nastavim vir epwm syncout pulza. ECAP_resetCounters(ECAP1_BASE); // Ponastavim vse stevce v eCAP1 modulu in pripravim na zagon. ECAP_startCounter(ECAP1_BASE); // Pozenem stevec eCAP1 modula. return; }
I have also attached a .zip file of the entire project folder if that helps.
240614 TI e2e eCAP SupportTicket.zip
I am really looking forward to any suggestions.
Regards,
Samo