STM32F1 的通用定时器是一个通过可编程预分频器(PSC)驱动的 16 位自动装载计数器(CNT)构成。
其中有4 个独立通道(TIMx_CH1~4),这些通道可以用来作为:
A.输入捕获
B.输出比较
C.PWM生成(边缘或中间对齐模式)
D.单脉冲模式输出
TIM1、8、9、10、11、15、16、17挂在APB2上
TIM2、3、4、5、6、7、12、13、14挂在APB1上
(1)使能时钟
(2)初始化定时器参数,设置自动重装值,分频系数,计数方式等
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

本文详细介绍了STM32F1系列芯片中通用定时器TIM3的配置过程,包括时钟使能、参数初始化、中断设置、中断优先级配置以及中断服务函数的编写。通过具体实例展示了如何使用TIM3实现LED闪烁,并提供了中断时间的计算公式。同时,提到了TIM3的时钟频率和中断周期,强调了初始化过程中预分频器和自动重载值的设置对中断周期的影响。
——定时器中断&spm=1001.2101.3001.5002&articleId=113835253&d=1&t=3&u=99096bf7eedb4edaa8b5010b709acbd1)
2667

被折叠的 条评论
为什么被折叠?



