timer_ic_parameter_struct timer_icinitpara;
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_AF);
rcu_periph_clock_enable(RCU_TIMER3);
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_6);
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_7);
gpio_init(GPIOB, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_8);
timer_deinit(TIMER3);
timer_initpara.prescaler = 16;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 65535;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER3,&timer_initpara);
timer_icinitpara.icpolarity = TIMER_IC_POLARITY_FALLING;
timer_icinitpara.icselection = TIMER_IC_SELECTION_ITS;
timer_icinitpara.icprescaler = TIMER_IC_PSC_DIV1;
timer_icinitpara.icfilter = 0x01;
timer_input_capture_config(TIMER3,TIMER_CH_0,&timer_icinitpara);
timer_hall_mode_config(TIMER3,TIMER_HALLINTERFACE_ENABLE);
timer_input_trigger_source_select(TIMER3,TIMER_SMCFG_TRGSEL_CI0F_ED);
timer_slave_mode_select(TIMER3,TIMER_SLAVE_MODE_RESTART);
timer_interrupt_flag_clear(TIMER3,TIMER_INT_CH0);
timer_interrupt_enable(TIMER3,TIMER_INT_CH0);
nvic_priority_group_set(NVIC_PRIGROUP_PRE1_SUB3);
nvic_irq_enable(TIMER3_IRQn, 1, 1);
timer_enable(TIMER3);
TIMER3中断就可以了 |