Basic library to interface a 2 channel quadrature encoder with mBed
QuadratureEncoder.h@2:fcb3790af96b, 2017-07-24 (annotated)
- Committer:
- el15lm
- Date:
- Mon Jul 24 14:07:04 2017 +0000
- Revision:
- 2:fcb3790af96b
- Parent:
- 1:42d1e211e624
added doxygen documentation;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15lm | 2:fcb3790af96b | 1 | /** |
el15lm | 2:fcb3790af96b | 2 | * @file QuadratureEncodere.h |
el15lm | 2:fcb3790af96b | 3 | * @brief this library allows the MCU to intepret the signal coming from a quadrature encoder. |
el15lm | 2:fcb3790af96b | 4 | * @author Lupo Manes |
el15lm | 2:fcb3790af96b | 5 | * @date 24/07/2017 |
el15lm | 2:fcb3790af96b | 6 | */ |
el15lm | 0:8e8c33a797a9 | 7 | #ifndef _QUADRATUREENCODER_H_ |
el15lm | 0:8e8c33a797a9 | 8 | #define _QUADRATUREENCODER_H_ |
el15lm | 0:8e8c33a797a9 | 9 | |
el15lm | 0:8e8c33a797a9 | 10 | #include "mbed.h" |
el15lm | 2:fcb3790af96b | 11 | /** QuadrtureEncoder class. |
el15lm | 2:fcb3790af96b | 12 | * Used to interface with quadrature encoder. |
el15lm | 2:fcb3790af96b | 13 | */ |
el15lm | 0:8e8c33a797a9 | 14 | class QuadratureEncoder |
el15lm | 0:8e8c33a797a9 | 15 | { |
el15lm | 0:8e8c33a797a9 | 16 | public: |
el15lm | 2:fcb3790af96b | 17 | /** Create QuadratureEncode instance |
el15lm | 2:fcb3790af96b | 18 | * @param pinA Pin to which is connected channel A of the encoder |
el15lm | 2:fcb3790af96b | 19 | * @param pinB Pin to which is connected channel Bof the encoder |
el15lm | 2:fcb3790af96b | 20 | */ |
el15lm | 0:8e8c33a797a9 | 21 | QuadratureEncoder(PinName pinA, PinName pinB); |
el15lm | 2:fcb3790af96b | 22 | |
el15lm | 2:fcb3790af96b | 23 | /** Return the total number of pulses sent by the encoder. |
el15lm | 2:fcb3790af96b | 24 | */ |
el15lm | 0:8e8c33a797a9 | 25 | int getTicks(); |
el15lm | 2:fcb3790af96b | 26 | /** Set the total number of ticks back to 0. |
el15lm | 2:fcb3790af96b | 27 | */ |
el15lm | 1:42d1e211e624 | 28 | void reset(); |
el15lm | 0:8e8c33a797a9 | 29 | |
el15lm | 0:8e8c33a797a9 | 30 | private: |
el15lm | 0:8e8c33a797a9 | 31 | void _Bfalling(); |
el15lm | 0:8e8c33a797a9 | 32 | void _Brising(); |
el15lm | 0:8e8c33a797a9 | 33 | InterruptIn _channelB; |
el15lm | 0:8e8c33a797a9 | 34 | DigitalIn _channelA; |
el15lm | 0:8e8c33a797a9 | 35 | int _ticks; |
el15lm | 0:8e8c33a797a9 | 36 | }; |
el15lm | 0:8e8c33a797a9 | 37 | |
el15lm | 0:8e8c33a797a9 | 38 | #endif |