Measuring time between PWM pulse and tick

Hi everyone,

I have an electronic speed controller that provides data through a fairly hard method.

Using my arduino mega I can send an inverted PWM pulse to the controller. However once the line goes back high (after the inverted pulse), a certain number of milliseconds later the controller pulls the line low for 1us. Currently my code (which is below) is too slow to register this change.

From my research it looks like the timer library might help or using direct port manipulation but I’m a newbie to both these things. Any help would be appreciated!!!

#define ESC 2 //the digital pin the esc signal line is attached to

int throttlePos = 0;

volatile unsigned long timer_start;
volatile int last_interrupt_time;
volatile int pulse_time;

void setup() {
  // put your setup code here, to run once:
  pinMode(ESC, OUTPUT); //originally set the ESC's line to output to keep line high ready for throttle armature
  digitalWrite(ESC, HIGH); //keep the pulse high due to inverted throttle pulse
  Serial.begin(115200); //opens the serial port for use when testing
  timer_start = 0; 
    attachInterrupt(digitalPinToInterrupt(ESC), calcSignal, FALLING);
  for(throttlePos = 0; throttlePos <= 1000; throttlePos += 1) //these for loops arm the ESC by emulating an inverted PWM pulse, process takes two seconds
  {
    digitalWrite(ESC, LOW);
    delayMicroseconds(1500);
    digitalWrite(ESC, HIGH);
    delayMicroseconds(100);
  }
  for(throttlePos = 1000; throttlePos <= 2000; throttlePos += 1)
  {
    digitalWrite(ESC, LOW);
    delayMicroseconds(1000);
    digitalWrite(ESC, HIGH);
    delayMicroseconds(100);
  }
}

void loop() {
  delay(19);
  digitalWrite(ESC, LOW);
  delayMicroseconds(1200);
  digitalWrite(ESC, HIGH);
  delayMicroseconds(100);
  Serial.println(pulse_time);
}
void calcSignal() 
{
    //record the interrupt time so that we can tell if the receiver has a signal from the transmitter 
    last_interrupt_time = micros(); 
    //if the pin has gone HIGH, record the microseconds since the Arduino started up 
    if(digitalRead(ESC) == HIGH) 
    { 
        timer_start = micros();
    } 
    //otherwise, the pin has gone LOW 
    else
    { 
        //only worry about this if the timer has actually started
        if(timer_start != 0)
        { 
            //record the pulse time
            pulse_time = ((volatile int)micros() - timer_start);
            //restart the timer
            timer_start = 0;
        }
    } 
}

From my research it looks like the timer library might help or using direct port manipulation but I'm a newbie to both these things.

If you need to catch a short pulse, an interrupt is the only way.