Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ESCON_encoder.h@0:c763749ece81, 2020-03-23 (annotated)
- Committer:
- dsfqfqds
- Date:
- Mon Mar 23 11:21:10 2020 +0000
- Revision:
- 0:c763749ece81
HRI;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dsfqfqds | 0:c763749ece81 | 1 | /* |
| dsfqfqds | 0:c763749ece81 | 2 | * @author Jinhyuk Yoon |
| dsfqfqds | 0:c763749ece81 | 3 | * |
| dsfqfqds | 0:c763749ece81 | 4 | * Designed to control ESCON via NUCELO-F767ZI |
| dsfqfqds | 0:c763749ece81 | 5 | */ |
| dsfqfqds | 0:c763749ece81 | 6 | |
| dsfqfqds | 0:c763749ece81 | 7 | #include "mbed.h" |
| dsfqfqds | 0:c763749ece81 | 8 | #define PI 3.14159265358979323846 |
| dsfqfqds | 0:c763749ece81 | 9 | |
| dsfqfqds | 0:c763749ece81 | 10 | #define PREV_MASK 0x1 //Mask for the previous state in determining direction |
| dsfqfqds | 0:c763749ece81 | 11 | //of rotation. |
| dsfqfqds | 0:c763749ece81 | 12 | #define CURR_MASK 0x2 //Mask for the current state in determining direction |
| dsfqfqds | 0:c763749ece81 | 13 | //of rotation. |
| dsfqfqds | 0:c763749ece81 | 14 | #define INVALID 0x3 //XORing two states where both bits have changed. |
| dsfqfqds | 0:c763749ece81 | 15 | |
| dsfqfqds | 0:c763749ece81 | 16 | class ESCON_encoder { |
| dsfqfqds | 0:c763749ece81 | 17 | private: |
| dsfqfqds | 0:c763749ece81 | 18 | void encode(void); |
| dsfqfqds | 0:c763749ece81 | 19 | |
| dsfqfqds | 0:c763749ece81 | 20 | InterruptIn channelA; |
| dsfqfqds | 0:c763749ece81 | 21 | InterruptIn channelB; |
| dsfqfqds | 0:c763749ece81 | 22 | |
| dsfqfqds | 0:c763749ece81 | 23 | int count_per_turn; |
| dsfqfqds | 0:c763749ece81 | 24 | int prevState; |
| dsfqfqds | 0:c763749ece81 | 25 | int currState; |
| dsfqfqds | 0:c763749ece81 | 26 | |
| dsfqfqds | 0:c763749ece81 | 27 | volatile int pulses; |
| dsfqfqds | 0:c763749ece81 | 28 | volatile int revolutions; |
| dsfqfqds | 0:c763749ece81 | 29 | volatile double pos_in_degree; |
| dsfqfqds | 0:c763749ece81 | 30 | volatile double pos_in_radian; |
| dsfqfqds | 0:c763749ece81 | 31 | |
| dsfqfqds | 0:c763749ece81 | 32 | public: |
| dsfqfqds | 0:c763749ece81 | 33 | ESCON_encoder(PinName channelA_, PinName channelB_, int count_per_turn_); |
| dsfqfqds | 0:c763749ece81 | 34 | void reset(void); |
| dsfqfqds | 0:c763749ece81 | 35 | int getCurrentState(void); |
| dsfqfqds | 0:c763749ece81 | 36 | int getPulses(void); |
| dsfqfqds | 0:c763749ece81 | 37 | double getPosInDegree(void); |
| dsfqfqds | 0:c763749ece81 | 38 | double getPosInRadian(void); |
| dsfqfqds | 0:c763749ece81 | 39 | int getRevolutions(void); |
| dsfqfqds | 0:c763749ece81 | 40 | }; |