From e6eaf7ac65ed158b1724a4ccd34437cc818db987 Mon Sep 17 00:00:00 2001 From: svollenweider <34137138+svollenweider@users.noreply.github.com> Date: Thu, 24 Mar 2022 17:30:47 +0100 Subject: [PATCH 1/4] Update ArduinoIOExpander.cpp --- src/utility/ioexpander/ArduinoIOExpander.cpp | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/utility/ioexpander/ArduinoIOExpander.cpp b/src/utility/ioexpander/ArduinoIOExpander.cpp index 3dc1be0..89af7b2 100644 --- a/src/utility/ioexpander/ArduinoIOExpander.cpp +++ b/src/utility/ioexpander/ArduinoIOExpander.cpp @@ -88,6 +88,19 @@ void ArduinoIOExpanderClass::initPins() if (_tca.getAddress() == IO_ADD) { PinStatus status = SWITCH_OFF; + set(IO_WRITE_CH_PIN_00, status); + set(IO_WRITE_CH_PIN_01, status); + set(IO_WRITE_CH_PIN_02, status); + set(IO_WRITE_CH_PIN_03, status); + set(IO_WRITE_CH_PIN_04, status); + set(IO_WRITE_CH_PIN_05, status); + set(IO_WRITE_CH_PIN_06, status); + set(IO_WRITE_CH_PIN_07, status); + set(IO_WRITE_CH_PIN_08, status); + set(IO_WRITE_CH_PIN_09, status); + set(IO_WRITE_CH_PIN_10, status); + set(IO_WRITE_CH_PIN_11, status); + pinMode(IO_WRITE_CH_PIN_00, OUTPUT); pinMode(IO_WRITE_CH_PIN_01, OUTPUT); pinMode(IO_WRITE_CH_PIN_02, OUTPUT); @@ -113,18 +126,7 @@ void ArduinoIOExpanderClass::initPins() pinMode(IO_READ_CH_PIN_10, INPUT); pinMode(IO_READ_CH_PIN_11, INPUT); - set(IO_WRITE_CH_PIN_00, status); - set(IO_WRITE_CH_PIN_01, status); - set(IO_WRITE_CH_PIN_02, status); - set(IO_WRITE_CH_PIN_03, status); - set(IO_WRITE_CH_PIN_04, status); - set(IO_WRITE_CH_PIN_05, status); - set(IO_WRITE_CH_PIN_06, status); - set(IO_WRITE_CH_PIN_07, status); - set(IO_WRITE_CH_PIN_08, status); - set(IO_WRITE_CH_PIN_09, status); - set(IO_WRITE_CH_PIN_10, status); - set(IO_WRITE_CH_PIN_11, status); + } else { pinMode(DIN_READ_CH_PIN_00, INPUT); pinMode(DIN_READ_CH_PIN_01, INPUT); From 1cdceadb73a4a6ba05c087c3dcea5bc3f3614c72 Mon Sep 17 00:00:00 2001 From: svollenweider <34137138+svollenweider@users.noreply.github.com> Date: Mon, 23 May 2022 13:20:45 +0200 Subject: [PATCH 2/4] Update QEI.cpp Added X1 Encoding --- src/utility/QEI/QEI.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/utility/QEI/QEI.cpp b/src/utility/QEI/QEI.cpp index 22f32e4..970b1f9 100644 --- a/src/utility/QEI/QEI.cpp +++ b/src/utility/QEI/QEI.cpp @@ -152,7 +152,9 @@ QEI::QEI(PinName channelA, //X4 encoding uses interrupts on channel A, //and on channel B. channelA_.rise(mbed::callback(this, &QEI::encode)); - channelA_.fall(mbed::callback(this, &QEI::encode)); + if(encoding != X1_ENCODING){ + channelA_.fall(mbed::callback(this, &QEI::encode)); + } //If we're using X4 encoding, then attach interrupts to channel B too. if (encoding == X4_ENCODING) { @@ -191,6 +193,20 @@ int QEI::getRevolutions(void) { } +// +-------------+ +// | X1 Encoding | +// +-------------+ +// +// When observing states two patterns will appear: +// +// Counter clockwise rotation: +// +// 10 -> 10 -> 10 -> 10 -> ... +// +// Clockwise rotation: +// +// 11 -> 11 -> 11 -> ... +// // +-------------+ // | X2 Encoding | // +-------------+ @@ -243,8 +259,15 @@ void QEI::encode(void) { //2-bit state. currState_ = (chanA << 1) | (chanB); - - if (encoding_ == X2_ENCODING) { + + if(encoding_ == X1_ENCODING){ + if(currState_ == 0x3){ + pulses++; + } + if(currState_ == 0x2){ + pulses--; + } + } else if (encoding_ == X2_ENCODING) { //11->00->11->00 is counter clockwise rotation or "forward". if ((prevState_ == 0x3 && currState_ == 0x0) || From 1f9f0a884bb6948cb37f9d7e0fc83065637bc209 Mon Sep 17 00:00:00 2001 From: svollenweider <34137138+svollenweider@users.noreply.github.com> Date: Mon, 23 May 2022 13:22:40 +0200 Subject: [PATCH 3/4] Update QEI.cpp Fixed Typo --- src/utility/QEI/QEI.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utility/QEI/QEI.cpp b/src/utility/QEI/QEI.cpp index 970b1f9..db767db 100644 --- a/src/utility/QEI/QEI.cpp +++ b/src/utility/QEI/QEI.cpp @@ -262,10 +262,10 @@ void QEI::encode(void) { if(encoding_ == X1_ENCODING){ if(currState_ == 0x3){ - pulses++; + pulses_++; } if(currState_ == 0x2){ - pulses--; + pulses_--; } } else if (encoding_ == X2_ENCODING) { From 29642fe0d8256fcc8f33da9d687f8981a52b02d6 Mon Sep 17 00:00:00 2001 From: svollenweider <34137138+svollenweider@users.noreply.github.com> Date: Mon, 23 May 2022 13:23:14 +0200 Subject: [PATCH 4/4] Update QEI.h Added X1_Encoding in header File --- src/utility/QEI/QEI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/QEI/QEI.h b/src/utility/QEI/QEI.h index 5ab79d2..8e6fba0 100644 --- a/src/utility/QEI/QEI.h +++ b/src/utility/QEI/QEI.h @@ -148,7 +148,7 @@ class QEI { public: typedef enum Encoding { - + X1_ENCODING, X2_ENCODING, X4_ENCODING