您的位置 首页 ADAS

STM32F107VCT6的通用定时器装备

将TIM2的周期配置成0.2ms。定时器周期公式:(1+TIM_Prescaler)/72M)*(1+TIM_Period)#defineNVIC_Priority_Timer21unsignedin

将TIM2的周期装备成0.2ms。

定时器周期公式:(1+TIM_Prescaler )/72M)*(1+TIM_Period )

#define NVIC_Priority_Timer2 1

unsigned int Period_TIM2 = 14400;

void TIM2_Init_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = NVIC_Priority_Timer2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

/*
* (1+TIM_Prescaler )/72M)*(1+TIM_Period )=((1+0)/72M)*(1+14400-1) = 0.2ms //5K采样速度
*/
TIM_TimeBaseStructure.TIM_Period = Period_TIM2 – 1;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

TIM_ClearFlag(TIM2, TIM_FLAG_Update);

TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM2->CNT = 0;
TIM_Cmd(TIM2, ENABLE);
}

stm32f10x_it.c文件中

void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);

//增加处理代码
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/adas/276332.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部