type
status
date
slug
summary
tags
category
icon
password
文章筛选
stm32定时器基本简介
f4:
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9cef305e-2b0f-490d-9ec3-dc603b2d3615%2Fbe3267c7-e95f-4fd1-bd46-cf5b4b4c75c7%2FUntitled.png?table=block&id=8e62a7fb-02f3-4c02-9dd6-c6f0b924ffe4&t=8e62a7fb-02f3-4c02-9dd6-c6f0b924ffe4&width=555&cache=v2)
stm32定时器时钟频率
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9cef305e-2b0f-490d-9ec3-dc603b2d3615%2Fbe7cf707-546c-4c7c-bbfc-b216532286d5%2FUntitled.png?table=block&id=9adf07bf-518e-471e-ab19-873b753ad823&t=9adf07bf-518e-471e-ab19-873b753ad823&width=869&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9cef305e-2b0f-490d-9ec3-dc603b2d3615%2F398378da-1e32-4df9-996b-d33fd0b632b2%2FUntitled.png?table=block&id=5a0a5f0e-f695-420c-8497-7106f29c2ed3&t=5a0a5f0e-f695-420c-8497-7106f29c2ed3&width=708&cache=v2)
因为系统初始化 SystemInit 函数里面已经初始化 APB1 的时钟为 4 分频,所以 APB1 的时钟为 42M,而从 STM32F4 的内部时钟树图(上图)得知:
(1)当 APB1 的时钟分频数为 1 的时候,TIM2~7 以及 TIM12~14 的时钟为APB1 的时钟,
(2)而如果 APB1 的时钟分频数不为 1,那么 TIM2~7 以及 TIM12~14 的时钟频率将为 APB1 时钟的两倍
这里还要注意的就是高级定时器以及 TIM9~TIM11 的时钟不是来
自 APB1,而是来自 APB2 的。(其定时器的时钟频率和APB1类似)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F951dc183-9280-4de6-a6f1-2696f6dc88f6%2FUntitled.png?table=block&id=b8e971c9-f0eb-464c-883e-e53ceef123f4&t=b8e971c9-f0eb-464c-883e-e53ceef123f4&width=872&cache=v2)
定时器溢出时间的计算:
Tout= ((arr+1)*(psc+1))/Tclk;
其中:
Tclk:TIM 的输入时钟频率(单位为 hz)。
Tout:TIM溢出时间(单位为 s)。
例如:
主函数中调用该函数TIM3_Int_Init(5000-1,8400-1);
其溢出时间的计算如下:
定时器时钟84M,分频系数8400,所以84M/8400=10Khz的计数频率,计数 5000 次为 500ms。
- 作者:也平凡
- 链接:https://www.990001.xyz/blog/st3
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。