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?
rotary encoder using timer feature
Moderators: RoccoMarco, barthess
-
- Posts: 94
- Joined: Sun Jun 26, 2016 5:22 pm
- Has thanked: 4 times
- Been thanked: 1 time
- 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
Hi,
There is an encoder driver in the community repository,
Giovanni
There is an encoder driver in the community repository,
Giovanni
-
- Posts: 94
- Joined: Sun Jun 26, 2016 5:22 pm
- Has thanked: 4 times
- Been thanked: 1 time
Re: rotary encoder using timer feature
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
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
- 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
Hi,
You should contact the original author, I never tried it. Please verify if the pins are assigned the correct alternate function.
Giovanni
You should contact the original author, I never tried it. Please verify if the pins are assigned the correct alternate function.
Giovanni
-
- Posts: 94
- Joined: Sun Jun 26, 2016 5:22 pm
- Has thanked: 4 times
- Been thanked: 1 time
Re: rotary encoder using timer feature
Yes,
I have change the PAD mode to alternate for TIM4 as
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 .
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 .
- 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
Hi,
You need to select an ALTERNATE mode not PAL_MODE_INPUT, see the STM32 datasheet for the correct settings.
Giovanni
You need to select an ALTERNATE mode not PAL_MODE_INPUT, see the STM32 datasheet for the correct settings.
Giovanni
-
- Posts: 94
- Joined: Sun Jun 26, 2016 5:22 pm
- Has thanked: 4 times
- Been thanked: 1 time
Re: rotary encoder using timer feature
Yes. while debugging i found that it is crashing. controller goes to _unhandled_exception.
and got this much stack trace.
i could track till qei_lld_start function. As soon as it starts configuring registers then it complete stack trace changes from
to above mentioned. Not able to debug properly this function.
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.
-
- Posts: 94
- Joined: Sun Jun 26, 2016 5:22 pm
- Has thanked: 4 times
- Been thanked: 1 time
Re: rotary encoder using timer feature
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.
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.
- 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
Hi,
Community code is supported by the original authors, cannot help, never used that driver.
Giovanni
Community code is supported by the original authors, cannot help, never used that driver.
Giovanni
Re: rotary encoder using timer feature
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);
Who is online
Users browsing this forum: No registered users and 44 guests