Library for manual Encoders as used in user interfaces. Very simple, reduced and rock solid encoder library. Counts full pulses only. Inherent debouncing through state machine. Running on a regular timer IRQ. No IRQ jamming through bouncing. Immune to false edges giving unwanted counts when moving partial steps. Not depending on PinDetect or anything else. May be enhanced by adding acceleration and push button debouncing in the future.

Library for manual Encoders as used in user interfaces. Very simple, reduced and rock solid. Counts full pulses/steps only. Inherent debouncing through state machine. No time dependency for debouncing. Very tight code running in a regular timer IRQ. No IRQ jamming through bouncing edges. Immune to false edges giving unwanted counts when moving partial steps back and forth. Not depending on PinDetect or any other debouncing library. May be enhanced in the near future by adding acceleration and push button debouncing.

Revision:
4:ee384561bfa4
Parent:
3:e8e1481ac042
Child:
5:70534b19d8bf
--- a/Encoder.cpp	Wed Nov 26 09:40:40 2014 +0000
+++ b/Encoder.cpp	Wed Dec 17 19:35:25 2014 +0000
@@ -47,8 +47,11 @@
 #define ENCODER_SAMPLE_PERIOD_US (250)
 #endif
 
+// Counts steps := pulses
 static volatile uint16_t Pulses;
-static bool UpDown, Ready;
+
+// State variables
+static volatile bool UpDown, Ready;
 
 DigitalIn  PinA(ENCODER_PIN_A), PinB(ENCODER_PIN_B);
 
@@ -63,7 +66,7 @@
     EncoderTick.attach_us (&EncoderTickIRQ, ENCODER_SAMPLE_PERIOD_US);
 }
 
-// Switch off Pullups and IRQ to save power f. e.
+// Switch off IRQ and change Pullups to PullDowns to save power
 void EncoderStop ()
 {
     PinA.mode(PullDown);