新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > STM32-普通定时器TIM3

STM32-普通定时器TIM3

作者: 时间:2016-11-13 来源:网络 收藏
理解掌握一个单片机模块可以从底层硬件结构来入手也可以从软件来切入。当然相辅相成可以加快对模块工作方式的理解,便于掌握,加快提高解决问题的方法和能力。

对于新手去看timer的硬件框图,还是有一定难度的。如何先感性的理解timer的结构及使用它。

本文引用地址://m.amcfsurvey.com/article/201611/316474.htm

关于STM32的定时器我们可以从参考手册和数据手册得到分类:

1、高级定时器 TIM1和TIM8

2、普通功能定时器

3、基本定时器

从手册上可以得到不能定时器的功能有稍微差别:

那我们先从简单的普通功能定时器来入手。选择TIM3

先看一下time-base 单元:

下面来看一下timebase的结构体:可以看到有预分频、计数模式、自动装载值等,

  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. 被装载到自动装载寄存器里(在下一次更新事件时(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;

首先我们先了解第一项 TIM-Prescaler。即预分频

对于下图的prescaler counter 是预分频的计数器(分频也需要计数)。对照图74的该项,即可看出来。

代码中第二项TIM-CounterMode

向上模式

怎么算计时呢?下一篇再分析。



评论


技术专区

关闭