I am quite new to the ESP32 Platform. Today I tried to connect an rotory encoder with button to my ESP32.
On the Arduino UNO I used interrupts to speed up the detection. And also to make the edge cleaner I use 100nF caps.
Now to my problem: The ESP32 triggers constantly when the edge is changing. The higher to capasitor, and therefor slower the rise/fall time, the more events are detected. This goes so far that if I use a 1000uF cap the ESP32 gets stuck inside a loop that doesn't do away if I remove the cap.
Of cours this makes the use of interrups totally useless. even if I code a software timed backout, it would be more economical to use aktiv pooling.
Am I doing something wrong or is this the desired operation of interreupts, and the UNO was just to slow to give me the same problems?
The code I used:
Code: Select all
const byte interruptPin = 27;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR handleInterrupt() {
portENTER_CRITICAL_ISR(&mux);
interruptCounter++;
portEXIT_CRITICAL_ISR(&mux);
}
void setup() {
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
}
void loop() {
if(interruptCounter>0){
portENTER_CRITICAL(&mux);
interruptCounter--;
portEXIT_CRITICAL(&mux);
numberOfInterrupts++;
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
}
}