An interface for a simple, 1-track, incremental encoder.

Dependents:   AVC_20110423 incrementalencoder-pid-robot DataBus2018

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IncrementalEncoder.h Source File

IncrementalEncoder.h

00001 #include "mbed.h"
00002 
00003 /** An interface for a simple, 1-track, incremental encoder. If using a simple reflectance sensor, then a voltage comparator
00004  *  circuit will be required to generate the pulsetrain.  See: http://www.bot-thoughts.com/2011/03/avc-bot-wheel-encoders.html
00005  *
00006  */
00007 class IncrementalEncoder
00008 {
00009     public:
00010         /** Create an incremental encoder interface.  Increments counter at every rise and fall signal 
00011          *
00012          * @param pin -- the pin to which a digital pulsetrain is sent
00013          */
00014         IncrementalEncoder(PinName pin);
00015 
00016         /** Get ticks since last call
00017          *
00018          * @returns the number of ticks since the last call to this method
00019          */        
00020         unsigned int read();
00021 
00022         /** Get total tick count since last reset
00023          *
00024          * @returns total ticks since the last reset or instantiation
00025          */
00026         unsigned int readTotal();
00027        
00028         /** Reset the tick counter
00029          *
00030          */
00031         void reset();
00032 
00033     private:
00034         unsigned int _lastTicks;
00035         unsigned int _ticks;
00036         InterruptIn _interrupt;
00037         void _increment();
00038 };