basic Quadrature Encoder Library

Dependents:   ESP8266_pid_mtrPos_webserver_SDcard_v2 ESP8266_pid_mtrSpeed_Webserver_SDcard ESP8266_pid_spd_and_pos_webserver_SDcard pid_encoder_speed_demo ... more

Committer:
electromotivated
Date:
Mon Nov 23 02:44:15 2015 +0000
Revision:
0:50aae578cb89
Basic encoder library upload;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
electromotivated 0:50aae578cb89 1 #ifndef QEI_H
electromotivated 0:50aae578cb89 2 #define QEI_H
electromotivated 0:50aae578cb89 3
electromotivated 0:50aae578cb89 4 /*
electromotivated 0:50aae578cb89 5 Basic Quadrature Encoder Interface (QEI) Class.
electromotivated 0:50aae578cb89 6
electromotivated 0:50aae578cb89 7 TODO: Expand to allow setting of quad mode, i.e. count on
electromotivated 0:50aae578cb89 8 rising of A only, rising and falling of A, rising and falling
electromotivated 0:50aae578cb89 9 of both A and B. (Forgot what these modes are called but
electromotivated 0:50aae578cb89 10 can be found in literature online.)
electromotivated 0:50aae578cb89 11 */
electromotivated 0:50aae578cb89 12
electromotivated 0:50aae578cb89 13 #include "mbed.h"
electromotivated 0:50aae578cb89 14
electromotivated 0:50aae578cb89 15 class QEI{
electromotivated 0:50aae578cb89 16 public:
electromotivated 0:50aae578cb89 17 /*
electromotivated 0:50aae578cb89 18 Constructor for QEI objects
electromotivated 0:50aae578cb89 19 @param encA The mbed pin that encoder input A is on
electromotivated 0:50aae578cb89 20 @param encB The mbed pin that encoder input B is on
electromotivated 0:50aae578cb89 21 */
electromotivated 0:50aae578cb89 22 QEI(PinName encA, PinName encB);
electromotivated 0:50aae578cb89 23 /*
electromotivated 0:50aae578cb89 24 read() returns total number of counts of the encoder.
electromotivated 0:50aae578cb89 25 Count can be +/- and indicates the overall direction,
electromotivated 0:50aae578cb89 26 (+): CW (-): CCW
electromotivated 0:50aae578cb89 27 @return The toltal number of counts of the encoder.
electromotivated 0:50aae578cb89 28
electromotivated 0:50aae578cb89 29 TODO: Add Conversion Overload for this method
electromotivated 0:50aae578cb89 30 */
electromotivated 0:50aae578cb89 31 long read();
electromotivated 0:50aae578cb89 32 /*
electromotivated 0:50aae578cb89 33 reset() clears the counter to 0.
electromotivated 0:50aae578cb89 34 */
electromotivated 0:50aae578cb89 35 void reset();
electromotivated 0:50aae578cb89 36 private:
electromotivated 0:50aae578cb89 37 long count; // Total number of counts since start.
electromotivated 0:50aae578cb89 38 InterruptIn _encA; // Encoder A interrupt pin
electromotivated 0:50aae578cb89 39 DigitalIn _encB; // Encoder B input pin
electromotivated 0:50aae578cb89 40 /*
electromotivated 0:50aae578cb89 41 Increments/Decrements count on interrrupt.
electromotivated 0:50aae578cb89 42 */
electromotivated 0:50aae578cb89 43 void callback(); // Interrupt callback function
electromotivated 0:50aae578cb89 44 };
electromotivated 0:50aae578cb89 45
electromotivated 0:50aae578cb89 46 #endif