Tool/software:
Hi,
I'm trying to use ECAP (peripheral #1, not #0) on my board & project.
Unlike the sdk example project - I do not use the ISR function.
I tried to make some sanity testing and I'm getting odd results unlike your example output.
I've configured pin C17(MCAN1_TX) to mode 2 - APWM_ECAP1.
I'm using a signal generator to produce a 1kHz Square Pulse at both 50% and 25% Duty Cycle (2 different test cases).
This is my configuration code:
/* Disable CAP1-CAP4 register loads */
ECAP_captureLoadingDisable(gEcapBaseAddr);
/* Configure eCAP */
ECAP_counterControl(gEcapBaseAddr, ECAP_COUNTER_STOP);
/* Enable capture mode */
ECAP_operatingModeSelect(gEcapBaseAddr, ECAP_CAPTURE_MODE);
/* One shot mode, stop capture at event 4 */
ECAP_oneShotModeConfig(gEcapBaseAddr, ECAP_CAPTURE_EVENT4_STOP);
// ECAP_continuousModeConfig(gEcapBaseAddr);
/* Set polarity of the events to rising, falling, rising, falling edge */
ECAP_captureEvtPolarityConfig(gEcapBaseAddr,
ECAP_CAPTURE_EVENT_RISING,
ECAP_CAPTURE_EVENT_FALLING,
ECAP_CAPTURE_EVENT_RISING,
ECAP_CAPTURE_EVENT_FALLING);
/* Set capture in time difference mode */
ECAP_captureEvtCntrRstConfig(gEcapBaseAddr,
ECAP_CAPTURE_EVENT_RESET_COUNTER_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_RESET,
ECAP_CAPTURE_EVENT_RESET_COUNTER_RESET);
ECAP_counterControl(gEcapBaseAddr, ECAP_COUNTER_FREE_RUNNING);
ECAP_syncInOutSelect(gEcapBaseAddr, ECAP_ENABLE_COUNTER, ECAP_SYNC_IN);
/* Enable eCAP module */
ECAP_captureLoadingEnable(gEcapBaseAddr);
However - I'm not getting the right results when using:
ECAP_oneShotReArm(gEcapBaseAddr);
#### Assume there is a delay here for the registers to load ###
/* Read Counter values and print for last iteration. */
cap1Count = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_1);
cap2Count = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_2);
cap3Count = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_3);
cap4Count = ECAP_timeStampRead(gEcapBaseAddr, ECAP_CAPTURE_EVENT_4);
cap1Count sometimes shows unreasonable values like 200,000,000.
Also I would expect the values of the rising edges/falling edges would be equal in case of 50% PWM - which they aren't,
In the case of 25% - there is no data consistency much like in the 50% DC case.
Also note -> pin D18 for APWM_ECAP0 is used for the Sigma Delta clock.
Thanks in advance