M5Dial
M5Dial copied to clipboard
Encoder works poorly due to undefined CORE_INT40_PIN and CORE_INT41_PIN
I am a developer on the same project cited in issue #5. We have discovered an issue whereby, when you spin the dial rapidly in one direction, the sequence of encoder delta values often changes sign. For example, you might see the sequence -1,-1,-1,-2,-1,2,-1 . The (+)2 is spurious; the dial is only spinning in one direction. Furthermore, the magnitude of the delta never exceeds 2.
I have tracked it down to the fact that attach_interrupt in Encoder.h is failing. The reason is that M5Dial.h has
#define DIAL_ENCODER_PIN_A 41
#define DIAL_ENCODER_PIN_B 40
but in Encoder.h, the list of interrupt pin defines ends at 39, i.e.
...
#define CORE_INT36_PIN 36
#define CORE_INT39_PIN 39
I suspect that this is because, on plain ESP32, the highest numbered GPIO is 39, whereas ESP32-S3 has GPIO numbers up to 48, and the code was not updated to reflect that.
When the interrupt does not attach, the update() method runs only when Encoder.read() is called, and that is not necessarily frequently enough to catch all encoder edges during fast rotation.
I manually added the following lines to Encoder.h to fix the problem:
#define CORE_INT40_PIN 40
#define CORE_INT41_PIN 41
A complete fix might include other GPIO numbers as well, although 40 and 41 suffice for the M5Dial hardware that uses those pins.