当前位置:网站首页>STM32中什么是预分频
STM32中什么是预分频
2022-07-22 09:42:00 【Obito_TXP】
在STM32的定时器中,预分频器(Prescaler-PSC)用来将定时器时钟源进行分频输出。
预分频器的值由寄存器TIMx_PSC设定,是一个16位正整数值。
STM32CubeMX中的TIM预分频设置
在STM32系统中,定时器的时钟源为内部时钟时,其频率一般都比较高,以STM32F103的TIM1为例,其总线时钟最大为72MHz,体现在16位的定时器上的效果就是从0计数到65535上溢只需要0.9毫秒。如果我们需要更长时间的定时间隔,那么就需要预分频器对时钟进行分频处理,以降低定时器时钟(CK_CNT)的频率。
除此之外,也可以通过配置预分频器,来获取想要的定时器时钟频率。依然以上边的TIM1为例,如果我们想获取一个精确的1ms中断,如果不分频,72MHz的时钟对应每周期1/72us,十分不利于计算。这时候使用预分频器将其72分频后为1MHz,每周期1us,1000个计时周期即为1ms,这样既便于计算,定时也更加精确。
预分频器的工作的工作原理是,定时器时钟源每tick一次,预分频器计数器值+1,直到达到预分频器的设定值,然后再tick一次后计数器归零,同时,CNT计数器值+1。
由此可以看出,因为达到最大值后还要再tick一次才归零,所以定时器时钟频率应该为Fosc/(PSC+ 1)。其中Fosc是定时器的时钟源。比如想对时钟源进行72分频,那么预分频器的值就应该设置为71。
预分频器值寄存器TIMx_PSC存在影子寄存器(官方翻译为缓冲功能),所以在定时器启动后更改TIMx_PSC的值并不会立即影响当前定时器的时钟频率。要等到下一个更新事件(UEV)发生时才会生效。比如下边这张图就体现了将分频系数由1修改为2(即TIMx_PSC由0更改为1)时整个定时器的时序图。
预分频器值更改时的定时器时序图
更新事件(UEV)则由TIMx_CR1寄存器中的UDIS位控制,在启用时,会通过以下两种方式触发 :
- 计数器上溢
- 手动将 TIMx_EGR 寄存器中的UG 位置 1
边栏推荐
- Has the climate changed in Hebei and Zhejiang?
- Mysql5.7 decompression configuration steps
- Create objects using factory methods
- 协同办公市场暴增背后:融云通信能力是需求重点
- Leetcode daily question 2022/1/31-2022/2/6
- Terminal data protection of Internet communication security
- Flutter 通过拖拽调整绘制图形
- 2022版Centos8 yum镜像安装&阿里云安装Mysql 5.7教程与问题解决
- 融云漫话:没有一个人躲得过“视频会议”
- 什么是“实时”
猜你喜欢
Create objects using factory methods
How can one page nest another page in thymeleaf? About page nesting, the tag tells you what you should know
Help brand insight -- Analysis of consumers' emotional behavior
Global scope and function scope
Grafana panel - about conversion
2022版Centos8 yum镜像安装&阿里云安装Mysql 5.7教程与问题解决
How to add funding information when writing a paper with latex
Programmer interview golden code interview question 01.05. primary editing
garbage collection
Atmospheric environment monitoring scheme for 4G industrial router
随机推荐
In his early 30s, he became a doctoral director of Fudan University. Chen Siming: I want to write both codes and poems
Methods of wrapping classes and strings
Leetcode notes
LeetCode 每日一题 2021/11/29-2021/12/5
Oracle容器数据库的安装和使用
Leetcode daily question 2021/12/20-2021/12/26
Leetcode: 185. all employees with the top three highest wages in the Department
How latex abbreviates the author's name to et al when writing references
Grafana panel - about conversion
2022版Centos8 yum镜像安装&阿里云安装Mysql 5.7教程与问题解决
关于红队方面的学习资料
关于人力外包公司那些事
idea快速上手指南
grafana面板-关于转换
Flutter 第一個程序Hello World!
About human resource outsourcing companies
不再执着于用产品说话,苹果库克加大美国反垄断游说投入:今年上半年支出 460 万美元
Grafana panel - override field values
How to add funding information when writing a paper with latex
Renjie, chief scientist of rongyun: experience produces talents, and career "experience > experience"