STM32定时器时间计算公式 理解(大白话)实现1ms、1s延时

STM32定时器时间计算公式

ARR(TIM_Period):自动重装载值,是定时器溢出前的计数值

PSC(TIM_Prescaler):预分频值,是用来降低定时器时钟频率的参数

Tclk:72M定时器的输入时钟频率(单位Mhz),通常为系统时钟频率或者定时器外部时钟频率

Tout:定时器溢出时间

如下图所示:

Tout=(7200x10000) ÷72M=1S

同理可得1ms配置:

PSC:72-1

ARR:1000-1

HAL_TIM_Base_Start_IT(&htim3);   //打开定时器中断
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
   
    if (htim->Instance == TIM3)
    {
        HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
    }

}

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
STM321S #include "stm32f10x_it.h" /** @addtogroup STM32F10x_StdPeriph_Template * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ extern u32 SystickCounter; extern u8 KeySwitch_Press; extern u8 KeyAdjust_Press; #define TRUE 1 #define FALSE 0 /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M3 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @ret
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值