arduino icon indicating copy to clipboard operation
arduino copied to clipboard

FSM for rotary encoders does not match the description

Open newbrain opened this issue 6 years ago • 0 comments

The problem described in #3 is actually real, the transition table differs from the documentation.

Why from a state of R_CW_BEGIN, with an input of 0-0 the FSM transition to R_CW_NEXT (third line of the matrix)? It should of course go back to R_START!

The same problem is there for CCW rotation.

It would seem that the matrix is a mix of the one needed for positive logic (rest state 0-0) and the one for negative logic (1-1).

In addition to the above, though it has probably a very minor effect, the readme.MD in Rotary/ states that:

If an invalid state happens (for example we go from '0-1' straight to '1-0'), the state machine resets to the start until 0-0 and the next valid codes occur.

The implementation will not catch a double invalid transition 0-1 -> 1-0 -> 0-1 as it, in fact, does not wait for the 0-0 state. In this example the final state will be R_CW_BEGIN.

This does not look correct, as also the second transition can be considered faulty.

To make sure that the base state R_START is reached only when the input is 0-0, an eight state is needed (R_FAULT?) that must be entered for all the faulty transitions, and move to R_START when input is 0-0 (with the exception of 1-1 -> 0-0, that can go directly to R_START!)

The cost is very low (4 bytes for the new row in the transition table), and the logic is unchanged. At 0 code cost, the Readme could be updated instead.

newbrain avatar Sep 26 '18 20:09 newbrain