Rotary encoder interruption issue with SPI display on some GPIOs #2615
Replies: 9 comments 3 replies
-
I did a further test with an I2C 1306 display with U8G2 I2C library in HW and in this case the encoder works correctly on all gpios or at least on some that previously gave problems. |
Beta Was this translation helpful? Give feedback.
-
Moved to a discussion because this looks like a HW issue that's not core related or reproducible outside your physical setup. If you can find an MCVE that runs w/o special HW and produces logic analyzer outputs we can look at, we can take a deeper look. Otherwise, we're at the guesswork stage here. In general the GPIOs are all identically handled (except for the LED on the PicoW). It's a single 32-bit register in the MCU and we just mask off specific pins. Even the GPIOs that are also connected to the ADC, for |
Beta Was this translation helpful? Give feedback.
-
I did the same test but without SPI. I attach images: |
Beta Was this translation helpful? Give feedback.
-
There are no bounces on the A and B signals which could generate errors in both tests. But with the display initialized with continuous writing of text the encoder goes a little crazy. I don't feel like the code I use is wrong, I've used it many times on AVR and have never encountered such problems. Even with another RP2040 board with SPI display with software management, encoder works correctly. |
Beta Was this translation helpful? Give feedback.
-
I might do one more test. I create a quadrature signal A and B with two GPIOs and connect them to the encoder reading GPIOs so I can check if in the real case there could be any disturbances on the signal. |
Beta Was this translation helpful? Give feedback.
-
In the simulation of the two quadrature signals generated via software and applied to the two GPIOs with interrupts I do not encounter any problems. In this case, however, the signals are read via interrupt but not when data is being transferred to the display. |
Beta Was this translation helpful? Give feedback.
-
Software quadrature signal
|
Beta Was this translation helpful? Give feedback.
-
I think it's a nuisance problem. I made the signal in quadrature with an st32 and connected pins A and B to the rp2040 and I don't get incorrect values in the counting with SPI display active. It's a hardware problem that I need to identify. |
Beta Was this translation helpful? Give feedback.
-
I solved it via software so as to ignore pulses on signals A and B that were too close together in time. In this way bounces are eliminated. This is the part of code inserted in the ISR that manages the two channels A and B:
I check with an oscilloscope where these bounces occur which I was unable to identify with a quick analysis. Perhaps bounces exceed the 0.2V hysteresis of the rp2040's GPIOs, generating erroneous interrupt pulses. Or more precisely with the noise of the SPI bus I exceed the 0.2V of the GPIO hysteresis with the noise, generating false interruptions. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I built a custom board rp2040 and it works correctly.
I'm testing with an SPI ST7735 display (Esplora) with a mechanical rotary encode button as well.
The display works correctly in SPI with the library
TFT_eSPI.
Mechanical encoder also works well if I do the test without a display and it also works correctly with the display but only on some pins such as D0 (A), D1 (B) and D2 (button).
The button does not have an interrupt routine that handles it.
However, if I use pins, for example from D20 to D29, unbalance the count when turning the knob.
It also jumps 3 or 4 randomly by 1 or more units, both in one direction and in the other direction of rotation.
It's like bounces are happening but I checked with an oscilloscope and everything is correct.
The encoder has circuitry that filters contact bounces.
I tried to reduce the speed of the SPI bus up to 1MHz but the problem remains.
I don't understand what such behavior could be due to.
I attach the code I use for the test.
Together there is User_setup.h but it is for reference only to set up the TFT_eSPI library
Encoder_GitHub.zip
Beta Was this translation helpful? Give feedback.
All reactions