You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
974 B
44 lines
974 B
## Timer
|
|
https://blog.csdn.net/qq_45138815/article/details/117954035
|
|
定时器Cube MX代码生成,tim.h tim.c
|
|
|
|
记得开启中断
|
|
|
|
#### 定时器间隔计算
|
|
由时钟树,获得MCU 频率, 如72MHZ,即 一秒 72 000 000
|
|
|
|
|
|
PSC为16位预置数寄存器 (TIM1_PSC); 71
|
|
|
|
ARR 为16位自动重载寄存器 (TIM1_ARR);4999
|
|
|
|
Update_event = 72 000 000/((71 + 1)*(4999 + 1)*(1)) = 200
|
|
|
|
即 1秒 200次, 即1/200秒 = 0.005秒 5ms
|
|
|
|
Tout= ((arr+1)*(psc+1))/Tclk
|
|
Tclk:TIM3 的输入时钟频率(单位为 Mhz)。 72(对应时间us) 不是72000000(对应时间s)
|
|
Tout:TIM3 溢出时间(单位为 us)。
|
|
|
|
### 开启时钟中断
|
|
__HAL_TIM_ENABLE(&htim5);
|
|
main()
|
|
HAL_TIM_Base_Start_IT(&htim3);
|
|
|
|
### 回调函数
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|
{
|
|
/*定时结束后做点什么吧*/
|
|
if(htim->Instance ==TIM6){
|
|
|
|
Red_Toggle() ;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#### TIM3 TIM6不同之处
|
|
TIM3 可以使用内部时钟 PWM 输入捕获
|
|
TIM6
|
|
exti.c |