ECAP外设
1.function name:
function description:
this function checks whether the specified base address of the eCAP module is valid. In debug mode, this function helps verify that the base address provided is a valid eCAP module address. This function takes effect only when DEBUG
compiled in mode.
parameter description:
- input parameters:
-
uint32_t base
: Base address of the specified eCAP module. -
output parameters:
bool
: Returnstrue
if the base address is valid, otherwise returnsfalse
.
2.function name:
function description:
this function sets the input prescaler value for the eCAP module. The prescaler is used to reduce the frequency of the input signal. The prescale value is doubled inside the block, for example, preScalerValue
at 5, the actual divider value is 10. When used preScalerValue = 1
, the frequency divider is not changed. The value should be less than ECAP_MAX_PRESCALER_VALUE
. The base function uses ECAP_isBaseValid
a macro to verify the validity of the base address. The and EDIS
are used EALLOW
to enable and disable write access to protected registers.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.uint16_t preScalerValue
: The value of the prescaler, which is applied to the eCAP input signal. The prescaler value is internally multiplied by 2.
output parameters:
- no return value.
3.function name:
function description:
this function sets the polarity of the specified eCAP event. The polarity of the event determines the trigger edge of the capture signal. The eCAP module supports 4 events with event numbers ranging from ECAP_EVENT_1
to ECAP_EVENT_4
. For each event, the polarity determines whether the rising or falling edge triggers the capture. Use ECAP_EVNT_RISING_EDGE
for rising edge and ECAP_EVNT_FALLING_EDGE
for falling edge. -This function verifies the legitimacy of the eCAP base address through ECAP_isBaseValid
a macro. The and EDIS
are used EALLOW
to enable and disable write access to protected registers. The polarity of the specified event is adjusted by the offset calculation and written to the appropriate register.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.ECAP_Events event
: The specified event number in the rangeECAP_EVENT_1
toECAP_EVENT_4
.ECAP_EventPolarity polarity
: The specified event polarity, eitherECAP_EVNT_RISING_EDGE
(rising edge) orECAP_EVNT_FALLING_EDGE
(falling edge).
output parameters:
- no return value.
4.function name:
function description:
this function is used to set the capture mode of the eCAP module. The continuous capture mode or the single capture mode can be selected. The user can specify that the counter stops when an event triggers or loops around in continuous mode. This function implements the corresponding settings by modifying the relevant registers of the eCAP module.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.ECAP_CaptureMode mode
: Capture mode, which can be one of two values:ECAP_CONTINUOUS_CAPTURE_MODE
: Continuous capture mode.ECAP_ONE_SHOT_CAPTURE_MODE
: Single capture mode.
ECAP_Events event
: The number of the event that triggered the stop or wrap. Values should beECAP_EVENT_1
between andECAP_EVENT_4
for each of the four valid events.
output parameters:
- no return value.
remark
- this function first verifies the validity of the eCAP base address through
ECAP_isBaseValid
a macro. - the and
EDIS
are usedEALLOW
to enable and disable write access to protected registers. - the function sets the capture mode and stop/wrap events by modifying
ECCTL2
the relevant bits of the register.
5.function name:
function description:
this function is used to reenable (reload) the eCAP module. This function reactivates the eCAP module to capture a new event by setting the corresponding control register.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- no return value.
remark
- this function uses a
ECAP_isBaseValid
macro to verify that the eCAP base address is valid. - use
EALLOW
andEDIS
to enable and disable write access to protected registers. - reenable the eCAP module by setting
ECCTL2
the bit inRE-ARM
the register.
6.function name:
function description:
this function enables the specified eCAP interrupt source. It enables specific interrupts for the eCAP module by setting the relevant interrupt flag bit.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.uint16_t intFlags
: The interrupt source to enable. Valid interrupt sources include:ECAP_ISR_SOURCE_CAPTURE_EVENT_1
: Capture event 1 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_2
: Capture event 2 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_3
: Capture event 3 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_4
: Capture Event 4 triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_OVERFLOW
: Counter overflow triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_PERIOD
: The counter is equal to the cycle trigger interrupt.ECAP_ISR_SOURCE_COUNTER_COMPARE
: An interrupt is triggered when the counter equals the compare value.
output parameters:
- no return value.
remark
- this function uses a
ECAP_isBaseValid
macro to verify that the eCAP base address is valid. - use
EALLOW
andEDIS
to enable and disable write access to protected registers. - set the specified interrupt source bit in the
ECEINT
register to enable the corresponding interrupt.
7.function name:
function description:
this function disables the specified eCAP interrupt source. It disables specific interrupts for the eCAP module by clearing the associated interrupt flag bit.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.uint16_t intFlags
: The interrupt source to disable. Valid interrupt sources include:ECAP_ISR_SOURCE_CAPTURE_EVENT_1
: Capture event 1 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_2
: Capture event 2 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_3
: Capture event 3 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_4
: Capture Event 4 triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_OVERFLOW
: Counter overflow triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_PERIOD
: The counter is equal to the cycle trigger interrupt.ECAP_ISR_SOURCE_COUNTER_COMPARE
: An interrupt is triggered when the counter equals the compare value.
output parameters:
- no return value.
remark
- this function uses a
ECAP_isBaseValid
macro to verify that the eCAP base address is valid. - use
EALLOW
andEDIS
to enable and disable write access to protected registers. - clear the specified interrupt source bit in the
ECEINT
register to disable the corresponding interrupt.
8.function name:
function description:
this function is used to get the interrupt flag of the eCAP module. It returns the type of interrupt that occurred so that the user is aware of the specific interrupt event.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- return value:
- return the eCAP interrupt flag. Possible return values include:
ECAP_ISR_SOURCE_CAPTURE_EVENT_1
: Capture event 1 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_2
: Capture event 2 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_3
: Capture event 3 triggers an interrupt.ECAP_ISR_SOURCE_CAPTURE_EVENT_4
: Capture Event 4 triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_OVERFLOW
: Counter overflow triggers an interrupt.ECAP_ISR_SOURCE_COUNTER_PERIOD
: The counter is equal to the cycle trigger interrupt.ECAP_ISR_SOURCE_COUNTER_COMPARE
: An interrupt is triggered when the counter equals the compare value.
remark
- this function uses a
ECAP_isBaseValid
macro to verify that the eCAP base address is valid. - the function returns
ECFLG
the contents of a register and bitwise and with0xFE
to obtain the associated interrupt flag. - the user can check whether multiple interrupts occurred at the same time by bit-ORing the return value.
9.function name:
function description:
this function is used to get the global interrupt flag of the eCAP module. It returns a Boolean value indicating whether there is a global interrupt.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- return value:
- returns a Boolean value:
true
: if there is a global eCAP interrupt.false
: if there is no global eCAP interrupt.
remark
- this function uses a
ECAP_isBaseValid
macro to verify that the eCAP base address is valid. - the function checks
ECFLG
the global interrupt bit (least significant bit) of the register to determine the global interrupt status.
10.Function name ECAP_getGlobalInterruptStatus(uint32_t base)
function description:
this function is used to obtain the global interrupt status of the ECAP module and return the contents of the global interrupt bit. When the interrupt flag is cleared, the following interrupt sources are in effect:
- ECAP_ISR_SOURCE_CAPTURE_EVENT_1
: Event 1 generates an interrupt
- ECAP_ISR_SOURCE_CAPTURE_EVENT_2
: Event 2 generates an interrupt
- ECAP_ISR_SOURCE_CAPTURE_EVENT_3
: Event 3 generates an interrupt
- ECAP_ISR_SOURCE_CAPTURE_EVENT_4
: Event 4 generates an interrupt
- ECAP_ISR_SOURCE_COUNTER_OVERFLOW
: Counter overflow generates interrupt
- ECAP_ISR_SOURCE_COUNTER_PERIOD
: Counter equals cycle generation interrupt
- ECAP_ISR_SOURCE_COUNTER_COMPARE
: Counter equals compare generates interrupt
parameter description:
- enter the parameters:
-
base
: Base address of the ECAP module. -
output parameters:
- return value: a Boolean value indicating the global interrupt status (true means the interrupt has occurred).
11.function name:
function description:
this function is used to clear the global interrupt flag of the eCAP module.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- no return value
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - the global interrupt flag is then cleared by writing
ECCLR
to the INT bit in the register.
12.function name:
function description:
this function forces the activation and enables the eCAP interrupt source.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.uint16_t intFlags
: The interrupt source to activate.
output parameters:
- no return value
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - these interrupts are then forced active by
ECFRC
writing the specified interrupt source flag to the register.
13.function name:
function description:
this function sets the eCAP module to capture mode.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- no return value
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - the eCAP module is then set to capture mode by clearing
ECCTL2
the bit inCAP/APWM
the register.
14.function name:
function description:
this function sets the eCAP module to APWM (Automatic Pulse Width Modulation) mode.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.
output parameters:
- no return
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - the eCAP module is then configured for APWM mode by setting
ECCTL2
the bit inCAP/APWM
the register.
15.function name:
function description:
this function enables the reset of the counter (TSCTR) when a capture event occurs.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.ECAP_Events event
: The number of the event that triggered the reset of the counter, rangingECAP_EVENT_1
from toECAP_EVENT_4
.
output parameters:
- no return value.
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - the reset of the counter when a capture event occurs is then enabled by setting
ECCTL1
the corresponding bit in the register.
16.function name:
function description:
this function disables the reset function of the counter (TSCTR) when a capture event occurs.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.ECAP_Events event
: The number of the event that triggered the reset of the counter, rangingECAP_EVENT_1
from toECAP_EVENT_4
.
output parameters:
- no return value
remark
- the function first verifies the validity of the incoming eCAP base address through a
ECAP_isBaseValid
macro. - the reset function of the counter when a capture event occurs is then disabled by clearing
ECCTL1
the corresponding bit in the register.
17.function name:
function description:
this function enables timestamp capture. The function first verifies that the incoming eCAP base address is valid and then enables the capture of the timestamp count by setting ECCTL1
the bit in CAPLDEN
the register.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
18.function name:
function description:
this function disables timestamp capture. The function first verifies that the incoming eCAP base address is valid and then disables the capture of the timestamp count by clearing ECCTL1
the bit in CAPLDEN
the register.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
19.function name:
function description:
this function sets the phase shift value count. The function first verifies that the incoming eCAP base address is valid and then writes the phase shift value to the master timestamp counter.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
uint32_t shiftCount
: Phase shift value. -
output parameters:
- no return value.
20.function name:
function description:
this function enables the counter to load the phase shift value. The function first verifies that the incoming eCAP base address is valid and then enables counter loading by setting ECCTL2
the bit in SYNCI_EN
the register.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
21.function name:
function description:
this function disables the counter from loading the phase shift value. The function first verifies that the incoming eCAP base address is valid and then disables the counter load by clearing ECCTL2
the bit in SYNCI_EN
the register.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
22.function name:
function description:
this function is used to load the timestamp counter register with the value in the phase shift counter register. Before calling this function, ensure that you have enabled the loading of the timestamp counter by calling ECAP_enableLoadCounter()
the function.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
23.function name:
function description:
this function is used to configure the synchronous output signal mode. Valid mode parameters are:
- ECAP_SYNC_OUT_SYNCI
— Triggers Sync Out on the Sync In event.
- ECAP_SYNC_OUT_COUNTER_PRD
-The sync output is triggered when the counter is equal to the period.
- ECAP_SYNC_OUT_DISABLED
-Disable synchronous output.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_SyncOutMode mode
: Synchronous output mode. -
output parameters:
- no return value.
24.function name:
function description:
this function stops the timestamp counter.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
25.function name:
function description:
this function is used to start the timestamp counter.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
26.function name:
function description:
this function sets the polarity of the eCAP in APWM mode. Valid polarity inputs include:
- ECAP_APWM_ACTIVE_HIGH
-Indicates active high.
- ECAP_APWM_ACTIVE_LOW
-Indicates active low.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_APWMPolarity polarity
: Polarity of APWM. -
output parameters:
- no return value.
27.function name:
function description:
this function sets the cycle count of the APWM waveform. periodCount
is the actual count written to the register, and the user needs to convert the desired frequency or time to a cycle count.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
uint32_t periodCount
: Cycle count for APWM. -
output parameters:
- no return value.
28.function name:
function description:
this function sets the on-off time count of the APWM waveform, depending on the polarity of the output. compareCount
is the actual count written to the register, and the user needs to convert the desired frequency or time to the corresponding count value.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
uint32_t compareCount
: Switching time count for APWM. -
output parameters:
- no return value.
29.function name:
function description:
this function sets the shadow cycle count for the APWM waveform. periodCount
is the actual count written to the register, and the user needs to convert the desired frequency or time to a cycle count.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
uint32_t periodCount
: Shadow cycle count for APWM. -
output parameters:
- no return value.
30.Function name: ECAP_setAPWMShadowCompare(uint32_t base, uint32_t compareCount)
function description:
this function sets the shadow on-off time count for the APWM waveform, depending on the polarity of the output. compareCount
is the actual count written to the register, and the user needs to convert the desired frequency or time to the corresponding count value.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
uint32_t compareCount
: Shadow on-off time count for APWM. -
output parameters:
- no return value.
31.function name:
function description:
this function returns the value of the time reference counter.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- returns the value of the time reference counter.
32.function name:
function description:
this function returns the current timestamp count for the given event. Valid event values are ECAP_EVENT_1
through ECAP_EVENT_4
.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_Events event
: Event number. -
output parameters:
- returns the event timestamp value, or 0 if the event is invalid.
33.function name:
function description:
this function selects the eCAP input signal.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_InputCaptureSignals input
: eCAP input signal. -
output parameters:
- no return value.
34.function name:
function description:
this function resets the master counter (TSCTR register), the event filter, the modulus counter, the capture event, and the counter overflow flag.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- no return value.
35.function name:
function description:
this function sets the eCAP event source for the DMA. Valid event values are ECAP_EVENT_1
through ECAP_EVENT_4
.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_Events event
: eCAP event. -
output parameters:
- no return value.
36.function name:
function description:
the function returns the modulus counter status indicating which register will be loaded for the next capture event.
parameter description:
- input parameters:
-
uint32_t base
: The base address of the eCAP module. -
output parameters:
- **Returns a
ECAP_EVENT_n
value indicating that CAPn is the register to be loaded for the next event. **
37.function name:
function description:
this function configures the emulation mode required by the eCAP counter (TSCTR) when the emulation is suspended. Valid models include:
- ECAP_EMULATION_STOP
-The counter stops immediately.
- ECAP_EMULATION_RUN_TO_ZERO
-The counter runs until it reaches 0.
- ECAP_EMULATION_FREE_RUN
-The counter is not affected.
parameter description:
- input parameters:
uint32_t base
: The base address of the eCAP module.-
ECAP_EmulationMode mode
: Simulation mode. -
output parameters:
- no return value.