User Tools

Site Tools


arduino:rotary-encoder

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
arduino:rotary-encoder [2023/01/10 17:06]
Ilias Iliopoulos [Theory of operation]
arduino:rotary-encoder [2024/02/02 21:48] (current)
Ilias Iliopoulos
Line 23: Line 23:
   * [[https://​en.wikipedia.org/​wiki/​Gray_code | Gray code]]  ​   * [[https://​en.wikipedia.org/​wiki/​Gray_code | Gray code]]  ​
  
-In this article, we will explore a simple form of Rotary Encoder which provides as outputs two signals, A and B. Most encoders labeled as EC11 or KY-40, are based on this principle. Please note that not all rotary encoders behave exactly the same, especially during transition from one state to another, depending on their construction. I will try to implement a universal solution, applicable to most rotary encoders variants. It is understood that this approach may have implications which may or may not affect a specific implementation and should be considered thoroughly at the design phase of each project. ​   ​+In this article, we will explore a simple form of Rotary Encoder which provides as outputs two signals, A and B. Most encoders labeled as EC11 or KY-040, are based on this principle. Please note that not all rotary encoders behave exactly the same, especially during transition from one state to another, depending on their construction. I will try to implement a universal solution, applicable to most rotary encoders variants. It is understood that this approach may have implications which may or may not affect a specific implementation and should be considered thoroughly at the design phase of each project. ​   ​
  
 In theory, we learn that signals A and B __"are in quadrature"​__ or __"are 90 degrees out of phase"​__. In theory, we learn that signals A and B __"are in quadrature"​__ or __"are 90 degrees out of phase"​__.
Line 44: Line 44:
 ** NOTE: The stable zones had been a source of controversy since I have received several emails regarding implementations of other encoder manufacturers where the signal transition from one step to another and the detents did not follow the above principle. For example, one detent might correspond to a change of a single signal, either A or B, according to the Gray encoding. The reason that I have not covered this case in this section relates: ** ** NOTE: The stable zones had been a source of controversy since I have received several emails regarding implementations of other encoder manufacturers where the signal transition from one step to another and the detents did not follow the above principle. For example, one detent might correspond to a change of a single signal, either A or B, according to the Gray encoding. The reason that I have not covered this case in this section relates: **
  
-** a) to the fact that the common EC11, KY-40 variants produce two Gray code transitions per detent. As per the KY-040 datasheet: **+** a) to the fact that the common EC11, KY-040 variants produce two Gray code transitions per detent. As per the {{arduino:​ky-040-datasheet.pdf|KY-040 datasheet}}: **
  
 // //
Line 55: Line 55:
  
 **  ** 
-b) to the principle of the debouncing algorithm [[arduino:​rotary-encoder#​2. A transition is considered valid when both signals (A and B) change value]] presented below. Therefore, I considered that even in the case where one detent corresponds to a change in only one signal, the user should make two shaft movements, or in the generic case, as many movements as necessary so that both signals are changed. This obviously has the effect that the Gray code will move two positions instead of one. This is a side-effect of this debouncing algorithm and the price to pay if we do not debounce with hardware. **+b) to the principle of the debouncing algorithm [[arduino:​rotary-encoder#​2. A transition is considered valid when both signals (A and B) change value]] presented below. Therefore, I considered that even in the case where one detent corresponds to a change in only one signal, the user should make two shaft movements, or in the generic case, as many movements as necessary so that both signals are changed. This obviously has the effect that the Gray code will move two positions instead of one. This is a side-effect of this debouncing algorithm and the price to pay if we do not debounce with hardware. ​ 
 +**
  
 If we consider signal A the most significant bit (MSB) and B the least significant bit (LSB) of a binary number composed of A and B, we can see that when the shaft is not rotating, it rests at state **00** (which is decimal **0**), or at state ** binary 11** (which is **decimal 3**).  If we consider signal A the most significant bit (MSB) and B the least significant bit (LSB) of a binary number composed of A and B, we can see that when the shaft is not rotating, it rests at state **00** (which is decimal **0**), or at state ** binary 11** (which is **decimal 3**). 
Line 233: Line 234:
 Please check [[https://​github.com/​fryktoria/​FR_RotaryEncoder | the Github page]] for a description of the functionality available and to download the library. Several examples which demonstrate the library features are included. ​   Please check [[https://​github.com/​fryktoria/​FR_RotaryEncoder | the Github page]] for a description of the functionality available and to download the library. Several examples which demonstrate the library features are included. ​  
  
 +~~DISQUS~~
arduino/rotary-encoder.1673363197.txt.gz · Last modified: 2023/01/10 17:06 by Ilias Iliopoulos