新手上路
- 积分
- 35
- 金钱
- 35
- 注册时间
- 2012-11-11
- 在线时间
- 0 小时
|
5金钱
原子哥,请问一下,我想用定时器2定时,然后在中断中更新定时的值。该怎么配置?
我下面的配置是不是有问题?我通过调试发现定时器的值并没有更新,一直是初始化的值.
void Timer2_Init(void)
{
TIM_TimeBaseInitTypeDef Tim_TimeBaseInitStruct;
TIM_DeInit(TIM2);
Tim_TimeBaseInitStruct.TIM_Period = 1000-1;
Tim_TimeBaseInitStruct.TIM_Prescaler = 71;
Tim_TimeBaseInitStruct.TIM_ClockDivision = 0;
Tim_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
Tim_TimeBaseInitStruct.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, & Tim_TimeBaseInitStruct);
TIM_ARRPreloadConfig(TIM2, ENABLE); //ENABLE// DISABLE
TIM_ClearFlag(TIM2,TIM_FLAG_Update);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_Cmd(TIM2,ENABLE);
}
void TIM2_IRQHandler(void)
{
static unsigned count =0;
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update );
TIM2->ARR=TimeValue[count];
count++;
if(count>=32)
{
count=0;
}
}
}
|
|