Bryce Williams / QEI

Dependents:   ESP8266_pid_mtrPos_webserver_SDcard_v2 ESP8266_pid_mtrSpeed_Webserver_SDcard ESP8266_pid_spd_and_pos_webserver_SDcard pid_encoder_speed_demo ... more

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 /*
00005     Basic Quadrature Encoder Interface (QEI) Class.
00006     
00007     TODO: Expand to allow setting of quad mode, i.e. count on 
00008     rising of A only, rising and falling of A, rising and falling 
00009     of both A and B. (Forgot what these modes are called but 
00010     can be found in literature online.) 
00011 */
00012 
00013 #include "mbed.h"
00014 
00015 class QEI{
00016     public:
00017         /*
00018             Constructor for QEI objects
00019             @param encA     The mbed pin that encoder input A is on
00020             @param encB     The mbed pin that encoder input B is on
00021         */
00022         QEI(PinName encA, PinName encB);
00023         /*
00024             read() returns total number of counts of the encoder.
00025             Count can be +/- and indicates the overall direction,
00026             (+): CW (-): CCW
00027             @return     The toltal number of counts of the encoder.
00028             
00029             TODO: Add Conversion Overload for this method
00030         */
00031         long read();
00032         /*
00033             reset() clears the counter to 0. 
00034         */
00035         void reset();
00036     private:
00037         long count;         // Total number of counts since start.
00038         InterruptIn _encA;  // Encoder A interrupt pin
00039         DigitalIn _encB;    // Encoder B input pin
00040         /*
00041             Increments/Decrements count on interrrupt.
00042         */
00043         void callback();    // Interrupt callback function
00044 };
00045 
00046 #endif