arduino icon indicating copy to clipboard operation
arduino copied to clipboard

The full step is detected differently than described

Open iamanonymus opened this issue 7 years ago • 5 comments

First of all - using a state machine for this task is an elegant solution I must say. I tested the code and it looks like it detects full step when both pins are high contrary to written that the step is detected when both pins go low:

CCW:                                CW:
10                                  01
00                                  00
01                                  10
11 <- this state returns DIR_CCW    11 <- this state returns DIR_CW

Maybe I`m doing something wrong or I have different kind of rotary encoder but for me the sequence is like this:

CCW:    CW:
10      01
11      11
01      10
00      00

Here is the state table that works for me:

const unsigned char ttable[7][4] = {
  // R_START
  {R_START,             R_CW_BEGIN,     R_CCW_BEGIN,    R_START},
  // R_CW_FINAL
  {R_START | DIR_CW,    R_START,        R_CW_FINAL,     R_CW_NEXT},
  // R_CW_BEGIN
  {R_START,             R_CW_BEGIN,     R_START,        R_CW_NEXT},
  // R_CW_NEXT
  {R_START,             R_CW_BEGIN,     R_CW_FINAL,     R_CW_NEXT},
  // R_CCW_BEGIN
  {R_START,             R_START,        R_CCW_BEGIN,    R_CCW_NEXT},
  // R_CCW_FINAL
  {R_START | DIR_CCW,   R_CCW_FINAL,    R_START,        R_CCW_NEXT},
  // R_CCW_NEXT
  {R_START,             R_CCW_FINAL,    R_CCW_BEGIN,    R_CCW_NEXT},
};

Maybe this helps someone else...

iamanonymus avatar Apr 29 '17 14:04 iamanonymus

@iamanonymus What kind of encoder were you using?

pReya avatar Feb 04 '18 00:02 pReya

Sorry for late response :) I think I used this one: https://www.ebay.com/itm/1PCS-KY-040-Rotary-Encoder-Module-Brick-Sensor-Development-For-Arduino/381375070024?hash=item58cbb9bf48:g:6aIAAOSwq5lTmbF7

iamanonymus avatar Feb 27 '18 11:02 iamanonymus

@iamanonymus Interesting. I use the same encoder, and I don't have the problem you described. Maybe there are different versions of this encoder being sold under the same name.

pReya avatar Feb 27 '18 15:02 pReya

It could just be that you have the two output pins swapped?

buxtronix avatar Feb 27 '18 22:02 buxtronix

This is the sequence defined in Your code state table for full step CCW direction (just go through on paper an check): 00 - R_START 10 - R_CCW_BEGIN 00 - R_CCW_NEXT 01 - R_CCW_FINAL 11 - R_START | DIR_CCW

This is stated in the documentation (Rotary.cpp/README.md)

Step1     0      0
 1/4      1      0
 1/2      1      1
 3/4      0      1
Step2     0      0
  1. My setup works as described in the documentation;
  2. This could probably be because the ground and VCC is swapped, swapping signal wires would just make it go the other way around;

For me the problem was that steps were registered mid-turn.

Either way I think You should fix at least documentation, because it does not match code..

iamanonymus avatar Mar 01 '18 06:03 iamanonymus