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

rotary state machine may be suboptimal #22

Open
nettings opened this issue Mar 12, 2019 · 0 comments
Open

rotary state machine may be suboptimal #22

nettings opened this issue Mar 12, 2019 · 0 comments

Comments

@nettings
Copy link
Owner

/* Yay. A bit-wise state machine :)
 *
 * State:
 *   nnnn
 *   |||+----> clk bit
 *   ||+-----> dt bit
 *   |+------> clockwise bit
 *   +-------> outer ring bit
 *
 * The clk and dt bits are set by interrupt handlers.
 * They can change rapidly when the switch hardware
 * bounces.
 *
 * Two rings:
 *  Outer        1100*_    _1000*
 *                /    \  /    \
 *  Inner        /     0x00     \
 *              |      /  \      |
 *            1101  0010  0101  1010
  *             |     |    |     |
 *               \  0011* 0111* /
 *                \    \  /    /
 *                 \___1x11___/ 
 *
 * The starred states will fire a callback.
 * Between two unstarred states, we tolerate bouncing.
 * A starred state cannot bounce back, because we 
 * change rings immediately, so that it cannot trigger 
 * again.
 * We need two firing states per ring, because
 * in the (clk == dt) case, we cannot tell which
 * direction we're going.
 */

Right now, CLOCKWISE is only updated when we pass a 01 or 10 state, i.e. when CLK and DT differ.
On 00 and 11 states, it remains unchanged. If we could "unset" it, we might be able to catch more invalid states, so the state machine might not be complete yet. It's very hard to trigger spurious directions changes already, but if they occur, then almost always in bursts of three or so.

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

1 participant