This repository was archived by the owner on Feb 28, 2024. It is now read-only.
File tree 1 file changed +26
-3
lines changed
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,
152
152
// X4 encoding uses interrupts on channel A,
153
153
// and on channel B.
154
154
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
+ }
156
158
157
159
// If we're using X4 encoding, then attach interrupts to channel B too.
158
160
if (encoding == X4_ENCODING) {
@@ -191,6 +193,20 @@ int QEI::getRevolutions(void) {
191
193
192
194
}
193
195
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
+ //
194
210
// +-------------+
195
211
// | X2 Encoding |
196
212
// +-------------+
@@ -243,8 +259,15 @@ void QEI::encode(void) {
243
259
244
260
// 2-bit state.
245
261
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) {
248
271
249
272
// 11->00->11->00 is counter clockwise rotation or "forward".
250
273
if ((prevState_ == 0x3 && currState_ == 0x0 ) ||
You can’t perform that action at this time.
0 commit comments