STM32定时器参数详解

本文介绍了STM32中用于配置定时器基本参数的TIM_TimeBaseInitTypeDef结构体,包括预分频值、计数模式、计数周期等。同时,还详细说明了TIM_ICInitTypeDef结构体,用于设置定时器输入捕获模块的参数,如捕获通道、极性、输入源等。
摘要由CSDN通过智能技术生成

一.TIM_TimeBaseInitTypeDef结构体:

TIM_TimeBaseInitTypeDef结构体是用于配置定时器(Timer)的基本参数的结构体类型。在使用定时器时,我们需要对其进行初始化和配置,以确定定时器的工作模式、时钟源、分频系数、计数周期等参数。

TIM_TimeBaseInitTypeDef 结构体包含以下成员:

  • TIM_Prescaler:定时器的预分频值,用于将定时器输入时钟进行分频,以控制计数频率。(它的作用是调整定时器的计数速度,从而实现不同的定时精度和计数范围)
  • TIM_CounterMode:定时器的计数模式,包括向上计数、向下计数和中央对齐计数等模式。
  • TIM_Period:定时器的计数周期,决定了定时器的溢出时间。(自动重装载值,决定了定时器计数器的上限值)
  • TIM_ClockDivision:定时器的时钟分频,用于进一步分频计数器的时钟。
  • TIM_RepetitionCounter:重复计数器的值,用于设定计数器的重复计数次数。
typedef struct
{
  uint16_t TIM_Prescaler;         /*!< Specifies the prescaler value used to divide the TIM clock.
                                       This parameter can be a number between 0x0000 and 0xFFFF */

  uint16_t TIM_CounterMode;       /*!< Specifies the counter mode.
                                       This parameter can be a value of @ref TIM_Counter_Mode */

  uint16_t TIM_Period;            /*!< Specifies the period value to be loaded into the active
                                       Auto-Reload Register at the next update event.
                                       This parameter must be a number between 0x0000 and 0xFFFF.  */ 

  uint16_t TIM_ClockDivision;     /*!< Specifies the clock division.
                                      This parameter can be a value of @ref TIM_Clock_Division_CKD */

  uint8_t TIM_RepetitionCounter;  /*!< Specifies the repetition counter value. Each time the RCR downcounter
                                       reaches zero, an update event is generated and counting restarts
                                       from the RCR value (N).
                                       This means in PWM mode that (N+1) corresponds to:
                                          - the number of PWM periods in edge-aligned mode
                                          - the number of half PWM period in center-aligned mode
                                       This parameter must be a number between 0x00 and 0xFF. 
                                       @note This parameter is valid only for TIM1 and TIM8. */
} TIM_TimeBaseInitTypeDef;    

 二.TIM_ICInitTypeDef结构体:

TIM_ICInitTypeDef结构体的成员变量用于配置STM32中的定时器输入捕获模块的参数。以下是该结构体的主要成员及其功能的解释:

  1. uint16_t TIM_Channel:指定输入捕获通道。可以选择定时器的不同输入捕获通道,例如TIM_Channel_1、TIM_Channel_2等。

  2. uint16_t TIM_ICPolarity:指定输入捕获通道的捕获极性。可以选择输入信号的上升沿或下降沿作为触发捕获事件。

  3. uint16_t TIM_ICSelection:指定输入捕获通道的输入源。可以选择输入捕获通道的输入源,如TIM_ICSelection_DirectTI或TIM_ICSelection_IndirectTI。

  4. uint16_t TIM_ICPrescaler:指定输入捕获通道的预分频器。可以设置输入捕获通道的预分频器值,用于将输入信号的频率降低。

  5. uint16_t TIM_ICFilter:指定输入捕获通道的滤波器。可以设置输入捕获通道的滤波器系数,用于去除输入信号中的噪声或抖动。

typedef struct
{

  uint16_t TIM_Channel;      /*!< Specifies the TIM channel.
                                  This parameter can be a value of @ref TIM_Channel */

  uint16_t TIM_ICPolarity;   /*!< Specifies the active edge of the input signal.
                                  This parameter can be a value of @ref TIM_Input_Capture_Polarity */

  uint16_t TIM_ICSelection;  /*!< Specifies the input.
                                  This parameter can be a value of @ref TIM_Input_Capture_Selection */

  uint16_t TIM_ICPrescaler;  /*!< Specifies the Input Capture Prescaler.
                                  This parameter can be a value of @ref TIM_Input_Capture_Prescaler */

  uint16_t TIM_ICFilter;     /*!< Specifies the input capture filter.
                                  This parameter can be a number between 0x0 and 0xF */
} TIM_ICInitTypeDef;

  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LJX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值