Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The full step is detected differently than described #3

Open
iamanonymus opened this issue Apr 29, 2017 · 5 comments
Open

The full step is detected differently than described #3

iamanonymus opened this issue Apr 29, 2017 · 5 comments

Comments

@iamanonymus
Copy link

iamanonymus commented Apr 29, 2017

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

@pReya
Copy link

pReya commented Feb 4, 2018

@iamanonymus What kind of encoder were you using?

@iamanonymus
Copy link
Author

@pReya
Copy link

pReya commented Feb 27, 2018

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

@buxtronix
Copy link
Owner

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

@iamanonymus
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants