cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Rotary Encoder effectively in external interrupt

Akash R
Associate II

Hi there this is Akash, I am doing a project on STM32F100RB Discovery Kit, in this project I am controlling stepper motor with some parameter given by the user using rotary encoder, basically I want to run the motor in the while loop, and through external interrupt I want to use rotary encoder. when I rotate the rotary encoder a display will show some parameters, and based on that display setting the motor will change the speed, the display and motor are working fine, the problem is with rotary encoder, when I rotate the encoder, there is slip(bouncing issue)in the encoder, to make the encoder bounce free, what is the best algorithm when using encoder in External interrupt mode

4 REPLIES 4

> what is the best algorithm when using encoder in External interrupt mode

The best is to NOT use external interrupt.

The best is to use the encoder mode of a timer which supports it, including the filters on ins inputs.

The best software option is to sample the encoder's input in a regular timer interrupt and decode in software.

JW

Akash R
Associate II

thanks @Community member​  for the feedback, if I use Encoder mode, how to use it as Interrupt, I am unable to get the Encoder mode in interrupt, can anyone help me out with this

You can enable capture on any of the two channels, and then interrupt on capture. But I wouldn't do that - simply read out the current value of TIMx_CNT periodically.

For periodic readout, you can also run a different timer out of the internal clock and perform the readout or whatever you want to do in that timer's update interrupt.

JW

Akash R
Associate II

thank you @Community member​  this was helpul for me, ill try to do it.