ECAP Module

The Enhanced Capture (eCAP) API provides a set of functions for configuring and using the eCAP module. Functions are provided to utilize both the capture and PWM capability of the eCAP module. The APIs allow for the selection and characterization of the input signal to be captured. A provision is also made to provide DMA trigger sources based on the eCAP events. The necessary APIs are also provided for PWM mode of operation.

group ecap_api

Defines

ECAP_MAX_PRESCALER_VALUE 32U
ECAP_ISR_SOURCE_CAPTURE_EVENT_1 0x2U

Event 1 ISR source

ECAP_ISR_SOURCE_CAPTURE_EVENT_2 0x4U

Event 2 ISR source

ECAP_ISR_SOURCE_CAPTURE_EVENT_3 0x8U

Event 3 ISR source

ECAP_ISR_SOURCE_CAPTURE_EVENT_4 0x10U

Event 4 ISR source

ECAP_ISR_SOURCE_COUNTER_OVERFLOW 0x20U

Counter overflow ISR source

ECAP_ISR_SOURCE_COUNTER_PERIOD 0x40U

Counter equals period ISR source

ECAP_ISR_SOURCE_COUNTER_COMPARE 0x80U

Counter equals compare ISR source

Enums

enum ECAP_EmulationMode

Values that can be passed to ECAP_setEmulationMode() as the mode parameter.

Values:

enumerator ECAP_EMULATION_STOP = 0x0U

TSCTR is stopped on emulation suspension.

enumerator ECAP_EMULATION_RUN_TO_ZERO = 0x1U

TSCTR runs until 0 before stopping on emulation suspension.

enumerator ECAP_EMULATION_FREE_RUN = 0x2U

TSCTR is not affected by emulation suspension.

enum ECAP_CaptureMode

Values that can be passed to ECAP_setCaptureMode() as the mode parameter.

Values:

enumerator ECAP_CONTINUOUS_CAPTURE_MODE = 0U

eCAP operates in continuous capture mode

enumerator ECAP_ONE_SHOT_CAPTURE_MODE = 1U

eCAP operates in one shot capture mode

enum ECAP_Events

Values that can be passed to ECAP_setEventPolarity(),ECAP_setCaptureMode(), ECAP_enableCounterResetOnEvent(),ECAP_disableCounterResetOnEvent(), ECAP_getEventTimeStamp(),ECAP_setDMASource() as the event parameter.

Values:

enumerator ECAP_EVENT_1 = 0U

eCAP event 1

enumerator ECAP_EVENT_2 = 1U

eCAP event 2

enumerator ECAP_EVENT_3 = 2U

eCAP event 3

enumerator ECAP_EVENT_4 = 3U

eCAP event 4

enum ECAP_SyncOutMode

Values that can be passed to ECAP_setSyncOutMode() as the mode parameter.

Values:

enumerator ECAP_SYNC_OUT_SYNCI = 0x00

sync out on the sync in signal and software force

enumerator ECAP_SYNC_OUT_COUNTER_PRD = 0x40

sync out on counter equals period

enumerator ECAP_SYNC_OUT_DISABLED = 0x80

Disable sync out signal.

enum ECAP_APWMPolarity

Values that can be passed to ECAP_setAPWMPolarity() as the polarity parameter.

Values:

enumerator ECAP_APWM_ACTIVE_HIGH = 0x000

APWM is active high.

enumerator ECAP_APWM_ACTIVE_LOW = 0x400

APWM is active low.

enum ECAP_EventPolarity

Values that can be passed to ECAP_setEventPolarity() as the polarity parameter.

Values:

enumerator ECAP_EVNT_RISING_EDGE = 0U

Rising edge polarity.

enumerator ECAP_EVNT_FALLING_EDGE = 1U

Falling edge polarity.

Functions

void ECAP_setEventPrescaler(uint32_t base, uint16_t preScalerValue)

Sets the input prescaler.

This function divides the ECAP input scaler. The pre scale value is doubled inside the module. For example a preScalerValue of 5 will divide the scaler by 10. Use a value of 1 to divide the pre scaler by 1. The value of preScalerValue should be less than

