STM32-普通定時(shí)器TIM3
對(duì)于新手去看timer的硬件框圖,還是有一定難度的。如何先感性的理解timer的結(jié)構(gòu)及使用它。
本文引用地址:http://www.biyoush.com/article/201611/316474.htm關(guān)于STM32的定時(shí)器我們可以從參考手冊(cè)和數(shù)據(jù)手冊(cè)得到分類:
1、高級(jí)定時(shí)器 TIM1和TIM8
2、普通功能定時(shí)器
3、基本定時(shí)器
從手冊(cè)上可以得到不能定時(shí)器的功能有稍微差別:
那我們先從簡(jiǎn)單的普通功能定時(shí)器來(lái)入手。選擇TIM3。
先看一下time-base 單元:
下面來(lái)看一下timebase的結(jié)構(gòu)體:可以看到有預(yù)分頻、計(jì)數(shù)模式、自動(dòng)裝載值等,
- 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. 被裝載到自動(dòng)裝載寄存器里(在下一次更新事件時(shí)(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;
首先我們先了解第一項(xiàng) TIM-Prescaler。即預(yù)分頻
對(duì)于下圖的prescaler counter 是預(yù)分頻的計(jì)數(shù)器(分頻也需要計(jì)數(shù))。對(duì)照?qǐng)D74的該項(xiàng),即可看出來(lái)。
代碼中第二項(xiàng)TIM-CounterMode
向上模式
怎么算計(jì)時(shí)呢?下一篇再分析。
評(píng)論