STM32学习笔记(5)——定时器中断

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

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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值