Library to read out speed and position from a quadrature encoder. This library uses X2 decoding.

Dependents:   BMT-K9_encoder BMT-K9-Regelaar K9motoraansturing_copy EMGverwerking ... more

Revision:
3:dcb7bdc73882
Parent:
1:2dd7853c911a
Child:
4:69be34f39c9f
--- a/encoder.h	Tue Oct 01 21:47:15 2013 +0000
+++ b/encoder.h	Mon Sep 29 15:45:09 2014 +0000
@@ -5,12 +5,14 @@
 /** Encoder class.
  *  Used to read out incremental position encoder. Decodes position in X2 configuration.
  *
+ *  Speed estimation is very crude and computationally intensive. Turned off by default
+ *
  * Example:
  * @code
  * #include "mbed.h"
  * #include "Encoder.h"
  *
- *   Encoder motor1(PTD0,PTC9);
+ *   Encoder motor1(PTD0,PTC9,true);
  *   Serial pc(USBTX,USBRX);
  *   pc.baud(115200);
  *   while(1) {
@@ -26,7 +28,7 @@
     @param int_a Pin to be used as InterruptIn! Be careful, as not all pins on all platforms may be used as InterruptIn.
     @param int_b second encoder pin, used as DigitalIn. Can be any DigitalIn pin, not necessarily on InterruptIn location
     */
-    Encoder(PinName int_a, PinName int_b);
+    Encoder(PinName int_a, PinName int_b, bool speed=false);
     /** Request position
     @returns current position in encoder counts
     */
@@ -42,6 +44,7 @@
     private:
     void encoderFalling(void);
     void encoderRising(void);
+    bool m_speed_enabled;
     Timer EncoderTimer;
     Timeout EncoderTimeout;
     InterruptIn pin_a;