Kiko Ishimoto / QEI2

Dependents:   Nucleo_Motor Nucleo_Motor mbed_test_enc mbed_touteki_MR1 ... more

Fork of QEI2 by Kiko Ishimoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QEI.h Source File

QEI.h

00001 
00002 
00003 #ifndef QEI_H
00004 #define QEI_H
00005 
00006 
00007 #include "mbed.h"
00008 
00009 
00010 #define PREV_MASK 0x1 //Mask for the previous state in determining direction
00011 //of rotation.
00012 #define CURR_MASK 0x2 //Mask for the current state in determining direction
00013 //of rotation.
00014 #define INVALID   0x3 //XORing two states where both bits have changed.
00015 
00016 class QEI
00017 {
00018 protected :
00019     PinName Pin[3];    
00020     QEI(const QEI& q);
00021     QEI& operator=(const QEI &q) {
00022         return *this;
00023     }
00024 public:
00025     typedef enum Encoding {
00026 
00027         X2_ENCODING,
00028         X4_ENCODING
00029 
00030     } Encoding;
00031 
00032 
00033     QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev,Timer *T, Encoding encoding = X2_ENCODING);
00034 
00035     void qei_reset(void);
00036 
00037     int getCurrentState(void);
00038 
00039 
00040     void set(int pul , int rev);
00041 
00042     int getPulses(void);
00043 
00044     int getRevolutions(void);
00045 
00046     int getAng_rev();
00047 
00048     double getAngle();
00049     double getSumangle();
00050     double getRPM();
00051     double getRPS();
00052     double getRPMS();
00053     double getRPUS();
00054     int          pulsesPerRev_;
00055     void state(int i);
00056 private:
00057     Timer *timer;
00058     //Ticker Tick;
00059     double RPM , RPS ,RPMS , RPUS;
00060     float gettime() {
00061         timer->start();
00062         static float prev_time;
00063         float a = timer->read()-prev_time;
00064         prev_time=timer->read();
00065         return a;
00066     }
00067 
00068     void encode(void);
00069 
00070     void index(void);
00071 
00072     Encoding encoding_;
00073 
00074     InterruptIn channelA_;
00075     InterruptIn channelB_;
00076     InterruptIn index_;
00077     int          round_rev;
00078 
00079     int          prevState_;
00080     int          currState_;
00081     double angle_ , sumangle;
00082     int angle_pulses;
00083     volatile int pulses_;
00084     volatile int revolutions_;
00085 
00086 };
00087 
00088 #endif