geekhack Projects > Making Stuff Together!
You can put rotary encoders in a keyboard matrix!
homenick:
--- Quote from: Snipeye on Sun, 12 May 2024, 10:14:11 ---
--- Quote from: Findecanor on Sun, 12 May 2024, 07:02:24 ---
--- Quote from: Snipeye on Sat, 11 May 2024, 21:14:57 ---you need about 2K+ scans/second to avoid missing a transition, but that's not too hard to achieve.
--- End quote ---
That's interesting. How do you debounce them?
Do you report a step on the next change and suppress only the opposite turning direction for the bounce period?
Or do you not need to?
--- End quote ---
The traditional method for debouncing encoders is to pass the raw outputs through a state machine (I didn't look closely, but I think it's described right in the stackexchange post https://electronics.stackexchange.com/questions/360637/quadrature-encoder-most-efficient-software-implementationpixel speedrun). QMK debounces individual keys in the matrix, and those debounced values are currently getting handled by the state machine so it's sort of double-debounced, which is providing some less-than-graceful results (the default key debouncing is too aggressive/not a good fit for an encoder).
I've written (for the client I mentioned in my previous post, with 32 encoders) a bitfield-state machine that handles all 32 encoders in parallel by performing bitwise operations on uint32_t variables that worked really well - I plan on submitting another PR to QMK to implement this method since it debounces all encoders at once (instead of running a loop that debounces them all individually).
--- End quote ---
I am sorry, but I've searched the article but couldn't find relevant information about traditional method for debouncing encoders vs state machine.
Snipeye:
--- Quote from: homenick on Tue, 28 May 2024, 20:39:03 ---I am sorry, but I've searched the article but couldn't find relevant information about traditional method for debouncing encoders vs state machine.
--- End quote ---
So a traditional "debounce" would be "make sure the pin stays in a certain state for a certain amount of time/readings before we allow it to change again." That can work with encoders, but a better approach is a state machine to enforce valid transitions. That approach is described pretty well here:
https://forum.arduino.cc/t/reading-rotary-encoders-as-a-state-machine/937388
The actual code can be adapted all sorts of ways.
Navigation
[0] Message Index
[*] Previous page
Go to full version