|
发表于 2011-3-5 08:01:39
|
显示全部楼层
STM32 基本定时器
/*******************************************************************************
* Function Name : TIM2_IRQHandler
* Description : This function handles TIM2 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM2_IRQHandler(void)
{
/* 方法1:
// Clear TIM2 update interrupt
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_SetAutoreload(TIM2, Motor2Tcnt1Val); //TIM2->ARR = 1000 ; // T1Tcnt1Val 1000
Motor2DriveInTimer(); //Motor-Driver
*/
static u16 capture = 0;
//----------------TIM_IT_CC1---------------------------------------------
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) //1ms
{
// Clear TIM2 Capture Compare1 interrupt pending bit
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
Motor1DriveInTimer(); //Motor-Driver
capture = TIM_GetCapture1(TIM2);
TIM_SetCompare1(TIM2, capture + Motor1Tcnt1Val);
}
//----------------TIM_IT_CC2---------------------------------------------
else if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
{
// Clear TIM2 Capture Compare2 interrupt pending bit
TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
Motor2DriveInTimer(); //Motor-Driver
capture = TIM_GetCapture2(TIM2);
TIM_SetCompare2(TIM2, capture + Motor2Tcnt1Val);
}
//----------------TIM_IT_CC3---------------------------------------------
else if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET)
{
// Clear TIM2 Capture Compare3 interrupt pending bit
TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);
Motor3DriveInTimer(); //Motor-Driver
capture = TIM_GetCapture3(TIM2);
TIM_SetCompare3(TIM2, capture + Motor3Tcnt1Val);
}
//----------------TIM_IT_CC4---------------------------------------------
else
{
// Clear TIM2 Capture Compare4 interrupt pending bit
TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);
Motor4DriveInTimer(); //Motor-Driver
capture = TIM_GetCapture4(TIM2);
TIM_SetCompare4(TIM2, capture + Motor4Tcnt1Val);
}
//-------------------------------------------------------------------------------
} |
|