Minorly Fixed
Dependents: AAA_Stabilus322699_LA0016 AAA_Stabilus322699_LA0018 AAA_Stabilus322699_LA0020 AAA_Stabilus322699_LA0021 ... more
Revision 4:46e47753206d, committed 2022-04-11
- Comitter:
- lex9296
- Date:
- Mon Apr 11 06:00:31 2022 +0000
- Parent:
- 3:0db131925e56
- Commit message:
- Upgraded Measure container to i64's Seed
Changed in this revision
QEI.cpp | Show annotated file Show diff for this revision Revisions of this file |
QEI.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 0db131925e56 -r 46e47753206d QEI.cpp --- a/QEI.cpp Fri Apr 08 05:25:22 2022 +0000 +++ b/QEI.cpp Mon Apr 11 06:00:31 2022 +0000 @@ -128,14 +128,15 @@ */ #include "QEI.h" -QEI::QEI (PinName channelA, +QEI::QEI( + PinName channelA, PinName channelB, PinName index, - int pulsesPerRev, - Encoding encoding): channelA_(channelA), - channelB_(channelB), - // led(LED2), - index_(index) { + int64_t pulsesPerRev, + Encoding encoding + ): channelA_(channelA), + channelB_(channelB), + index_(index) { channelA_.mode(PullUp); // LA: Hall 1504 is Open Drain channelB_.mode(PullUp); // @@ -146,8 +147,8 @@ encoding_ = encoding; //Workout what the current state is. - int chanA = channelA_.read(); // LA: Includes a Method, outside - int chanB = channelB_.read(); // + int64_t chanA = channelA_.read(); // LA: Includes a Method, outside + int64_t chanB = channelB_.read(); // //2-bit state. currState_ = (chanA << 1)| (chanB); @@ -174,15 +175,15 @@ revolutions_ = 0; } -int QEI::getCurrentState(void) { +int64_t QEI::getCurrentState(void) { return currState_; } -int QEI::getPulses(void) { +int64_t QEI::getPulses(void) { return pulses_; } -int QEI::getRevolutions(void) { +int64_t QEI::getRevolutions(void) { return revolutions_; } @@ -231,10 +232,8 @@ // predict - if this is the case, it is generally safe to ignore it, update // the state and carry on, with the error correcting itself shortly after. void QEI::encode(void) { -// led = !led; - int change = 0; -// int chanA = channelA_.read(); -// int chanB = channelB_.read(); +int64_t change = 0; + chanA = channelA_.read(); chanB = channelB_.read(); @@ -246,18 +245,14 @@ //11->00->11->00 is counter clockwise rotation or "forward". if ((prevState_ == 0x3 && currState_ == 0x0) || (prevState_ == 0x0 && currState_ == 0x3)) { - pulses_++; - } //10->01->10->01 is clockwise rotation or "backward". else if ((prevState_ == 0x2 && currState_ == 0x1) || (prevState_ == 0x1 && currState_ == 0x2)) { pulses_--; - } - } else if (encoding_ == X4_ENCODING) { //Entered a new valid state. @@ -269,18 +264,13 @@ if (change == 0) { change = -1; } - pulses_ -= change; } } - prevState_ = currState_; - } void QEI::index(void) { - revolutions_++; - }
diff -r 0db131925e56 -r 46e47753206d QEI.h --- a/QEI.h Fri Apr 08 05:25:22 2022 +0000 +++ b/QEI.h Mon Apr 11 06:00:31 2022 +0000 @@ -148,10 +148,8 @@ public: typedef enum Encoding { - X2_ENCODING, X4_ENCODING - } Encoding; /** @@ -176,7 +174,13 @@ * of only channel A where as X4 uses them on both * channels. */ - QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING); + QEI ( + PinName channelA, + PinName channelB, + PinName index, + int64_t pulsesPerRev, + Encoding encoding = X2_ENCODING + ); /** * Reset the encoder. @@ -192,27 +196,27 @@ * bit 1 = The reading from channel B * bit 2 = The reading from channel A */ - int getCurrentState(void); + int64_t getCurrentState(void); /** * Read the number of pulses recorded by the encoder. * * @return Number of pulses which have occured. */ - int getPulses(void); + int64_t getPulses(void); /** * Read the number of revolutions recorded by the encoder on the index channel. * * @return Number of revolutions which have occured on the index channel. */ - int getRevolutions(void); + int64_t getRevolutions(void); - inline int getChannelA() { + inline int64_t getChannelA() { return chanA; } - inline int getChannelB() { + inline int64_t getChannelB() { return chanB; } @@ -240,17 +244,15 @@ InterruptIn channelB_; InterruptIn index_; - int pulsesPerRev_; - int prevState_; - int currState_; + int64_t pulsesPerRev_; + int64_t prevState_; + int64_t currState_; - int chanA; - int chanB; + int64_t chanA; + int64_t chanB; - volatile int pulses_; - volatile int revolutions_; -// DigitalOut led; + volatile int64_t pulses_; + volatile int64_t revolutions_; }; - #endif /* QEI_H */