捕获定时器

功能特性

  • 向上计数的 16 位计数器

  • 内部有 16 位的分频寄存器

  • 自动重载寄存器的值可以预加载

  • 两种工作模式:

    • 记录输入引脚的脉冲宽度

    • 记录输入引脚在可配置周期内脉冲的数量

应用示例

SDK 提供了 raw 示例,帮助开发者了解和使用捕获定时器功能:

  • 路径:{SDK}\example\peripheral\raw\Timer\{demo}

  • 展示如何在无抽象层的情况下直接控制捕获定时器

以下是对 raw 示例功能的简要说明:

备注

要了解示例支持的芯片,请查看示例路径下的 README.md 文件。

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.

参数:
  • 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.

返回:

Capture Compare x Register value.

备注

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