81 lines
1.9 KiB
C
81 lines
1.9 KiB
C
/**
|
||
******************************************************************************
|
||
* @file : bsp_tim.c
|
||
* @author : zsq
|
||
* @version : V1.0
|
||
* @date : 2019-06-27
|
||
* @brief : timer config
|
||
******************************************************************************
|
||
* @attention
|
||
*
|
||
* Copyright (c) 2019 YUNHORN(Shenzhen YunHorn Technology Co., Ltd
|
||
* All rights reserved.
|
||
*
|
||
******************************************************************************
|
||
*/
|
||
|
||
#include "bsp_tim.h"
|
||
|
||
/**
|
||
* @brief 基本定时器 TIMx,x[6,7]中断优先级配置
|
||
* @param 无
|
||
* @retval 无
|
||
*/
|
||
static void TIMx_NVIC_Configuration(void)
|
||
{
|
||
NVIC_InitTypeDef NVIC_InitStructure;
|
||
NVIC_InitStructure.NVIC_IRQChannel = TIM6_DAC_IRQn;
|
||
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
|
||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||
NVIC_Init(&NVIC_InitStructure);
|
||
}
|
||
|
||
/**
|
||
* @brief 基本定时器 TIMx,x[6,7]配置
|
||
* @param 无
|
||
* @retval 无
|
||
*/
|
||
static void TIM_Mode_Config(void)
|
||
{
|
||
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
||
|
||
// 开启TIMx_CLK,x[6,7]
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
|
||
|
||
/* 累计 TIM_Period个后产生一个更新或者中断*/
|
||
//当定时器从0计数到4999,即为5000次,为一个定时周期
|
||
TIM_TimeBaseStructure.TIM_Period = 24000-1;
|
||
|
||
//定时器时钟源TIMxCLK = 2 * PCLK1
|
||
// PCLK1 = HCLK / 4
|
||
// => TIMxCLK=HCLK/2=SystemCoreClock/2=90MHz
|
||
// 设定定时器频率为=TIMxCLK/(TIM_Prescaler+1)=10000Hz
|
||
TIM_TimeBaseStructure.TIM_Prescaler = 20000-1;
|
||
|
||
// 初始化定时器TIMx, x[2,3,4,5]
|
||
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
|
||
|
||
|
||
// 清除定时器更新中断标志位
|
||
TIM_ClearFlag(TIM6, TIM_FLAG_Update);
|
||
|
||
// 开启定时器更新中断
|
||
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
|
||
|
||
// 使能定时器
|
||
TIM_Cmd(TIM6, ENABLE);
|
||
}
|
||
|
||
/**
|
||
* @brief 初始化基本定时器定时,1ms产生一次中断
|
||
* @param 无
|
||
* @retval 无
|
||
*/
|
||
void TIMx_Configuration(void)
|
||
{
|
||
TIMx_NVIC_Configuration();
|
||
|
||
TIM_Mode_Config();
|
||
}
|
||
|