ECAP_MAX_PRESCALER_VALUE.
Parameters
  • base: is the base address of the ECAP module.

  • preScalerValue: is the pre scaler value for ECAP input

Return

None.

void ECAP_setEventPolarity(uint32_t base, ECAP_Events event, ECAP_EventPolarity polarity)

Sets the Capture event polarity.

This function sets the polarity of a given event. The value of event is between

ECAP_EVENT_1 and ECAP_EVENT_4 inclusive corresponding to the four available events.For each event the polarity value determines the edge on which the capture is activated. For a rising edge use a polarity value of ECAP_EVNT_RISING_EDGE and for a falling edge use a polarity of ECAP_EVNT_FALLING_EDGE.
Parameters
  • base: is the base address of the ECAP module.

  • event: is the event number.

  • polarity: is the polarity of the event.

Return

None.

void ECAP_setCaptureMode(uint32_t base, ECAP_CaptureMode mode, ECAP_Events event)

Sets the capture mode.

This function sets the eCAP module to a continuous or one-shot mode. The value of mode should be either

ECAP_CONTINUOUS_CAPTURE_MODE or ECAP_ONE_SHOT_CAPTURE_MODE corresponding to continuous or one-shot mode respectively.
Parameters
  • base: is the base address of the ECAP module.

  • mode: is the capture mode.

  • event: is the event number at which the counter stops or wraps.

The value of event determines the event number at which the counter stops (in one-shot mode) or the counter wraps (in continuous mode). The value of event should be between ECAP_EVENT_1 and ECAP_EVENT_4 corresponding to the valid event numbers.

Return

None.

void ECAP_reArm(uint32_t base)

Re-arms the eCAP module.

This function re-arms the eCAP module.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_enableInterrupt(uint32_t base, uint16_t intFlags)

Enables interrupt source.

This function sets and enables eCAP interrupt source. The following are valid interrupt sources.

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_1 - Event 1 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_2 - Event 2 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_3 - Event 3 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_4 - Event 4 generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_OVERFLOW - Counter overflow generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_PERIOD - Counter equal period generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_COMPARE - Counter equal compare generates interrupt

Parameters
  • base: is the base address of the ECAP module.

  • intFlags: is the interrupt source to be enabled.

Return

None.

void ECAP_disableInterrupt(uint32_t base, uint16_t intFlags)

Disables interrupt source.

This function clears and disables eCAP interrupt source. The following are valid interrupt sources.

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_1 - Event 1 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_2 - Event 2 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_3 - Event 3 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_4 - Event 4 generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_OVERFLOW - Counter overflow generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_PERIOD - Counter equal period generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_COMPARE - Counter equal compare generates interrupt

Parameters
  • base: is the base address of the ECAP module.

  • intFlags: is the interrupt source to be disabled.

Return

None.

uint16_t ECAP_getInterruptSource(uint32_t base)

Returns the interrupt flag.

This function returns the eCAP interrupt flag. The following are valid interrupt sources corresponding to the eCAP interrupt flag.

Parameters
  • base: is the base address of the ECAP module.

Return

Returns the eCAP interrupt that has occurred. The following are valid return values.

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_1 - Event 1 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_2 - Event 2 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_3 - Event 3 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_4 - Event 4 generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_OVERFLOW - Counter overflow generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_PERIOD - Counter equal period generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_COMPARE - Counter equal compare generates interrupt

Note

- User can check if a combination of various interrupts have occurred by ORing the above return values.

bool ECAP_getGlobalInterruptStatus(uint32_t base)

Returns the Global interrupt flag.

This function returns the eCAP Global interrupt flag.

Parameters
  • base: is the base address of the ECAP module.

Return

Returns true if there is a global eCAP interrupt, false otherwise.

void ECAP_clearInterrupt(uint32_t base, uint16_t intFlags)

Clears interrupt flag.

