Quadrature decoder
Diff: qed.cpp
- Revision:
- 2:72d7f93f2881
- Parent:
- 1:83b43784d90c
--- a/qed.cpp Sat Aug 31 15:54:44 2013 +0000 +++ b/qed.cpp Sat Sep 14 17:16:32 2013 +0000 @@ -4,13 +4,7 @@ : interruptA(channelA), interruptB(channelB) { pulses = 0; - - //Workout what the current state is. - int chanA = interruptA.read(); - int chanB = interruptB.read(); - - //2-bit state. - currState = (chanA << 1) | (chanB); + currState = (interruptA.read() << 1) | (interruptB.read()); prevState = currState; interruptA.rise(this, &QED::decode); @@ -26,20 +20,14 @@ } void QED::decode() { - - int change = 0; - int chanA = interruptA.read(); - int chanB = interruptB.read(); - - currState = (chanA << 1) | (chanB); - - change = (prevState & PREV_MASK) ^ ((currState & CURR_MASK) >> 1); + currState = (interruptA.read() << 1) | (interruptB.read()); + + int change = (prevState & PREV_MASK) ^ ((currState & CURR_MASK) >> 1); if (change == 0) { change = -1; } - pulses -= change; - + pulses -= change; prevState = currState; } \ No newline at end of file