geezer88
Senior Member
I've been working on a project that would use a rotary encoder for user input. My first attempt was a miserable failure, and after a bit of head scratching I found my "new" surplus encoder was no good. So, to sort the good from the bad, I cobbled up a tester with my Picaxe test bed. First the hardware.
I am only using three I/O. B.1 and B.2 are the two encoder connections. B.5 is used to drive a serial display. In this case, the display is this one: http://www.picaxeforum.co.uk/showthread.php?20521-Inexpensive-Serial-(surplus)-LCD&highlight=surplus+dual+lcd
The encoder common pin is connected to ground, and a 10K resistor goes from +5 to each phase connection. The phase connections are then routed to the Picaxe inputs. Very simple; when an encoder switch closes the input is low and when it is open, the pullup resistor sends it high.
The program uses three lines of the display. Lines one and two show phases A and B graphically, with an underscore representing low, and a solid block for high. This makes it real easy to see the phase relationship change as the knob is turned left and right. The third line prints CW or CCW and a counter that starts at 100 to show how many "clicks" the knob has turned.
This will never be a finished product for me. The breadboard version works well enough, and as soon as I get a few good encoders squirreled away, it will become some other project.
Here's the code. I have made no attempt to optimize the code for speed or compactness, preferring a straight forward program that is easy to understand and use.
The direction of rotation uses the XOR of old phase A with new phase B. The best explanation I have seen is this one: http://www.tufts.edu/programs/mma/emid/RotaryEncoder.pdf
Because of the display activity and slow clock speed, a fast twist of the knob will get ahead of the Picaxe, so don't consider this code for any high speed need.
View attachment EncoderOutputAnalyser.bas
Hope this is of some use to the rotarians out there.
tom
I am only using three I/O. B.1 and B.2 are the two encoder connections. B.5 is used to drive a serial display. In this case, the display is this one: http://www.picaxeforum.co.uk/showthread.php?20521-Inexpensive-Serial-(surplus)-LCD&highlight=surplus+dual+lcd
The encoder common pin is connected to ground, and a 10K resistor goes from +5 to each phase connection. The phase connections are then routed to the Picaxe inputs. Very simple; when an encoder switch closes the input is low and when it is open, the pullup resistor sends it high.
The program uses three lines of the display. Lines one and two show phases A and B graphically, with an underscore representing low, and a solid block for high. This makes it real easy to see the phase relationship change as the knob is turned left and right. The third line prints CW or CCW and a counter that starts at 100 to show how many "clicks" the knob has turned.
This will never be a finished product for me. The breadboard version works well enough, and as soon as I get a few good encoders squirreled away, it will become some other project.
Here's the code. I have made no attempt to optimize the code for speed or compactness, preferring a straight forward program that is easy to understand and use.
The direction of rotation uses the XOR of old phase A with new phase B. The best explanation I have seen is this one: http://www.tufts.edu/programs/mma/emid/RotaryEncoder.pdf
Because of the display activity and slow clock speed, a fast twist of the knob will get ahead of the Picaxe, so don't consider this code for any high speed need.
View attachment EncoderOutputAnalyser.bas
Hope this is of some use to the rotarians out there.
tom