This repository was archived by the owner on Feb 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,9 @@ QEI::QEI(PinName channelA,
152152 // X4 encoding uses interrupts on channel A,
153153 // and on channel B.
154154 channelA_.rise (mbed::callback (this , &QEI::encode));
155- channelA_.fall (mbed::callback (this , &QEI::encode));
155+ if (encoding != X1_ENCODING){
156+ channelA_.fall (mbed::callback (this , &QEI::encode));
157+ }
156158
157159 // If we're using X4 encoding, then attach interrupts to channel B too.
158160 if (encoding == X4_ENCODING) {
@@ -191,6 +193,20 @@ int QEI::getRevolutions(void) {
191193
192194}
193195
196+ // +-------------+
197+ // | X1 Encoding |
198+ // +-------------+
199+ //
200+ // When observing states two patterns will appear:
201+ //
202+ // Counter clockwise rotation:
203+ //
204+ // 10 -> 10 -> 10 -> 10 -> ...
205+ //
206+ // Clockwise rotation:
207+ //
208+ // 11 -> 11 -> 11 -> ...
209+ //
194210// +-------------+
195211// | X2 Encoding |
196212// +-------------+
@@ -243,8 +259,15 @@ void QEI::encode(void) {
243259
244260 // 2-bit state.
245261 currState_ = (chanA << 1 ) | (chanB);
246-
247- if (encoding_ == X2_ENCODING) {
262+
263+ if (encoding_ == X1_ENCODING){
264+ if (currState_ == 0x3 ){
265+ pulses++;
266+ }
267+ if (currState_ == 0x2 ){
268+ pulses--;
269+ }
270+ } else if (encoding_ == X2_ENCODING) {
248271
249272 // 11->00->11->00 is counter clockwise rotation or "forward".
250273 if ((prevState_ == 0x3 && currState_ == 0x0 ) ||
You can’t perform that action at this time.
0 commit comments