新聞中心

STM32-普通定時(shí)器TIM3

作者: 時(shí)間:2016-11-13 來(lái)源:網(wǎng)絡(luò) 收藏
理解掌握一個(gè)單片機(jī)模塊可以從底層硬件結(jié)構(gòu)來(lái)入手也可以從軟件來(lái)切入。當(dāng)然相輔相成可以加快對(duì)模塊工作方式的理解,便于掌握,加快提高解決問(wèn)題的方法和能力。

對(duì)于新手去看timer的硬件框圖,還是有一定難度的。如何先感性的理解timer的結(jié)構(gòu)及使用它。

本文引用地址:http://butianyuan.cn/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)裝載值等,

  1. typedefstruct
  2. {
  3. uint16_t TIM_Prescaler;/*!< Specifies the prescaler value used to divide the TIM clock.
  4. This parameter can be a number between 0x0000 and 0xFFFF */
  5. uint16_t TIM_CounterMode;/*!< Specifies the counter mode.
  6. This parameter can be a value of @ref TIM_Counter_Mode */
  7. uint16_t TIM_Period;/*!< Specifies the period value to be loaded into the active
  8. Auto-Reload Register at the next update event.
  9. This parameter must be a number between 0x0000 and 0xFFFF. 被裝載到自動(dòng)裝載寄存器里(在下一次更新事件時(shí)(update event))*/
  10. uint16_t TIM_ClockDivision;/*!< Specifies the clock division.
  11. This parameter can be a value of @ref TIM_Clock_Division_CKD */
  12. uint8_t TIM_RepetitionCounter;/*!< Specifies the repetition counter value. Each time the RCR downcounter
  13. reaches zero, an update event is generated and counting restarts
  14. from the RCR value (N).
  15. This means in PWM mode that (N+1) corresponds to:
  16. - the number of PWM periods in edge-aligned mode
  17. - the number of half PWM period in center-aligned mode
  18. This parameter must be a number between 0x00 and 0xFF.
  19. @note This parameter is valid only for TIM1 and TIM8. */
  20. } 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í)呢?下一篇再分析。



關(guān)鍵詞: STM3普通定時(shí)器TIM

評(píng)論


技術(shù)專區(qū)

關(guān)閉