driver for incremental encoder
decoder.h@2:b82d31306c4b, 2019-01-09 (annotated)
- Committer:
- ianaherne
- Date:
- Wed Jan 09 15:00:23 2019 +0000
- Revision:
- 2:b82d31306c4b
- Parent:
- 1:017efde7ab29
- Child:
- 3:4a03a73d7554
added limits for encoder count
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ianaherne | 0:c3a05fe15b84 | 1 | #ifndef DECODER_H |
ianaherne | 0:c3a05fe15b84 | 2 | #define DECODER_H |
ianaherne | 0:c3a05fe15b84 | 3 | #include "mbed.h" |
ianaherne | 0:c3a05fe15b84 | 4 | |
ianaherne | 0:c3a05fe15b84 | 5 | |
ianaherne | 0:c3a05fe15b84 | 6 | |
ianaherne | 0:c3a05fe15b84 | 7 | |
ianaherne | 0:c3a05fe15b84 | 8 | class decoder{ |
ianaherne | 0:c3a05fe15b84 | 9 | |
ianaherne | 0:c3a05fe15b84 | 10 | public: |
ianaherne | 0:c3a05fe15b84 | 11 | |
ianaherne | 2:b82d31306c4b | 12 | |
ianaherne | 2:b82d31306c4b | 13 | /* These values control the upper and lower limits the the count will go to change limits to suit application*/ |
ianaherne | 2:b82d31306c4b | 14 | typedef enum{ |
ianaherne | 2:b82d31306c4b | 15 | |
ianaherne | 2:b82d31306c4b | 16 | |
ianaherne | 2:b82d31306c4b | 17 | LOWER_LIMIT = 0, |
ianaherne | 2:b82d31306c4b | 18 | UPPER_LIMIT = 15 |
ianaherne | 2:b82d31306c4b | 19 | |
ianaherne | 2:b82d31306c4b | 20 | |
ianaherne | 2:b82d31306c4b | 21 | }limits_t; |
ianaherne | 2:b82d31306c4b | 22 | |
ianaherne | 0:c3a05fe15b84 | 23 | decoder(PinName channelA,PinName channelB); |
ianaherne | 0:c3a05fe15b84 | 24 | |
ianaherne | 0:c3a05fe15b84 | 25 | void isr(); |
ianaherne | 0:c3a05fe15b84 | 26 | |
ianaherne | 0:c3a05fe15b84 | 27 | int8_t getDirection(); |
ianaherne | 0:c3a05fe15b84 | 28 | int16_t getCount(); |
ianaherne | 1:017efde7ab29 | 29 | void reset(); |
ianaherne | 0:c3a05fe15b84 | 30 | |
ianaherne | 0:c3a05fe15b84 | 31 | |
ianaherne | 0:c3a05fe15b84 | 32 | |
ianaherne | 0:c3a05fe15b84 | 33 | private: |
ianaherne | 0:c3a05fe15b84 | 34 | |
ianaherne | 1:017efde7ab29 | 35 | InterruptIn _channelA; // interrupt only required on one channel |
ianaherne | 1:017efde7ab29 | 36 | DigitalIn _channelB; // channelB is only required for comparison to determine direction |
ianaherne | 0:c3a05fe15b84 | 37 | |
ianaherne | 0:c3a05fe15b84 | 38 | |
ianaherne | 0:c3a05fe15b84 | 39 | int8_t _direction; |
ianaherne | 0:c3a05fe15b84 | 40 | int16_t _count; |
ianaherne | 0:c3a05fe15b84 | 41 | int16_t _oldCount; |
ianaherne | 0:c3a05fe15b84 | 42 | |
ianaherne | 0:c3a05fe15b84 | 43 | |
ianaherne | 0:c3a05fe15b84 | 44 | }; |
ianaherne | 0:c3a05fe15b84 | 45 | |
ianaherne | 0:c3a05fe15b84 | 46 | #endif |