I bought some rotary encoders from China a while back. There are 5 pins:
Both CLK and DT are pulled up to + with a 10K pull-up resistor on the PCB. For some reasons, the resistor isn't installed for SW.
Each of the position (blue vertical line) always have both CLK and DT high. As the knob is turned, CLK and DT cycles through transitions. The following shows the clockwise rotation.
I have been scratching my head try to get it to work. Not having a hardware debugger for this microcontroller is not helping. I hooked up my logic analyzer to get a better feel.
I guess I have been trying to make it more complicated than needed. I throw in a couple of 0.1uF caps on the CLK and DT lines to get rid of most of the contact bounce.
The naming clued me in to only use the CLK pin to trigger an Level Change IRQ. The only state transition to look out for are: CLK, DT: 01->10 and 00->11.
Since there are usually some form of user feedback, I can ignore the error recovery for the rare glitches.
AVR C code:
Here is a rare find:
The R x C time constant = 10K (pull up) x 0.1uF (added) = 1ms so roughly in the right neighborhood. You can increase that values to 0.22uF for a really sloppy or old switch.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.