今天下午在调一个PWM输入捕捉,搞了很久,发现进不了中断.
原程序如下,望高手帮忙分析一下.
TIM8初始化
void TIM8_Configuration (void)
{
uint16_t PrescalerValue = 0;
/* Compute the prescaler value 1MHz, CLK1MAX = 36MHz*/
PrescalerValue = (uint16_t) ((SystemCoreClock/2) / 1000000) - 1;
/* Time base configuration */
TIM_TimeBaseStructure.TIM_Period = 0xffff; //定时65.536ms
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM8, PrescalerValue, TIM_PSCReloadMode_Immediate);
/* TIM8 configuration: PWM Input mode ------------------------
The external signal is connected to TIM8 CH1 pin (PC.06),
The Rising edge is used as active edge,
The TIM8 CCR1 is used to compute the frequency value
The TIM3 CCR2 is used to compute the duty cycle value
------------------------------------------------------------ */
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 = 0x0;
TIM_PWMIConfig(TIM8, &TIM_ICInitStructure);
/* Select the TIM8 Input Trigger: TI1FP1 */
TIM_SelectInputTrigger(TIM8, TIM_TS_TI1FP1);
/* Select the slave Mode: Reset Mode */
TIM_SelectSlaveMode(TIM8, TIM_SlaveMode_Reset);
/* Enable the Master/Slave Mode */
TIM_SelectMasterSlaveMode(TIM8, TIM_MasterSlaveMode_Enable);
/* TIM enable counter */
TIM_Cmd(TIM8, ENABLE);
/* Enable the CC1 Interrupt Request */
TIM_ITConfig(TIM8, TIM_IT_CC1, ENABLE);
}
GPIO初始化就不贴了,PC6配成GPIO_Mode_IN_FLOATING.
时钟
/* TIM8 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
/* APB2 AFIO clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
/* GPIO clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
中断使能打开
NVIC_InitStructure.NVIC_IRQChannel = TIM8_CC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
中断向量函数
void BSP_IntHandlerTIM8_CC (void)
{
LED ^= 1; //LED灯亮灭取反
/* Clear TIM8 Capture compare interrupt pending bit */
TIM_ClearITPendingBit(TIM8, TIM_IT_CC1);
} |