rotary encoder using timer feature

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

rotary encoder using timer feature

Postby ep.hobbyiest » Sat Nov 11, 2017 5:01 am

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?

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: rotary encoder using timer feature

Postby Giovanni » Sat Nov 11, 2017 6:23 am

Hi,

There is an encoder driver in the community repository,

Giovanni

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: rotary encoder using timer feature

Postby ep.hobbyiest » Sat Nov 11, 2017 8:49 pm

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

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: rotary encoder using timer feature

Postby Giovanni » Sat Nov 11, 2017 8:52 pm

Hi,

You should contact the original author, I never tried it. Please verify if the pins are assigned the correct alternate function.

Giovanni

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: rotary encoder using timer feature

Postby ep.hobbyiest » Sun Nov 12, 2017 3:47 pm

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 .
s-l500.jpg

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: rotary encoder using timer feature

Postby Giovanni » Sun Nov 12, 2017 4:11 pm

Hi,

You need to select an ALTERNATE mode not PAL_MODE_INPUT, see the STM32 datasheet for the correct settings.

Giovanni

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: rotary encoder using timer feature

Postby ep.hobbyiest » Sun Nov 12, 2017 6:15 pm

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.

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: rotary encoder using timer feature

Postby ep.hobbyiest » Mon Nov 13, 2017 6:21 pm

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.
que driver files.7z
(5.17 KiB) Downloaded 160 times

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: rotary encoder using timer feature

Postby Giovanni » Mon Nov 13, 2017 8:56 pm

Hi,

Community code is supported by the original authors, cannot help, never used that driver.

Giovanni

wayne
Posts: 2
Joined: Sat Nov 18, 2017 9:03 pm

Re: rotary encoder using timer feature

Postby wayne » Sat Nov 18, 2017 11:13 pm

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);


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 44 guests