STM32-普通定时器TIM3
对于新手去看timer的硬件框图,还是有一定难度的。如何先感性的理解timer的结构及使用它。
本文引用地址:https://www.eepw.com.cn/article/201611/316474.htm关于STM32的定时器我们可以从参考手册和数据手册得到分类:
1、高级定时器 TIM1和TIM8
2、普通功能定时器
3、基本定时器
从手册上可以得到不能定时器的功能有稍微差别:
那我们先从简单的普通功能定时器来入手。选择TIM3。
先看一下time-base 单元:
下面来看一下timebase的结构体:可以看到有预分频、计数模式、自动装载值等,
- typedefstruct
- {
- 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. 被装载到自动装载寄存器里(在下一次更新事件时(update event))*/
- 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-Prescaler。即预分频
对于下图的prescaler counter 是预分频的计数器(分频也需要计数)。对照图74的该项,即可看出来。
代码中第二项TIM-CounterMode
向上模式
怎么算计时呢?下一篇再分析。
评论