This function clears eCAP interrupt flags. The following are valid interrupt sources.

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_1 - Event 1 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_2 - Event 2 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_3 - Event 3 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_4 - Event 4 generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_OVERFLOW - Counter overflow generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_PERIOD - Counter equal period generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_COMPARE - Counter equal compare generates interrupt

Parameters
  • base: is the base address of the ECAP module.

  • intFlags: is the interrupt source.

Return

None.

void ECAP_clearGlobalInterrupt(uint32_t base)

Clears global interrupt flag

This function clears the global interrupt bit.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_forceInterrupt(uint32_t base, uint16_t intFlags)

Forces interrupt source.

This function forces and enables eCAP interrupt source. The following are valid interrupt sources.

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_1 - Event 1 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_2 - Event 2 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_3 - Event 3 generates interrupt

  • ECAP_ISR_SOURCE_CAPTURE_EVENT_4 - Event 4 generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_OVERFLOW - Counter overflow generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_PERIOD - Counter equal period generates interrupt

  • ECAP_ISR_SOURCE_COUNTER_COMPARE - Counter equal compare generates interrupt

Parameters
  • base: is the base address of the ECAP module.

  • intFlags: is the interrupt source.

Return

None.

void ECAP_enableCaptureMode(uint32_t base)

Sets eCAP in Capture mode.

This function sets the eCAP module to operate in Capture mode.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_enableAPWMMode(uint32_t base)

Sets eCAP in APWM mode.

This function sets the eCAP module to operate in APWM mode.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_enableCounterResetOnEvent(uint32_t base, ECAP_Events event)

Enables counter reset on an event.

This function enables the base timer, TSCTR, to be reset on capture event provided by the variable event. Valid inputs for event are

ECAP_EVENT_1 to ECAP_EVENT_4.
Parameters
  • base: is the base address of the ECAP module.

  • event: is the event number the time base gets reset.

Return

None.

void ECAP_disableCounterResetOnEvent(uint32_t base, ECAP_Events event)

Disables counter reset on events.

This function disables the base timer, TSCTR, from being reset on capture event provided by the variable event. Valid inputs for event are

ECAP_EVENT_1 to ECAP_EVENT_4.
Parameters
  • base: is the base address of the ECAP module.

  • event: is the event number the time base gets reset.

Return

None.

void ECAP_enableTimeStampCapture(uint32_t base)

Enables time stamp capture.

This function enables time stamp count to be captured

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_disableTimeStampCapture(uint32_t base)

Disables time stamp capture.

This function disables time stamp count to be captured

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_setPhaseShiftCount(uint32_t base, uint32_t shiftCount)

Sets a phase shift value count.

This function writes a phase shift value to be loaded into the main time stamp counter.

Parameters
  • base: is the base address of the ECAP module.

  • shiftCount: is the phase shift value.

Return

None.

void ECAP_enableLoadCounter(uint32_t base)

Enable counter loading with phase shift value.

This function enables loading of the counter with the value present in the phase shift counter as defined by the

ECAP_setPhaseShiftCount() function.
Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_disableLoadCounter(uint32_t base)

Disable counter loading with phase shift value.

This function disables loading of the counter with the value present in the phase shift counter as defined by the

ECAP_setPhaseShiftCount() function.
Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_loadCounter(uint32_t base)

Load time stamp counter

This function forces the value in the phase shift counter register to be loaded into Time stamp counter register. Make sure to enable loading of Time stamp counter by calling

ECAP_enableLoadCounter() function before calling this function.
Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_setSyncOutMode(uint32_t base, ECAP_SyncOutMode mode)

Configures Sync out signal mode.

This function sets the sync out mode. Valid parameters for mode are:

  • ECAP_SYNC_OUT_SYNCI - Trigger sync out on sync-in event.

  • ECAP_SYNC_OUT_COUNTER_PRD - Trigger sync out when counter equals period.

  • ECAP_SYNC_OUT_DISABLED - Disable sync out.

Parameters
  • base: is the base address of the ECAP module.

  • mode: is the sync out mode.

