打印

定时器比较中断

[复制链接]
1626|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
big5|  楼主 | 2009-8-8 12:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
初始化:

TIM_TimeBaseStructure.TIM_Period = 0xffff;
  TIM_TimeBaseStructure.TIM_Prescaler = 11;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  TIM_SetCompare1(TIM4, 55296);
  TIM_SetCompare2(TIM4, 55296);

  TIM_ClearFlag(TIM4, TIM_FLAG_CC1 | TIM_FLAG_CC2);
  TIM_ITConfig(TIM4, TIM_IT_CC1 | TIM_IT_CC2, ENABLE);
  TIM_Cmd(TIM4, ENABLE);

中断伪代码:
void TIM4_IRQHandler(void)
{
  u16 capture;         

  if (TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)
  {
    capture = TIM_GetCapture1(TIM4);
    TIM_SetCompare1(TIM4, capture + 55296);
               ...
    TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);
  }
  if (TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)
  {
    capture = TIM_GetCapture2(TIM4);
    TIM_SetCompare2(TIM4, capture + 55296);
                ...
    TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);
  }
}
结果不是预期的,只打开任何一路,结果正确。是这样使用吗?
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

91

主题

242

帖子

0

粉丝