How to use high priority interrupts

DDGGAADD
Posts: 3
Joined: Thu Aug 20, 2020 8:52 pm

How to use high priority interrupts

Postby DDGGAADD » Thu Sep 17, 2020 10:12 am

Hello,

I seek help to use high priority interrupts.

I use a digital output from a ESP32(Pin 19), to trigger interrupts on 2 other ESP32s(Pin 23).
wire Connection is like,
    ESP0:Pin 19 --> ESP1:Pin23
      ESP0:Pin 19 --> ESP2:Pin23

      This should mean that when ESP0 triggers a digital output, an interrupt is triggered on ESP1 and ESP2.
      I do this twice and mark the time difference between the 2 interrupt arrives on ESP1 and ESP2.
      I want this time to be the same on both ESP1 and ESP2 but in reality one of the ESP1(or ESP2) is always slower than the other by 2 to 10 micro seconds.

      Here is the code for ESP1 and ESP2 interrupt creation.

      Code: Select all

      static void  intr_create(void* pvParameter) {
      
        gpio_pad_select_gpio(GPIO_NUM_23);
        gpio_set_direction(GPIO_NUM_23, GPIO_MODE_INPUT);
        gpio_pullup_en(GPIO_NUM_23);
        gpio_pulldown_dis(GPIO_NUM_23);
      
        gpio_set_intr_type(GPIO_NUM_23, GPIO_INTR_POSEDGE);
        gpio_install_isr_service([b][i][u]ESP_INTR_FLAG_LEVEL3[/u][/i][/b]);
        gpio_isr_handler_add(GPIO_NUM_23, zero_i_isr, (void*) GPIO_NUM_23);
        gpio_intr_enable(GPIO_NUM_23);
        Serial.printf("Interrupt setup \n");
        vTaskDelete(NULL);
      
      
      }
      Here is the code for interrupt handling

      Code: Select all

      static void IRAM_ATTR zero_i_isr(void *arg) {
        BaseType_t xHigherPriorityTaskWoken;
        xHigherPriorityTaskWoken = pdFALSE;
        static int j = 0;
        j++;
        time_test[j] = micros();
        vTaskNotifyGiveFromISR(Calc_Time, &xHigherPriorityTaskWoken );
        portYIELD_FROM_ISR();
      }

      in Calc time task, I just print the time difference

      Code: Select all

       if (j == 2) {
      
          Serial.printf("Time between interrupts is %lu : %lu  : %lu\n", time_test[2] - time_test[1], time_test[1], time_test[2]);
          j = 0;
        }
      1. Why is there a time difference in interrupt handling between the two ESPs although they are receiving the interrupts at the same time?
      2. I have used ESP_INTR_FLAG_LEVEL3 while registering interrupt. If I try to use ESP_INTR_FLAG_LEVEL4 ESP_INTR_FLAG_LEVEL5 ESP_INTR_FLAG_LEVEL6 or ESP_INTR_FLAG_NMI , software crashes all the time. What should I do in order to use high prio interrupts like ESP_INTR_FLAG_NMI?
      3. Will using high prio interrupts solve the problem with the time delays that I am facing now?
      Attachments
      Interrupts_delays.jpg
      Interrupts_delays.jpg (34.9 KiB) Viewed 6909 times

      ESP_Sprite
      Posts: 9757
      Joined: Thu Nov 26, 2015 4:08 am

      Re: How to use high priority interrupts

      Postby ESP_Sprite » Thu Sep 17, 2020 1:10 pm

      Not sure what is causing the jitter... do you perhaps also have other things (WiFi, BT, ...) running on the receiving ESP32s? The reason that you're not having any success with high-level interrupts is that they must be written in assembly, you can't write them in C.

      DDGGAADD
      Posts: 3
      Joined: Thu Aug 20, 2020 8:52 pm

      Re: How to use high priority interrupts

      Postby DDGGAADD » Thu Sep 17, 2020 1:36 pm

      Thank you for the reply ESP_Sprite.

      Each device device is running ESP_NOW to communicate between each other(but this service is not used very often but maybe once every 5s or so).
      Each device also have two hardware timers(as below) running periodically at ~500 microseconds.
      • TIMERG0.hw_timer[1]
      • TIMERG0.hw_timer[0]
      I guess that these timers have higher priority that ESP_INTR_FLAG_LEVEL3 interrupts?

      Also what interrupts have higher priority than the Timer interrupts? Any one of the below maybe?
      • #define ESP_INTR_FLAG_LEVEL4 (1<<4)
      • #define ESP_INTR_FLAG_LEVEL5 (1<<5)
      • #define ESP_INTR_FLAG_LEVEL6 (1<<6)
      • #define ESP_INTR_FLAG_NMI (1<<7) ///< Accept a Level 7 interrupt vector (highest priority)
      • #define ESP_INTR_FLAG_IRAM (1<<10)


      finally, do you mean that interrupts listed above needs to be programmed in Assembly language? Are there any link you can give to documentation or for examples that shows us how to write such code for Xtensa processor?

      Thank you ,
      Regards,

      wjxway
      Posts: 15
      Joined: Wed Aug 05, 2020 2:52 am

      Re: How to use high priority interrupts

      Postby wjxway » Thu Oct 10, 2024 2:50 am

      Same problem, timer interrupt will fail to fire in time when ESP-NOW is active, any solutions?

      Who is online

      Users browsing this forum: No registered users and 49 guests