Quadrature decoder
Diff: qed.h
- Revision:
- 0:0e8cb3139868
diff -r 000000000000 -r 0e8cb3139868 qed.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/qed.h Mon Jul 29 20:25:05 2013 +0000 @@ -0,0 +1,28 @@ +#ifndef QED_H +#define QED_H + +#include "mbed.h" + +#define PREV_MASK 0x1 //Mask for the previous state in determining direction of rotation. +#define CURR_MASK 0x2 //Mask for the current state in determining direction of rotation. +#define INVALID 0x3 //XORing two states where both bits have changed. + +class QED { +public: + QED(PinName channelA, PinName channelB); + + int read(); + +private: + void decode(); + + InterruptIn interruptA; + InterruptIn interruptB; + + volatile int pulses; + + int prevState; + int currState; +}; + +#endif \ No newline at end of file