This repository was archived by the owner on Feb 28, 2024. It is now read-only.
File tree 3 files changed +41
-4
lines changed
3 files changed +41
-4
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 ) ||
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ class QEI {
148
148
public:
149
149
150
150
typedef enum Encoding {
151
-
151
+ X1_ENCODING,
152
152
X2_ENCODING,
153
153
X4_ENCODING
154
154
Original file line number Diff line number Diff line change @@ -103,6 +103,20 @@ void ArduinoIOExpanderClass::initPins()
103
103
{
104
104
105
105
if (_tca.getAddress () == IO_ADD) {
106
+ PinStatus status = SWITCH_OFF;
107
+ set (IO_WRITE_CH_PIN_00, status);
108
+ set (IO_WRITE_CH_PIN_01, status);
109
+ set (IO_WRITE_CH_PIN_02, status);
110
+ set (IO_WRITE_CH_PIN_03, status);
111
+ set (IO_WRITE_CH_PIN_04, status);
112
+ set (IO_WRITE_CH_PIN_05, status);
113
+ set (IO_WRITE_CH_PIN_06, status);
114
+ set (IO_WRITE_CH_PIN_07, status);
115
+ set (IO_WRITE_CH_PIN_08, status);
116
+ set (IO_WRITE_CH_PIN_09, status);
117
+ set (IO_WRITE_CH_PIN_10, status);
118
+ set (IO_WRITE_CH_PIN_11, status);
119
+
106
120
pinMode (IO_WRITE_CH_PIN_00, OUTPUT);
107
121
pinMode (IO_WRITE_CH_PIN_01, OUTPUT);
108
122
pinMode (IO_WRITE_CH_PIN_02, OUTPUT);
You can’t perform that action at this time.
0 commit comments