timer - Reading quadrature encoder output using NUCLEO-F072RB -


i using nucleo-f072rb board in conjunction x2c read output of dc motor encoder, in order measure speed. according datasheet, using timers tim2 , tim3 possible perform read. purpose, followed this , this sources write following code:

/** - configure a6 encoder input (t1) */ gpio_structinit(&gpio_initstruct); gpio_initstruct.gpio_mode = gpio_mode_af; gpio_initstruct.gpio_pupd = gpio_pupd_up; gpio_initstruct.gpio_pin = gpio_pin_6; gpio_init (gpioa, &gpio_initstruct); gpio_pinafconfig(gpioa, gpio_initstruct.gpio_pin, gpio_af_1);  /** - configure a7 encoder input (t2) */ gpio_structinit(&gpio_initstruct); gpio_initstruct.gpio_mode = gpio_mode_af; gpio_initstruct.gpio_pupd = gpio_pupd_up; gpio_initstruct.gpio_pin = gpio_pin_7; gpio_init (gpioa, &gpio_initstruct); gpio_pinafconfig(gpioa, gpio_initstruct.gpio_pin, gpio_af_1);  /**********************************************/ /* encoder input setup */  /* tim3 clock enabled */ rcc_apb1periphclockcmd(rcc_apb1periph_tim3, enable);  /* tim3 deinit */ tim_deinit(tim3); tim_timebasestructinit(&tim_timebasestructure); tim_ocstructinit(&tim_ocinitstructure);   /* configure timer tim3 encoder input */ tim_encoderinterfaceconfig(tim3, tim_encodermode_ti12,  tim_icpolarity_rising, tim_icpolarity_rising); tim_setautoreload (tim3, 0xffff);  /* tim3 counter enable */ tim_cmd(tim3, enable); 

here use alternate function 1 both inputs, which, according datasheet, corresponds tim3. far understand, setup, every time there rising edge on t1 (gpio a6 in case), tim3 counter increases 1, , when there rising edge on t2 (a7), counter decreases one.

for debugging purposes, set value variable can monitor. if counter 1 or greater value int16_max set, otherwise 0 set.

if (tim_getcounter(tim3) > 0x0) {     inports.encoder_input = int16_max; } else {     inports.encoder_input = 0; } 

before using actual encoder, have tried using switch manually generate rising edges , pwm output gpio feed inputs (gpio's a6 , a7). way, expect tim3 counter starts counting up/down, nothing happens. have noticed when connect signal a6 or a7, gets degradated, may explain why no rising edges detected. measuring dc multimeter resistance on these inputs approximately 40 ohm, low input port.

how can setup timer , gpios able read encoder signal , tim3 counter start counting?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -