enc

Dependents:   ToyBox ohta

Fork of QEI by Aaron Berk

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QEI.h Source File

QEI.h

00001 #ifndef QEI_H
00002 #define QEI_H
00003 
00004 #include "mbed.h"
00005 
00006 #define PREV_MASK 0x1 //Mask for the previous state in determining direction of rotation.
00007 #define CURR_MASK 0x2 //Mask for the current state in determining direction of rotation.
00008 #define INVALID   0x3 //XORing two states where both bits have changed.
00009 
00010 class QEI {
00011 
00012 public:
00013 
00014     typedef enum Encoding {
00015 
00016         X2_ENCODING,
00017         X4_ENCODING
00018 
00019     } Encoding;
00020 
00021     QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING);
00022 
00023     void reset(void);
00024 
00025     int getCurrentState(void);
00026 
00027     int getPulses(void);
00028 
00029     int getRevolutions(void);
00030 
00031 private:
00032 
00033     void encode(void);
00034 
00035     void index(void);
00036 
00037     Encoding encoding_;
00038 
00039     InterruptIn channelA_;
00040     InterruptIn channelB_;
00041     InterruptIn index_;
00042 
00043     int          pulsesPerRev_;
00044     int          prevState_;
00045     int          currState_;
00046 
00047     volatile int pulses_;
00048     volatile int revolutions_;
00049 
00050 };
00051 
00052 #endif