Capture Timer

Features

  • 16-bit up-counter

  • 16-bit programmable prescaler

  • Preloadable auto-reload register

  • Operation modes:

    • Pulse width measurement

    • Pulse counting within configurable window

Application Examples

SDK provides raw implementation examples for Capture Timer:

  • Path: {SDK}\example\peripheral\raw\Timer\{demo}

  • Demonstrates direct register-level capture control

Key implementations:

Note

Check example’s README.md for supported chip information.

API

Raw API

CAPTIMER Exported Constants

TIM CC Pulse Mode
/* Input pulse mode: measure pulse width. */
#define TIM_CCMode_PulseWidth ((u32)0x00000000)

/* Input pulse mode: count pulse number. */
#define TIM_CCMode_PulseNumber ((u32)0x10000000)

/* Check if TIM pulse mode value is valid. */
#define IS_TIM_CC_PULSEMODE (((MODE) == TIM_CCMode_PulseWidth) || \
    ((MODE) == TIM_CCMode_PulseNumber))

/* Maximum CCR value mask (16-bit). */
#define TIM_CCMode_CCR ((u32)0x0000FFFF)

/* Check if pulse width compare value fits in CCR. */
#define IS_TIM_CC_PULSEWIDTH ((Compare) <= TIM_CCMode_CCR)
TIM Capture Type
RTL8721Dx:
/* Check if peripheral is an input pulse capture timer. */
#define IS_TIM_INPULSE_TIM (((PERIPH) == TIM9) || \
    ((PERIPH) == TIM9_S))

CAPTIMER Exported Functions

u32 RTIM_CCRxGet(RTIM_TypeDef *TIMx, u16 TIM_Channel)

Get the TIMx Capture Compare X register value.

Parameters:
  • TIMx – The TIM peripheral with CCM capability. See IS_TIM_CCM_TIM macro.

  • TIM_Channel – The channel to be read, which can be one of the following parameters TIM Channel.

Returns:

Capture Compare x Register value.

Note

If you want to get pulse width of PWM, remember to plus 1 to the return value of this function.