我用的定时器0,求教要怎么配置编码器呢?
我现在这样配置,CNT没有反应
void encoder_init()
{
timer_parameter_struct timer_initpara;
timer_ic_parameter_struct timer_ic;
rcu_periph_clock_enable(RCU_TIMER0);
rcu_periph_clock_enable(RCU_GPIOA);
gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_8|GPIO_PIN_9);
gpio_af_set(GPIOA, GPIO_AF_2, GPIO_PIN_8|GPIO_PIN_9);
timer_deinit(TIMER0);
timer_initpara.prescaler = 0;
timer_initpara.alignedmode = TIMER_COUNTER_EDGE;
timer_initpara.counterdirection = TIMER_COUNTER_UP;
timer_initpara.period = 3000;
timer_initpara.clockdivision = TIMER_CKDIV_DIV1;
timer_initpara.repetitioncounter = 0;
timer_init(TIMER0,&timer_initpara);
timer_ic.icfilter= 0x00;
timer_ic.icpolarity=TIMER_IC_POLARITY_FALLING;
timer_ic.icprescaler=TIMER_IC_PSC_DIV1;
timer_ic.icselection=TIMER_IC_SELECTION_DIRECTTI;
timer_input_capture_config(TIMER0,TIMER_CH_0,&timer_ic);
timer_input_capture_config(TIMER0,TIMER_CH_1,&timer_ic);
timer_slave_mode_select(TIMER0,TIMER_ENCODER_MODE2);
timer_quadrature_decoder_mode_config(TIMER0,TIMER_ENCODER_MODE2,TIMER_IC_POLARITY_FALLING,TIMER_IC_POLARITY_FALLING);
timer_counter_value_config(TIMER0,3000);
timer_enable(TIMER0);
} |