PWM Input From RC Receiver - Erroneous Values

Output of Recorded Receiver Input
1:THR,    2:AIL,    3:ELE,    4:RUD,    5:AUX1,   6:AUX2
--------------------------------------------------------
1:988,   2:1472,   3:2257961564,   4:1484,   5:1500,   6:1500
1:2258966912,   2:2258966920,   3:2258968424,   4:2258969236,   5:1500,   6:1500
1:988,   2:1472,   3:2259976888,   4:1480,   5:1500,   6:1500
1:988,   2:1476,   3:2260984556,   4:2260986040,   5:1500,   6:1500
1:992,   2:1472,   3:2261974224,   4:1480,   5:1500,   6:1500
1:992,   2:1476,   3:2262981884,   4:2262983372,   5:1500,   6:1500
1:988,   2:1472,   3:2263989548,   4:2263991032,   5:1500,   6:1500
1:992,   2:1476,   3:2264997208,   4:2264998696,   5:1500,   6:1500
1:988,   2:1476,   3:2266004868,   4:2266006356,   5:1500,   6:1500
1:2267010212,   2:2267010224,   3:2266994540,   4:2266996028,   5:1500,   6:1500
1:988,   2:1476,   3:2268020196,   4:2268021684,   5:1500,   6:1500
1:992,   2:1476,   3:2269027860,   4:2269029348,   5:1500,   6:1500
1:988,   2:1472,   3:2270035524,   4:2270037012,   5:1500,   6:1500
1:988,   2:2271040876,   3:2271025192,   4:2271026680,   5:1500,   6:1500
1:988,   2:1476,   3:2272050848,   4:2272052336,   5:1500,   6:1500
1:992,   2:1476,   3:2273040516,   4:2273042004,   5:1500,   6:1500
1:988,   2:1472,   3:2274048180,   4:2274049668,   5:1500,   6:1500
1:988,   2:1472,   3:2275055844,   4:2275057332,   5:1500,   6:1500
1:988,   2:1468,   3:2276063508,   4:2276064992,   5:1500,   6:1500
1:988,   2:1472,   3:2277071164,   4:1484,   5:1500,   6:1500
1:988,   2:1476,   3:2278060828,   4:1480,   5:1500,   6:1500

I am using the GreyGnome/EnableInterrupt Library:

GitHub - GreyGnome/EnableInterrupt: New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due.

In my comments, I reference the servos library and eRCaGuy_Timer2_Counter :

http://www.electricrcaircraftguy.com/2014/02/Timer2Counter-more-precise-Arduino-micros-function.html Do I need to bother?

Due to this message being greater than 9000 characters, my sketch will be put in another post. Any and all help will be greatly appreciated. Thanks in advance.

Here is my sketch:

#include <EnableInterrupt.h>

// DECLARATIONS
PROGMEM const byte rxPins[6]={  //Assign to an Pins to an Array
  2,    // 0. Digital Input Pin 2 - Throttle
  3,    // 1. Digital Input Pin 3 - Aileron
  4,    // 2. Digital Input Pin 4 - Elevator
  5,    // 3. Digital Input Pin 5 - Rudder
  6,    // 4. Digital Input Pin 6 - Aux 1 - Mode Switch
  7};   // 5. Digital Input Pin 7 - Aux 2 - Reserved

// INTERRUPTS
volatile unsigned long rxPuls[6]={ // Temporarily Holds Micros() on Interrupt RISING or Saves Puls Length on Interrupt FALLING 
  1000,1500,1500,1500,1500,1500};
volatile unsigned long rxLastPuls[6]={  // Holds the Last PWM Puls Value to compare to new Puls Length.  This will eleminate eronious values being saved.
  1000,1500,1500,1500,1500,1500};  

void rxThrHigh(){
  rxPuls[0]=micros();
  enableInterrupt(rxPins[0],rxThrLow,FALLING);
}
void rxThrLow(){
  rxPuls[0]=micros()-rxPuls[0];
  if (rxPuls[0] < 988 || rxPuls[0] > 2012) {rxPuls[0] = rxLastPuls[0];}
  else {rxLastPuls[0] = rxPuls[0];}
  enableInterrupt(rxPins[0],rxThrHigh,RISING);  
}
void rxAilHigh(){
  rxPuls[1]=micros();
  enableInterrupt(rxPins[1],rxAilLow,FALLING);
}
void rxAilLow(){
  rxPuls[1]=micros()-rxPuls[1];
  if (rxPuls[1] < 988 || rxPuls[1] > 2012) {rxPuls[1] = rxLastPuls[1];}
  else {rxLastPuls[1] = rxPuls[1];}  
  enableInterrupt(rxPins[1],rxAilHigh,RISING);  
}
void rxEleHigh(){
  rxPuls[2]=micros();
  enableInterrupt(rxPins[2],rxEleLow,FALLING);
}
void rxEleLow(){
  rxPuls[2]=micros()-rxPuls[2];
  if (rxPuls[2] < 988 || rxPuls[2] > 2012) {rxPuls[2] = rxLastPuls[2];}
  else {rxLastPuls[2] = rxPuls[2];}  
  enableInterrupt(rxPins[2],rxEleHigh,RISING);   
}
void rxRudHigh(){
  rxPuls[3]=micros();
  enableInterrupt(rxPins[3],rxRudLow,FALLING);
}
void rxRudLow(){
  rxPuls[3]=micros()-rxPuls[3];
  if (rxPuls[3] < 988 || rxPuls[3] > 2012) {rxPuls[3] = rxLastPuls[3];}
  else {rxLastPuls[3] = rxPuls[3];}  
  enableInterrupt(rxPins[3],rxRudHigh,RISING);  
}
void rxAux1High(){
  rxPuls[4]=micros();
  enableInterrupt(rxPins[4],rxAux1Low,FALLING);
}
void rxAux1Low(){
  rxPuls[4]=micros()-rxPuls[4];  
  if (rxPuls[4] < 988 || rxPuls[4] > 2012) {rxPuls[4] = rxLastPuls[4];}
  else {rxLastPuls[4] = rxPuls[4];}   
  enableInterrupt(rxPins[4],rxAux1High,RISING);  
}
void rxAux2High(){
  noInterrupts();  
  rxPuls[5]=micros();
  enableInterrupt(rxPins[5],rxAux2Low,FALLING);
}
void rxAux2Low(){
  rxPuls[5]=micros()-rxPuls[5]; 
  if (rxPuls[5] < 988 || rxPuls[5] > 2012) {rxPuls[5] = rxLastPuls[5];}
  else {rxLastPuls[5] = rxPuls[5];}
  enableInterrupt(rxPins[5],rxAux2High,RISING);   
}

// SETUP
void setup(){
  for(byte i=0;i<6;i++){
    pinMode(rxPins[i],INPUT); 
    digitalWrite(rxPins[i],HIGH); // Is this needed?
    }
  enableInterrupt(rxPins[2],rxThrHigh,RISING);
  enableInterrupt(rxPins[3],rxAilHigh,RISING);
  enableInterrupt(rxPins[4],rxEleHigh,RISING);
  enableInterrupt(rxPins[5],rxRudHigh,RISING);
  enableInterrupt(rxPins[6],rxAux1High,RISING);
  enableInterrupt(rxPins[7],rxAux2High,RISING);

  //Display the results
  Serial.begin(9600);
  Serial.println(""); //insert a space
  Serial.println("Output of Recorded Receiver Input");
  Serial.println("1:THR,    2:AIL,    3:ELE,    4:RUD,    5:AUX1,   6:AUX2");
  Serial.println("--------------------------------------------------------");
}

// LOOP
void loop() {
  for(byte i=0;i<5;i++){
    Serial.print(i+1);
    Serial.print(":");
    Serial.print(rxPuls[i]);
    Serial.print(",   ");
    }
  Serial.print("6:");  
  Serial.println(rxPuls[5]);
  delay(1000);
}

I found one of my errors but I'm still getting random erroneous values. The below changes fixed it so the Arduino is now reading Aux1 and Aux2.

I changed this:

  enableInterrupt(rxPins[2],rxThrHigh,RISING);
  enableInterrupt(rxPins[3],rxAilHigh,RISING);
  enableInterrupt(rxPins[4],rxEleHigh,RISING);
  enableInterrupt(rxPins[5],rxRudHigh,RISING);
  enableInterrupt(rxPins[6],rxAux1High,RISING);
  enableInterrupt(rxPins[5],rxAux2High,RISING);

to this:

  enableInterrupt(rxPins[0],rxThrHigh,RISING);
  enableInterrupt(rxPins[1],rxAilHigh,RISING);
  enableInterrupt(rxPins[2],rxEleHigh,RISING);
  enableInterrupt(rxPins[3],rxRudHigh,RISING);
  enableInterrupt(rxPins[4],rxAux1High,RISING);
  enableInterrupt(rxPins[5],rxAux2High,RISING);

Leave pins 0 and 1 alone since you are using them as serial.

justone:
Leave pins 0 and 1 alone since you are using them as serial.

Thanks for your help. Pins 0 and 1 are unused.

You'll have to use the Servo library for the servos, with any pins. The servo signals are created in software, while PWM signals can be created by hardware and then are restricted to specific pins.

DrDiettrich:
You'll have to use the Servo library for the servos, with any pins. The servo signals are created in software, while PWM signals can be created by hardware and then are restricted to specific pins.

OK... Good... Then I CAN use any pin for PWM output with the servos library. I thought I read somewhere that certain pins are restricted.

But before I tackle the servo output, I need to figure out what is causing the erroneous LARGE values.

Can an interrupt interrupt another interrupt?

I believe I’ve found what was causing the erroneous values. I changed this:

void rxThrHigh(){
rxtPuls[0]=micros();
enableInterrupt(rxPins[0],rxThrLow,FALLING);
}
void rxThrLow(){
rxPuls[0]=micros()-rxPuls[0];
if (rxPuls[0] < 988 || rxPuls[0] > 2012) {rxPuls[0] = rxLastPuls[0];}
else {rxLastPuls[0] = rxPuls[0];}
enableInterrupt(rxPins[0],rxThrHigh,RISING);
}

to this:

void rxThrHigh(){
rxStartPuls[0]=micros();
enableInterrupt(rxPins[0],rxThrLow,FALLING);
}
void rxThrLow(){
rxPuls[0]=micros()-rxStartPuls[0];
if (rxPuls[0] < 988 || rxPuls[0] > 2012) {rxPuls[0] = rxLastPuls[0];}
else {rxLastPuls[0] = rxPuls[0];}
enableInterrupt(rxPins[0],rxThrHigh,RISING);
}

and added the rsStartPuls array in the declarations.