Return

None.

void ECAP_stopCounter(uint32_t base)

Stops Time stamp counter.

This function stops the time stamp counter.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_startCounter(uint32_t base)

Starts Time stamp counter.

This function starts the time stamp counter.

Parameters
  • base: is the base address of the ECAP module.

Return

None.

void ECAP_setAPWMPolarity(uint32_t base, ECAP_APWMPolarity polarity)

Set eCAP APWM polarity.

This function sets the polarity of the eCAP in APWM mode. Valid inputs for polarity are:

  • ECAP_APWM_ACTIVE_HIGH - For active high.

  • ECAP_APWM_ACTIVE_LOW - For active low.

Parameters
  • base: is the base address of the ECAP module.

  • polarity: is the polarity of APWM

Return

None.

void ECAP_setAPWMPeriod(uint32_t base, uint32_t periodCount)

Set eCAP APWM period.

This function sets the period count of the APWM waveform. periodCount takes the actual count which is written to the register. The user is responsible for converting the desired frequency or time into the period count.

Parameters
  • base: is the base address of the ECAP module.

  • periodCount: is the period count for APWM.

Return

None.

void ECAP_setAPWMCompare(uint32_t base, uint32_t compareCount)

Set eCAP APWM on or off time count.

This function sets the on or off time count of the APWM waveform depending on the polarity of the output. If the output , as set by

ECAP_setAPWMPolarity(), is active high then compareCount determines the on time. If the output is active low then compareCount determines the off time. compareCount takes the actual count which is written to the register. The user is responsible for converting the desired frequency or time into the appropriate count value.
Parameters
  • base: is the base address of the ECAP module.

  • compareCount: is the on or off count for APWM.

Return

None.

void ECAP_setAPWMShadowPeriod(uint32_t base, uint32_t periodCount)

Load eCAP APWM shadow period.

This function sets the shadow period count of the APWM waveform. periodCount takes the actual count which is written to the register. The user is responsible for converting the desired frequency or time into the period count.

Parameters
  • base: is the base address of the ECAP module.

  • periodCount: is the shadow period count for APWM.

Return

None.

void ECAP_setAPWMShadowCompare(uint32_t base, uint32_t compareCount)

Set eCAP APWM shadow on or off time count.

This function sets the shadow on or off time count of the APWM waveform depending on the polarity of the output. If the output , as set by

ECAP_setAPWMPolarity() , is active high then compareCount determines the on time. If the output is active low then compareCount determines the off time. compareCount takes the actual count which is written to the register. The user is responsible for converting the desired frequency or time into the appropriate count value.
Parameters
  • base: is the base address of the ECAP module.

  • compareCount: is the on or off count for APWM.

Return

None.

uint32_t ECAP_getTimeBaseCounter(uint32_t base)

Returns the time base counter value.

This function returns the time base counter value.

Parameters
  • base: is the base address of the ECAP module.

Return

Returns the time base counter value.

uint32_t ECAP_getEventTimeStamp(uint32_t base, ECAP_Events event)

Returns event time stamp.

This function returns the current time stamp count of the given event. Valid values for event are

ECAP_EVENT_1 to ECAP_EVENT_4.
Parameters
  • base: is the base address of the ECAP module.

  • event: is the event number.

Return

Event time stamp value or 0 if event is invalid.

void ECAP_setEmulationMode(uint32_t base, ECAP_EmulationMode mode)

Configures emulation mode.

This function configures the eCAP counter, TSCTR, to the desired emulation mode when emulation suspension occurs. Valid inputs for mode are:

  • ECAP_EMULATION_STOP - Counter is stopped immediately.

  • ECAP_EMULATION_RUN_TO_ZERO - Counter runs till it reaches 0.

  • ECAP_EMULATION_FREE_RUN - Counter is not affected.

Parameters
  • base: is the base address of the ECAP module.

  • mode: is the emulation mode.

Return

None.

The code for this module is contained in driverlib/ecap.c, with driverlib/ecap.h containing the API declarations for use by applications.