GPIO Interrupts issues?

RebelJD
Posts: 5
Joined: Wed Feb 08, 2023 1:13 pm

GPIO Interrupts issues?

Postby RebelJD » Sat Feb 18, 2023 8:58 pm

Hello, I'm using an ESP32 (DEV board) to interface to a quadrature encoder using GPIO interrupts. I'm using the Arduino IDE. I'm having issues getting it to work as intended so I've written some simple code to troubleshoot. From my testing it seems it is double counting when I trigger an interrupt on the FALLING edge. It works fine when I trigger on a LEADING edge and CHANGE. It also works when I trigger on HIGH, but does not work when I trigger on LOW. The encoder (100 ppr) I'm using is 5v TTL so I'm shifting the level with a 74AHCT125N powered by the 3.3v from the ESP32. I've looked at the signal with a scope and it the rising and falling edges look fine. I have also tested with a Linear Scale and it acts just the same.

Here is the simple code I'm using to troubleshoot. (sorry not sure how to make this display as code)

Any help would be appreciated.

#define A_pin 34
volatile long NSV = 0;
void IRAM_ATTR EnCnt (){NSV++;}
void setup()
{
Serial.begin(115200);
attachInterrupt(A_pin,EnCnt,LOW);
}
void loop()
{
Serial.println(NSV);
}


/* RISING - works fine, counts to 100 in either direction
CHANGE - works fine, counts to 200 in either direction
FALLING - ERROR , counts to 200 in either direction, s/b 100
HIGH - works fine, counts to 100 in either direction
LOW - ERROR, counts to 200 in either direction, s/b 100, sometimes doesnt work at all.
*/

Who is online

Users browsing this forum: Bing [Bot] and 80 guests