Quadrature encoder interface library.

Dependents:   EX_encoder_qei_hukeqin EX_encoder_PID_QianYuyang EX_encoder_PID_QianYuyang EX_encoder_PID_QianYuyangV2

Files at this revision

API Documentation at this revision

Comitter:
brainliang
Date:
Tue Apr 09 06:54:47 2019 +0000
Parent:
0:5c2ad81551aa
Commit message:
dsaf

Changed in this revision

QEI.cpp Show annotated file Show diff for this revision Revisions of this file
QEI.h Show annotated file Show diff for this revision Revisions of this file
--- a/QEI.cpp	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.cpp	Tue Apr 09 06:54:47 2019 +0000
@@ -191,6 +191,11 @@
 
 }
 
+//获取旋转方向函数
+int QEI::getState(void)
+{
+    return state_;
+}
 // +-------------+
 // | X2 Encoding |
 // +-------------+
@@ -249,14 +254,14 @@
         //11->00->11->00 is counter clockwise rotation or "forward".
         if ((prevState_ == 0x3 && currState_ == 0x0) ||
                 (prevState_ == 0x0 && currState_ == 0x3)) {
-
+            state_ = 1;
             pulses_++;
 
         }
         //10->01->10->01 is clockwise rotation or "backward".
         else if ((prevState_ == 0x2 && currState_ == 0x1) ||
                  (prevState_ == 0x1 && currState_ == 0x2)) {
-
+            state_ = -1;
             pulses_--;
 
         }
@@ -271,6 +276,11 @@
 
             if (change == 0) {
                 change = -1;
+                state_ = -1;
+            }
+            else 
+            {
+                state_ = 1;
             }
 
             pulses_ -= change;
--- a/QEI.h	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.h	Tue Apr 09 06:54:47 2019 +0000
@@ -207,7 +207,8 @@
      * @return Number of revolutions which have occured on the index channel.
      */
     int getRevolutions(void);
-
+    
+    int getState(void);
 private:
 
     /**
@@ -235,7 +236,8 @@
     int          pulsesPerRev_;
     int          prevState_;
     int          currState_;
-
+    int          state_; 
+    
     volatile int pulses_;
     volatile int revolutions_;