void TIM3_Cap_Init(void)
{
RCC_AHBPeriphClock_Enable( RCC_AHBPERIPH_GPIOB, ENABLE );
RCC_APB1PeriphClock_Enable( RCC_APB1PERIPH_TIMER3,ENABLE );
/*************³õʼ»¯GPIO****************/
{
GPIO_InitPara GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_5 | GPIO_PIN_4;
GPIO_InitStructure.GPIO_Mode = GPIO_MODE_AF;
// GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_PULLDOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_Init( GPIOB , &GPIO_InitStructure );
GPIO_PinAFConfig(GPIOB,GPIO_PINSOURCE5,GPIO_AF_1); //GPIO¸´ÓÃ
GPIO_PinAFConfig(GPIOB,GPIO_PINSOURCE4,GPIO_AF_1); //GPIO¸´ÓÃ
}
//******************ÓÅÏȼ¶ÉèÖÃ****************//
{
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 );//
}
//******************TIM3³õʼ»¯***************//
{
TIMER_BaseInitPara TIM_TimeBaseStructure;
TIMER_ICInitPara TIM_ICInitStructure;
TIMER_DeInit( TIMER3 );
TIM_TimeBaseStructure.TIMER_Period = 65535 ;
TIM_TimeBaseStructure.TIMER_Prescaler = 0 ;
TIM_TimeBaseStructure.TIMER_ClockDivision = TIMER_CDIV_DIV1;
TIM_TimeBaseStructure.TIMER_CounterMode = TIMER_COUNTER_UP;
TIMER_BaseInit(TIMER3, &TIM_TimeBaseStructure);
TIMER_EncoderInterfaceConfig( TIMER3 , TIMER_ENCODER_MODE_TI1 ,
TIMER_IC_POLARITY_BOTH_EDGE , TIMER_IC_POLARITY_BOTH_EDGE );
TIMER_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIMER_ICFilter = 6;
TIMER_ICInit(TIMER3, &TIM_ICInitStructure);
TIMER_SetAutoreload(TIMER3,65535);
TIMER_ClearBitState(TIMER3, TIMER_FLAG_UPDATE );
TIMER_INTConfig(TIMER3, TIMER_INT_UPDATE, ENABLE);
TIMER3->CNT = 0;
TIMER_Enable(TIMER3, ENABLE);
}
}
配置能够进入中断,但计数器TIMER3->CNT只有0与1的变化,读不到其他值,望大神指点!!! |