Interrupts based quadrature encoder counter
Hi, I tried finding a simple compact piece of code for a up/down counter working with the quadrature optical rotary encoder (HES-36-2MD).
The chip I use is a PIC18F2455. Connections are made (INT0=RB0, INT1=RB1) and tested with a multimeter giving pulses in the range of 0.04V to 4.85V.
I found this thread and also "The Book of DT's INTERRUPTS".
Lot's of info but to complex for me.
I have the same question as the above mentioned thread asked:- is there a sample code for interfacing quadrature encoders[a/b channels]
- I need to determine position/direction...
- i searched for posts in the pbp forum,but they were all for 1 channel, 2 channels wanted.
Thanks
Re: Interrupts based quadrature encoder counter
I keep this comment in my code that uses encoders:
Code:
' Wiper Chart:
' ============
' A B
' --- ---
' 0 0
' 1 0 /\ CCW
' 1 1
' 0 1 \/ CW
' 0 0
You can check position by reading the Port, and you can check rotation by checking previous position of the two wipers.
I suggest you keep a log of the two Port pins (send a HSEROUT to your PC if you don't have tools like the Saleae Logic probe), and see if your encoder sends the same pulses.
Note that "some" encoders send pulses between the clicks that you feel on the shaft, so don't trust your fingertips.