void TIM2_init(void)
{
rcu_periph_clock_enable(RCU_GPIOA);
gpio_deinit(GPIOA);
/**************Pulse Input******************/
gpio_mode_set(GPIOA,GPIO_MODE_AF,GPIO_PUPD_NONE,GPIO_PIN_6);
gpio_af_set(GPIOA,GPIO_AF_1,GPIO_PIN_6);
timer_parameter_struct TIM2_BaseInitStructure;
timer_ic_parameter_struct TIM2_CaptureInitStructure;
rcu_periph_clock_enable(RCU_TIMER2);
timer_deinit(TIMER2);
TIM2_BaseInitStructure.prescaler = 225;
TIM2_BaseInitStructure.alignedmode = TIMER_COUNTER_EDGE;
TIM2_BaseInitStructure.counterdirection = TIMER_COUNTER_UP;
TIM2_BaseInitStructure.clockdivision = TIMER_CKDIV_DIV1;
TIM2_BaseInitStructure.repetitioncounter = 0;
TIM2_BaseInitStructure.period = 0xFFFFFFFF;
timer_init(TIMER2,&TIM2_BaseInitStructure);
TIM2_CaptureInitStructure.icpolarity = TIMER_IC_POLARITY_RISING;
TIM2_CaptureInitStructure.icselection = TIMER_IC_SELECTION_DIRECTTI;
TIM2_CaptureInitStructure.icprescaler = TIMER_IC_PSC_DIV2;
TIM2_CaptureInitStructure.icfilter = 15;
timer_input_capture_config(TIMER2,TIMER_CH_0,&TIM2_CaptureInitStructure);
//timer_auto_reload_shadow_enable(TIMER2);
timer_interrupt_flag_clear(TIMER2,TIMER_INT_FLAG_CH0);
timer_interrupt_enable(TIMER2,TIMER_INT_CH0);
nvic_irq_enable(TIMER2,2,1);
timer_enable(TIMER2);
} |