ESP 32 rising edge interrupt issue

Hi everyone!

I wanted to use two pins of my esp 32 and I faced that problem, it was detected both rising and falling edge of my signal. I wanted to read a tachometer's signal but it didn'tt want to work properly. I have tried it with esp8266 and then it worked fine.

Is there any solution for this problem?

Here is my code:

#include <Arduino.h>
#include <analogWrite.h>

const int pinA = 23;//14
const int pinB = 22;//4

int cA = 0;
int cB = 0;

int enA = 32;
int in1 = 33;
int in2 = 25;

int enB = 13;
int in3 = 26;
int in4 = 27;

void IRAM_ATTR cntA() {
  cA++;
  Serial.print("cA:");
  Serial.println(cA);
  }
void IRAM_ATTR cntB() {
  cB++;
  Serial.print("cB:");
  Serial.println(cB);
  }
  
void Forward( int steps,int mspeed){

  cA = 0;  //  reset counter A to zero
  cB = 0;  //  reset counter B to zero

     // Set Motor A forward
   digitalWrite(in1, HIGH);
   digitalWrite(in2, LOW);
 
   // Set Motor B forward
   digitalWrite(in3, HIGH);
   digitalWrite(in4, LOW);
   
   // Go forward until step value is reached
  while (steps > cA && steps > cB) {
    if (steps > cA) {
    analogWrite(enA, 1*mspeed);
    } else {
    analogWrite(enA, 0);
    }
    if (steps > cB) {
    analogWrite(enB, 1*mspeed);
    } else {
    analogWrite(enB, 0);
    }
    delay(0);
   }
    
  // Stop when done
  analogWrite(enA, 0);
  analogWrite(enB, 0);
  cA = 0;  //  reset counter A to zero
  cB = 0;  //  reset counter B to zero 
}

void Backward (int steps, int mspeed) {

  cA = 0;  //  reset counter A to zero
  cB = 0;  //  reset counter B to zero

     // Set Motor A forward
   digitalWrite(in1, LOW);
   digitalWrite(in2, HIGH);
 
   // Set Motor B forward
   digitalWrite(in3, LOW);
   digitalWrite(in4, HIGH);
   
   while (steps > cA && steps > cB){
     if (steps > cA) {
    analogWrite(enA, 1*mspeed);
    } else {
    analogWrite(enA, 0);
    }
    if (steps > cB) {
    analogWrite(enB, 1*mspeed);
    } else {
    analogWrite(enB, 0);
    }
    delay(0);
   }

   // Stop when done
  analogWrite(enA, 0);
  analogWrite(enB, 0);
  cA = 0;  //  reset counter A to zero
  cB = 0;  //  reset counter B to zero 
}
void setup() 
{
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  pinMode(enA,OUTPUT);

  pinMode(in3,OUTPUT);
  pinMode(in4,OUTPUT);
  pinMode(enB,OUTPUT);

  pinMode(pinA,INPUT_PULLDOWN);
  pinMode(pinB,INPUT_PULLDOWN);

  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt (pinA), cntA, RISING);
  attachInterrupt(digitalPinToInterrupt (pinB), cntB, RISING);  // Increase counter B when speed sensor pin goes High
  
  Forward(20,130);
  delay(2000);
  Backward(20,130);
  delay(2000);
 } 
void loop()
{
}

I also tried with and without pull down the interrupt pins, but it didn't work.

One "solution" would be DO NOT do Serial I/O in the interrupt handler....

Regards,
Ray L.

Start off by reviewing the ports you are using.

int enA = 32; pinMode(enA,OUTPUT);

The ESP32 has 2 32 bit I/O ports. GPIO0 to GPIO32 are assigned to PortA and GPIO32-GPIOX are assigned to portB.

PortA and PortB have very different characteristics. PortB is a input only I/O port. Here is the link to the ESP32 API that holds GPIO and Port information, API Reference - ESP32 - — ESP-IDF Programming Guide latest documentation.