/******************************************************************************* * Function Name : NVIC_Config * * Description : None * * Arguments : None * * Returns : None *******************************************************************************/ static void NVIC_Config(void) { NVIC_InitTypeDef NVIC_InitStructure;
/* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x00);
/* Configure one bit for preemption priority */ NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
/* TIM1 IRQ configuration Priority : 1 -----------------------------------*/ NVIC_InitStructure.NVIC_IRQChannel = TIM1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
/* TIM2 IRQ configuration Priority : 1 -----------------------------------*/ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
/* TIM3 IRQ configuration Priority : 1 -----------------------------------*/ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
/* TIM4 IRQ configuration Priority : 1 -----------------------------------*/ NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
}
/******************************************************************************* * Function Name : TIM_16CaptureInitial * * Description : None * * Arguments : None * * Returns : None *******************************************************************************/ static void TIM_16CaptureInitial(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure;
/* Timer Base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 7199; TIM_TimeBaseStructure.TIM_ClockDivision = 0x00; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
// TIMx Input Capture Configuration //TIM_ICInitStructure.TIM_ICMode = TIM_ICMode_ICAP; TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0;
TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInit(TIM2, &TIM_ICInitStructure); TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInit(TIM2, &TIM_ICInitStructure); TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_ICInit(TIM4, &TIM_ICInitStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInit(TIM2, &TIM_ICInitStructure); TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInit(TIM2, &TIM_ICInitStructure); TIM_ICInit(TIM3, &TIM_ICInitStructure); TIM_ICInit(TIM4, &TIM_ICInitStructure); //Enable TIMx Capture Compare x Interrupt source TIM_ITConfig(TIM1,TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4,ENABLE); TIM_ITConfig(TIM2,TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4,ENABLE); TIM_ITConfig(TIM3,TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4,ENABLE); TIM_ITConfig(TIM4,TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4,ENABLE);
/* Enable timer counter */ TIM_Cmd(TIM1,ENABLE); TIM_Cmd(TIM2,ENABLE); TIM_Cmd(TIM3,ENABLE); TIM_Cmd(TIM4,ENABLE);
}
|