初始化:
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);
}
}
结果不是预期的,只打开任何一路,结果正确。是这样使用吗? |