simple QEI library. no return speed, only return angle.
Dependents: WRS_mechanamu_test
QEI.h@0:bffc97496048, 2018-08-20 (annotated)
- Committer:
- sgrsn
- Date:
- Mon Aug 20 04:54:24 2018 +0000
- Revision:
- 0:bffc97496048
- Child:
- 1:6fa863d09d45
- Child:
- 2:62821df48957
simple QEI
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:bffc97496048 | 1 | #ifndef QEI_H |
sgrsn | 0:bffc97496048 | 2 | #define QEI_H |
sgrsn | 0:bffc97496048 | 3 | |
sgrsn | 0:bffc97496048 | 4 | #include "mbed.h" |
sgrsn | 0:bffc97496048 | 5 | |
sgrsn | 0:bffc97496048 | 6 | |
sgrsn | 0:bffc97496048 | 7 | #define PREV_MASK 0x1 //Mask for the previous state in determining direction |
sgrsn | 0:bffc97496048 | 8 | //of rotation. |
sgrsn | 0:bffc97496048 | 9 | #define CURR_MASK 0x2 //Mask for the current state in determining direction |
sgrsn | 0:bffc97496048 | 10 | //of rotation. |
sgrsn | 0:bffc97496048 | 11 | #define INVALID 0x3 //XORing two states where both bits have changed. |
sgrsn | 0:bffc97496048 | 12 | |
sgrsn | 0:bffc97496048 | 13 | |
sgrsn | 0:bffc97496048 | 14 | class QEI { |
sgrsn | 0:bffc97496048 | 15 | |
sgrsn | 0:bffc97496048 | 16 | public: |
sgrsn | 0:bffc97496048 | 17 | |
sgrsn | 0:bffc97496048 | 18 | QEI(PinName A, PinName B, int ppr); |
sgrsn | 0:bffc97496048 | 19 | |
sgrsn | 0:bffc97496048 | 20 | float getAngle(); |
sgrsn | 0:bffc97496048 | 21 | |
sgrsn | 0:bffc97496048 | 22 | private: |
sgrsn | 0:bffc97496048 | 23 | |
sgrsn | 0:bffc97496048 | 24 | void encode(void); |
sgrsn | 0:bffc97496048 | 25 | |
sgrsn | 0:bffc97496048 | 26 | InterruptIn channelA; |
sgrsn | 0:bffc97496048 | 27 | InterruptIn channelB; |
sgrsn | 0:bffc97496048 | 28 | float angle; |
sgrsn | 0:bffc97496048 | 29 | int currState; |
sgrsn | 0:bffc97496048 | 30 | int prevState; |
sgrsn | 0:bffc97496048 | 31 | int position; |
sgrsn | 0:bffc97496048 | 32 | float _ppr; |
sgrsn | 0:bffc97496048 | 33 | }; |
sgrsn | 0:bffc97496048 | 34 | |
sgrsn | 0:bffc97496048 | 35 | #endif |