Page 1 of 2
rotary encoder using timer feature
Posted: Sat Nov 11, 2017 5:01 am
by ep.hobbyiest
Hi,
I want to interface rotary encoder with stm32f103xx. Do we have encoder functionality with timer?
I was reading stm32f1xx reference manual which mentioned stm32 has built in encoder reading feature which needs 2 channel from timer which worked together to get this work.
Or is it possible to implement it with ICU?
Re: rotary encoder using timer feature
Posted: Sat Nov 11, 2017 6:23 am
by Giovanni
Hi,
There is an encoder driver in the community repository,
Giovanni
Re: rotary encoder using timer feature
Posted: Sat Nov 11, 2017 8:49 pm
by ep.hobbyiest
Thanks Giovanni,
I merge the code and it compiled. I am using TIM4 for that. I have connected PB6 and PB7 are connected to CLK and DT of encoder.
but it is giving only one value as 5489.
Here is my code for ref.
https://github.com/devdprj/rotaryenc
Re: rotary encoder using timer feature
Posted: Sat Nov 11, 2017 8:52 pm
by Giovanni
Hi,
You should contact the original author, I never tried it. Please verify if the pins are assigned the correct alternate function.
Giovanni
Re: rotary encoder using timer feature
Posted: Sun Nov 12, 2017 3:47 pm
by ep.hobbyiest
Yes,
I have change the PAD mode to alternate for TIM4 as
Code: Select all
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT);
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
Is that correct?
And also i am facing one more problem like, USB and encoder are not working together. Is there timer causing issue to usb to work.?
I tried with TIM3 and TIM4 as well.
here is pic of encoder i am using .
Re: rotary encoder using timer feature
Posted: Sun Nov 12, 2017 4:11 pm
by Giovanni
Hi,
You need to select an ALTERNATE mode not PAL_MODE_INPUT, see the STM32 datasheet for the correct settings.
Giovanni
Re: rotary encoder using timer feature
Posted: Sun Nov 12, 2017 6:15 pm
by ep.hobbyiest
Yes. while debugging i found that it is crashing. controller goes to _unhandled_exception.
and got this much stack trace.
Code: Select all
3 _unhandled_exception() vectors.c:77 0x08002620
2 <signal handler called>() 0xfffffffd
1 <symbol is not available> 0x55555554
i could track till qei_lld_start function. As soon as it starts configuring registers then it complete stack trace changes from
Code: Select all
4 qei_lld_start() hal_qei_lld.c:156 0x080025a4
3 qeiStart() hal_qei.c:177 0x080025a4
2 initEncoder() main.c:99 0x080025a4
1 main() main.c:117 0x080025a4
to above mentioned. Not able to debug properly this function.
Re: rotary encoder using timer feature
Posted: Mon Nov 13, 2017 6:21 pm
by ep.hobbyiest
I am trying to figure out at lld level.
i could figure out some register value but not STM32_TIM_SMCR_TS field.
What should be value of STM32_TIM_SMCR_TS field in TIM1->SMCR?
I am trying to get two capture event on single timer which done in qeu driver. but that driver is not working with me.
here is the driver i found on community.
Re: rotary encoder using timer feature
Posted: Mon Nov 13, 2017 8:56 pm
by Giovanni
Hi,
Community code is supported by the original authors, cannot help, never used that driver.
Giovanni
Re: rotary encoder using timer feature
Posted: Sat Nov 18, 2017 11:13 pm
by wayne
This works for me.
Code: Select all
palSetPadMode(GPIOB, 6, PAL_MODE_INPUT);
palSetPadMode(GPIOB, 7, PAL_MODE_INPUT);
// CH1 - PB6 CH2 - PB7
qeiInit();
qeiStart(&QEID4, &qeicfg);
qeiEnable(&QEID4);