Connect encoder channel A to portB.0 (I assume you already have it) and channel B to portB.1. Since channel A is out of phase on channel B turning your encoder CW channel A will be high before channel B and turning it CCW channel B will be high first.
In your interrupt handler check the above conditions
Code:
If portB & %00000011 = 1 Then
a = a + 1
CW = 1
Else
a = a - 1
CW = 0
Endif
If variable CW is 1 then your motor is turning clockwise if CW = 0 then is turning counterclockwise, while word variable a will contain the updated count.
Al.
Last edited by aratti; - 30th August 2009 at 22:57.
All progress began with an idea
Bookmarks