Quadrature decoder

Dependents:   Telliskivi2_2014

Files at this revision

API Documentation at this revision

Comitter:
Reiko
Date:
Sat Sep 14 17:16:32 2013 +0000
Parent:
1:83b43784d90c
Commit message:
Made code shorter

Changed in this revision

qed.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 83b43784d90c -r 72d7f93f2881 qed.cpp
--- 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