Enable and Disable interrupt pins takes much time


(Daniel kirubakaran) #1

Hello,
I am using 4 dig pins as interrupt using CHANGE mode

when i calculated the execution time of enabling and disabling all interrupt pins it gave me the following result

timer=micros();

  GPIO_REG(GPIO_RISE_IE) |= (( 1 << (digitalPinToInterrupt(2) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(3) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(8) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(17) - INT_GPIO_BASE)) );
  GPIO_REG(GPIO_FALL_IE) |= (( 1 << (digitalPinToInterrupt(2) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(3) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(8) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(17) - INT_GPIO_BASE)) );


 GPIO_REG(GPIO_RISE_IE) &= ~(( 1 << (digitalPinToInterrupt(2) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(3) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(8) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(17) - INT_GPIO_BASE)) );
 GPIO_REG(GPIO_FALL_IE) &= ~(( 1 << (digitalPinToInterrupt(2) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(3) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(8) - INT_GPIO_BASE)) | ( 1 << (digitalPinToInterrupt(17) - INT_GPIO_BASE)));

  Serial.println(micros() - timer);

O/P is

32631
32636
32639
32643
32649
32641
32626
32634
32634
32643
32642
32641
32646

(in micro seconds)
why does it take much time?
As these 4 pins are 4 channels of rc receiver.

I am facing timing issues due to that.


(Daniel kirubakaran) #2

This is my receiver(r6b) signal’s format.PWM

And here is my service routine

void ISR1() {
  current_time = micros();
  //Channel 1=========================================
  if (GPIO_REG(GPIO_INPUT_VAL) & pinmask2) {                                      //Is input 2 high?

    if (last_channel_1 == 0) {                                                    //Input 2 changed from 0 to 1

      last_channel_1 = 1;                                                          //Remember current input state
      timer_1 = current_time;                                                      //Set timer_1 to current_time

    }
    GPIO_REG(GPIO_RISE_IP) = pinmask2;
  }
  else if (last_channel_1 == 1) {                              //Input 2 is not high and changed from 1 to 0
    last_channel_1 = 0;                                        //Remember current input state
    receiver_input[1]  = current_time - timer_1;              //Channel 1 is current_time - timer_1

    GPIO_REG(GPIO_FALL_IP) = pinmask2;
  }


}
void ISR2() {

  current_time = micros();

  //Channel 2=========================================
  if (GPIO_REG(GPIO_INPUT_VAL) & pinmask3 ) {                                     //Is input 9 high?

    if (last_channel_2 == 0) {                                 //Input 3 changed from 0 to 1

      last_channel_2 = 1;                                      //Remember current input state
      timer_2 = current_time;                                  //Set timer_2 to current_time

    }
    GPIO_REG(GPIO_RISE_IP) = pinmask3;
  }
  else if (last_channel_2 == 1) {                              //Input 3 is not high and changed from 1 to 0
    last_channel_2 = 0;                                        //Remember current input state
    receiver_input[2] = current_time - timer_2;                //Channel 2 is current_time - timer_2
    
    GPIO_REG(GPIO_FALL_IP) = pinmask3;
  }



}
void ISR3() {

  current_time = micros();

  //Channel 3=========================================
  if (GPIO_REG(GPIO_INPUT_VAL) & pinmask8 ) {                                     //Is input 8 high?

    if (last_channel_3 == 0) {                                 //Input 8 changed from 0 to 1

      last_channel_3 = 1;                                      //Remember current input state
      timer_3 = current_time;                                  //Set timer_3 to current_time

    }
    GPIO_REG(GPIO_RISE_IP) = pinmask8;
  }
  else if (last_channel_3 == 1) {                              //Input 8 is not high and changed from 1 to 0
    last_channel_3 = 0;                                        //Remember current input state
    receiver_input[3] = current_time - timer_3;                //Channel 3 is current_time - timer_3
    
    GPIO_REG(GPIO_FALL_IP) = pinmask8 ;
  }


}
void ISR4() {

  current_time = micros();

  //Channel 4=========================================
  if (GPIO_REG(GPIO_INPUT_VAL) & pinmask17) {                  //Is input 17 high?

    if (last_channel_4 == 0) {                                 //Input 17 changed from 0 to 1
      last_channel_4 = 1;                                      //Remember current input state
      timer_4 = current_time;                                  //Set timer_4 to current_time

    }
    GPIO_REG(GPIO_RISE_IP) = pinmask17;
  }
  else if (last_channel_4 == 1) {                              //Input 17 is not high and changed from 1 to 0
    last_channel_4 = 0;                                        //Remember current input state
    receiver_input[4] = current_time - timer_4;                //Channel 4 is current_time - timer_4
    
    GPIO_REG(GPIO_FALL_IP) = pinmask17;
  }
  // Clear out the interrupt pending bit, or the interrupt will
  // just happen again as soon as we return,
  // and we'll never get back into our loop() function.
  // These are write-one-to-clear.

}

Kindly Correct me if i am wrong.