Reading two separate rc pwm signals using arduino

Hello! I am trying to read two separate pwm signals from my flight controller pixhawk 2.4.8. The signal that it generates is similar to an rc transmitter signal (1500us pulse width to indicate stop and 2000us for max speed in one direction). I am doing this because I want to read the flight controller's transmitted signal from arduino and then generate a pwm of greater width for my ibt2 from arduino. In other words, I am trying to connect a flight controller to the h bridge motor driver so that I can skid steer my robot. I need arduino because direct connection is very difficult to set up.
The problem with my code is that it gets stuck in the ISR and keeps measuring the signal through PulseTimer1 () and never goes to the main loop. I added serial print statements and saw this. If someone can please help. I would be very thankful.

`#define left1 2
#define right3 3
volatile long StartTime1 = 0;
volatile long CurrentTime1 = 0;
volatile long Pulses1 = 0;
int PulseWidth1 = 0;

volatile long StartTime3 = 0;
volatile long CurrentTime3 = 0;
volatile long Pulses3 = 0;
int PulseWidth3 = 0;

#define RPWM1 5
#define LPWM1 6
#define RPWM3 9
#define LPWM3 10
#define ENL1 7
#define ENR1 8
#define ENL3 13
#define ENR3 12

byte movecase = 0;
volatile bool execute1 = false;
volatile bool execute3 = false;

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);

  attachInterrupt(digitalPinToInterrupt(left1), PulseTimer1, RISING);
  attachInterrupt(digitalPinToInterrupt(right3), PulseTimer3, RISING);

  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  digitalWrite(ENL1, LOW);
  digitalWrite(ENR1, LOW);
  digitalWrite(ENL3, LOW);
  digitalWrite(ENR3, LOW);
}

void loop() {

  if (execute1) {
    delay(20);  // avoid measuring that unusual spike that was seen in a constant 1500 stream
    CurrentTime1 = micros();
    if (CurrentTime1 > StartTime1) {
      Pulses1 = CurrentTime1 - StartTime1;
      StartTime1 = CurrentTime1;
      Serial.print("execute1 ran\n");
    }
    execute1 = false;
  }  // end execute1

  if (execute3) {
    delay(20);
    CurrentTime3 = micros();
    if (CurrentTime3 > StartTime3) {
      Pulses3 = CurrentTime3 - StartTime3;
      StartTime3 = CurrentTime3;
      Serial.print("execute3 ran\n");
    }
    execute3 = false;
  }  // end execute3

  if (Pulses1 > 1700 && Pulses1 < 2000) {
    if (Pulses3 > 1700 && Pulses3 < 2000) {
      movecase = 1;  //FORWARD
    }

    else if (Pulses3 > 1300 && Pulses3 < 1700) {
      movecase = 2;  //ONLY LEFT FORWARD RIGHT STOPPED FOR MOTOR TEST
    }
  }  // end if

  else if (Pulses3 > 1700 && Pulses3 < 2000) {
    if (Pulses1 > 1300 && Pulses1 < 1700) {
      movecase = 3;  //ONLY RIGHT FORWARD LEFT STOPPED FOR MOTOR TEST
    }
  }  // end else if

  switch (movecase) {
    case 1:
      int keepi1forward = 0;
      digitalWrite(ENL1, LOW);
      digitalWrite(ENR1, HIGH);
      digitalWrite(ENL3, LOW);
      digitalWrite(ENR3, HIGH);

      for (int i1forward = 30; i1forward < 100; i1forward++) {
        analogWrite(RPWM1, i1forward);
        analogWrite(RPWM3, i1forward);
        delay(100);
        keepi1forward = i1forward;
      }
      while (Pulses1 > 1700 && Pulses1 < 2000) {
        while (Pulses3 > 1700 && Pulses3 < 2000) {
          analogWrite(RPWM1, keepi1forward);
          analogWrite(RPWM3, keepi1forward);
          delay(100);  //otherwise when the wheel reaches its max speed it stops and restarts to spin to max speed.
        }
      }
      Serial.print("forward ran\n");
      break;

    case 2:
      int keepi1forwardonly = 0;
      digitalWrite(ENL1, LOW);
      digitalWrite(ENR1, HIGH);
      digitalWrite(ENL3, LOW);
      digitalWrite(ENR3, LOW);
      for (int i1forwardonly = 30; i1forwardonly < 100; i1forwardonly++) {
        analogWrite(RPWM1, i1forwardonly);
        delay(100);
        keepi1forwardonly = i1forwardonly;
      }
      while (Pulses1 > 1700 && Pulses1 < 2000) {
        while (Pulses3 > 1300 && Pulses3 < 1700) {
          analogWrite(RPWM1, keepi1forwardonly);
          delay(100);
        }
      }
      Serial.print("left ran\n");
      break;

    case 3:
      int keepi3forwardonly = 0;
      digitalWrite(ENL1, LOW);
      digitalWrite(ENR1, LOW);
      digitalWrite(ENL3, LOW);
      digitalWrite(ENR3, HIGH);
      for (int i3forwardonly = 30; i3forwardonly < 100; i3forwardonly++) {
        analogWrite(RPWM3, i3forwardonly);
        delay(100);
        keepi3forwardonly = i3forwardonly;
      }
      while (Pulses3 > 1700 && Pulses3 < 2000) {
        while (Pulses1 > 1300 && Pulses1 < 1700) {
          analogWrite(RPWM3, keepi3forwardonly);
        }
      }
      Serial.print("right ran\n");
      break;

    default:
      digitalWrite(ENL1, LOW);
      digitalWrite(ENR1, LOW);
      digitalWrite(ENL3, LOW);
      digitalWrite(ENR3, LOW);
      Serial.print("default ran\n");
      break;
  }  // end case
}  // end void loop

void PulseTimer1() {
  execute1 = true;
}
void PulseTimer3() {
  execute3 = true;
}
`

I tried changing the RISING to CHANGE but that didnt change anything. On the serial monitor I only get the message:
execute 1 ran
execute 3 ran
execute 1 ran
this continuous forvever

Have you tried pulseIn();

Read servo signal in to arduino, process as needed, writeMicroseconds(1000-2000) out

Read the ppm from the receiver, there you have all the channels in one.

or........ https://www.youtube.com/watch?v=PdBS_W5tc-0

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.