Difference between revisions of "STM32 Rotary Encoder"

From Stm32World Wiki
Jump to navigation Jump to search
Line 23: Line 23:
  
 
== Using Timer to decode rotary encoder ==
 
== Using Timer to decode rotary encoder ==
 +
 +
In [[STM32CubeMX]] a timer can be configured to combine two channels in Encoder mode.
  
 
[[File:Timer Encoder.png|600px]]
 
[[File:Timer Encoder.png|600px]]
 +
 +
This will highlight the necessary pins:
 +
 +
[[File:Rotary encoder pins.png|600px]]
  
 
== Miscellaneous Links ==
 
== Miscellaneous Links ==
  
 
* [https://github.com/lbthomsen/rotary-encoder-breakout Rotary Encoder Breakout w. de-bouncing circuit]
 
* [https://github.com/lbthomsen/rotary-encoder-breakout Rotary Encoder Breakout w. de-bouncing circuit]

Revision as of 12:08, 26 July 2021

Rotary encoder on de-bouncing breakout board

Rotary Encoders are devices which will generate pulses when they are turned.

Typically they will have two outputs with the pulses out of phase. By checking which pulse "comes first" the direction of the turn can be determined. It is not overly complicated to handle this manually, for example by hooking the signals up to an external GPIO Interrupt.

Rotary encoder signals

A rotary encoder will output 2 signals 90 degrees out of phase with each other.

Rotary encoder signals.jpeg

By analysing the order of the transitions the steps can be counted and the direction can be detected.

Rotary encoder de-bouncing

Rotary encoders are build with mechanical contacts and they are prone to "bouncing" (one press generate more than one interrupt". The "signals" can be cleaned up by implementing a low-pass filter like this:

Rotary debounce.png

I just happened to have a few of those rotary encoder breakout boards lying around.

Using Timer to decode rotary encoder

In STM32CubeMX a timer can be configured to combine two channels in Encoder mode.

Timer Encoder.png

This will highlight the necessary pins:

Rotary encoder pins.png

Miscellaneous Links