输入捕获配置:
void TIM3_Cap_Init(uint16_t arr ,uint16_t psc)
{
RCC_AHBPeriphClock_Enable( RCC_AHBPERIPH_GPIOC, ENABLE );
RCC_APB1PeriphClock_Enable( RCC_APB1PERIPH_TIMER3,ENABLE );
{
GPIO_InitPara GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_6 ;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init( GPIOC , &GPIO_InitStructure );
}
{
NVIC_InitPara NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQ = TIMER3_IRQn;//
NVIC_InitStructure.NVIC_IRQPreemptPriority = 0;//
NVIC_InitStructure.NVIC_IRQSubPriority = 1;// ¨
NVIC_InitStructure.NVIC_IRQEnable = ENABLE;//
NVIC_Init( &NVIC_InitStructure );//
}
{
TIMER_BaseInitPara TIM_TimeBaseStructure;
TIMER_ICInitPara TIM_ICInitStructure;
TIMER_DeInit( TIMER3 );
TIM_TimeBaseStructure.TIMER_Period = arr ;
TIM_TimeBaseStructure.TIMER_Prescaler = psc ;
TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIMER_BaseInit(TIMER3, &TIM_TimeBaseStructure);
TIMER_PrescalerConfig( TIMER3, 71, 1 );
TIM_ICInitStructure.TIMER_CH = TIMER_CH_1;
TIM_ICInitStructure.TIMER_ICPolarity = TIMER_IC_POLARITY_FALLING;
TIM_ICInitStructure.TIMER_ICSelection = TIMER_IC_SELECTION_DIRECTTI;
TIM_ICInitStructure.TIMER_ICPrescaler = TIMER_IC_PSC_DIV1;
TIM_ICInitStructure.TIMER_ICFilter = 0X00;
TIMER_ICStructInit(&TIM_ICInitStructure);
TIMER_PWMCaptureConfig(TIMER3, &TIM_ICInitStructure);
}
TIMER_SelectInputTrigger(TIMER3 ,TIMER_TS_TI1FP1);//ke gai
TIMER_SelectSlaveMode(TIMER3 ,TIMER_SLAVE_MODE_RESET);
TIMER_UpdateRequestConfig(TIMER3 ,TIMER_UPDATE_SRC_REGULAR );
TIMER3->CARL = arr;
//TIMER_SelectMasterSlaveMode(TIMER2 ,TIMER_MASTER_SLAVE_MODE_ENABLE);
TIMER_ClearBitState(TIMER3, TIMER_FLAG_UPDATE | TIMER_FLAG_CH1 | TIMER_FLAG_CH2 );
TIMER_INTConfig(TIMER3, TIMER_INT_CH2, ENABLE);
TIMER_INTConfig(TIMER3, TIMER_INT_CH1, ENABLE);
TIMER_Enable(TIMER3, ENABLE);
}
中断服务函数:
void TIM3_IRQHandler(void)
{
if((TIMER_GetBitState(TIMER3, TIMER_FLAG_CH2 ) != RESET))
{
TIMER_ClearBitState(TIMER3, TIMER_FLAG_CH2 );
ICValue2 = TIMER3->CHCC2;
}
if((TIMER_GetBitState(TIMER3, TIMER_FLAG_CH1) != RESET))
{
TIMER_ClearBitState(TIMER3, TIMER_FLAG_CH1);
ICValue1 = TIMER3->CHCC1 - TIMER3->CHCC2;
}
}
在线仿真时寄存器里面没有值,没有产生输入捕获,不知道问题出在哪里,求高手指点问题出在哪里 |