Skip to content

The full step is detected differently than described #3

@iamanonymus

Description

@iamanonymus

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions