12 interrupts issues

I am trying to decipher 4 telemetry signals from 4 ESCs. Here is the protocol in question:

I have 2 pwm signals coming into the Arduino 101 (all pins interruptable), 1 is a non-inverted PWM signal, and the other is the inverted PWM signal with telemetry data embedded as per the protocol above.

Additionally I am reading in rpm via a sensor wire tap that results in 2 square waves per revolution.

I have done this successfully with 1 signal using this code:

//12 is aux
//2 is pmw standard
//9 is inverted pwm
//3 is rpm
void pwmend() {
  //Serial.print("pwmtrig");
  timestart=micros();
  data=TRUE; 
}
void trig(){
   //Serial.print("datatrig");
   if (data==TRUE){
      timeend=micros();
      updateready=TRUE;
      tickval=timeend-timestart;
      data=FALSE;

   }
  
}
void spin(){
  current=micros();
  t=current-past;
  past=current;
}

void setup() {
  Serial.begin(9600);
  pinMode(inpin1, INPUT);
  pinMode(outpin1, INPUT);
   pinMode(3, INPUT);
  attachInterrupt(3, spin, FALLING);
  attachInterrupt(outpin1, pwmend, FALLING);
  attachInterrupt(inpin1,trig,FALLING);
  timestamp=micros();
  past=micros();
  t=0;
}

void loop() {
filled=FALSE;
if (updateready==TRUE){
  updateready=FALSE;
  
  
  if(tickval>5090){
    count=0;
  }
  if(count != -1){
    telem[count]=tickval;
    if (count==11){
      filled=TRUE;
      count=-1;
    }
    else{
      count++;
    }
  }
}
  if (filled==TRUE){
    
    for (int i=0; i<12;i++){

      if (i==1){
        cal1=1000-telem[i];
        item=cal1;
      }
      else if (i==11){
        cal2=500-telem[i];
        item=cal2;
      }
      else if ((i>=3) && (i<=10)){
        item= (((double)telem[i]-500+cal1)/1000)*scale[i];
        Serial.print(item);
        Serial.print(",");
      }
    }
    rpm= 1000/((t*2/1000))*60;
    Serial.print(rpm);
    Serial.print(",");
    
    tstamp= (micros()-timestamp)/1000;
    Serial.println(tstamp);
  }
  
//
  
}

First it searches for the end of the non-inverted pwm signal to indicate the time to search for telemetry, then if data==true the signal gets detected and it’s timing stored, which fills an array which is outputted. The rpm sensor wire works similarly.

My issue arises when trying to integrate this code for 4 motors+ESCs.

This is what I have currently, lots of copy paste and variable renaming but otherwise pretty similar.
Biggest difference is in the way the rpm sensor signal is handled, I was unsure if analog pins used digitally would be slow so I have been attaching and detaching interrupts on those pins when the rpm data is necessary.

Code attached as file for character limit.

In testing, I was able to get relatively reasonable data but only from motor 4. During these tests all 4 ESCs where receiving the same pwm signal and supposedly sending back the same data.

It is my understanding that if more than two interrupts occur at the same time then they will not be handled properly.

How can I read the data from all 4 signals? I could really use some help with interrupts or advice on alternate approaches to this issue.

Thanks so much!

_4motorread.ino (5.91 KB)

It is my understanding that if more than two interrupts occur at the same time then they will not be handled properly.

That should say two or more interrupts. When one interrupt is being processed, other interrupts are queued. A queue can hold ONE interrupt.

int pwmout1,pwmout2,pwmout3,pwmout4;
int pwmin1,pwmin2,pwmin3,pwmin4;

int aux1,aux2,aux3,aux4;

volatile unsigned long timestart1,timestart2,timestart3,timestart4,timeend;
volatile unsigned long tickval1,tickval2,tickval3,tickval4;
volatile unsigned long past1, current1, past2, current2 ,past3 ,current3, past4, current4;

Before trying to learn about interrupts, you need to learn about something much simpler - arrays.

    while(t==0){
      delay(10);
    }

Why do you care how many times the while loop iterates? The delay() is dumb.

// Comments are a good thing

Why don't you have any?