Different time of the interruption call

Buldakov
Posts: 3
Joined: Wed Oct 02, 2024 2:46 pm

Different time of the interruption call

Postby Buldakov » Thu Oct 03, 2024 4:01 am

Hi.
I am sending a stable signal with a frequency of 10000 Hz from a quartz oscillator. The variable M must be stable and in the range from M=240013970 - 240013971.But the variable M varies over a larger range. I think other interrupts may have a higher priority and calling my interrupt is waiting for the other interrupts to end. Please help me.
  1. const    int      interruptPin = 27; // GPIO pin where the interrupt will be configured               //
  2.          bool     start_gate=1;                                                                       //
  3.          uint32_t tik_new,tik_old;                                                                    //
  4.          uint64_t tik,tik_start;                                                                      //
  5.          uint64_t time_new,time_old;                                                                  //
  6.          uint64_t N_int;                                                                              //
  7. volatile uint64_t N=0,M=0;                                                                            //
  8. //----------------------------------------------------------------------------------------------------//
  9. void IRAM_ATTR buttonTick()                                                                           //
  10. {                                                                                                     //
  11.    tik_new = esp_cpu_get_cycle_count();                                                               //
  12.    tik     = tik+tik_new-tik_old;                                                                     //
  13.    if (tik_new<tik_old) tik=tik+4294967296;                                                           //
  14.    tik_old=tik_new;                                                                                   //
  15.    N_int=N_int+1;                                                                                     //
  16.    if (start_gate==1            )  {tik_start=tik;N_int=0;start_gate=0;  }                            //
  17.    if ((tik-tik_start)>=240000000) {N=N_int;M=tik-tik_start;start_gate=1;}                            //
  18. }                                                                                                     //
  19. //----------------------------------------------------------------------------------------------------//
  20. void setup()                                                                                          //
  21. {                                                                                                     //
  22.   Serial.begin(115200);                                                                               //
  23.   pinMode(interruptPin, INPUT); // Configure the pin as an input with an internal pull-up resistor    //
  24.   attachInterrupt(interruptPin, buttonTick, RISING); // Configure the interrup                        //
  25. }                                                                                                     //
  26. //----------------------------------------------------------------------------------------------------//
  27. void loop()                                                                                           //
  28. {                                                                                                     //
  29.   time_new = esp_timer_get_time();                                                                    //
  30.   if ((time_new-time_old)>=1000000)                                                                   //
  31.   {                                                                                                   //
  32.    Serial.print(" N= ");Serial.print(N);Serial.print(" M= ");Serial.println(M);                       //
  33.    time_old=time_new;                                                                                 //
  34.   }                                                                                                   //
  35. }                                                                                                     //
N= 10001 M= 240013929
N= 10001 M= 240013875
N= 10001 M= 240013848
N= 10001 M= 240014067
N= 10001 M= 240014070
N= 10001 M= 240014229
N= 10001 M= 240014145
N= 10001 M= 240013806
N= 10001 M= 240013839
N= 10001 M= 240014007
N= 10001 M= 240013806
N= 10001 M= 240014157

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

Re: Different time of the interruption call

Postby ESP_Sprite » Thu Oct 03, 2024 7:42 am

Either that, or cache hits/misses, or writes to the AHB bus that take a few cycles, or...

Suggest you use a peripheral (RMT or MCPWM, for example) if you need to measure the time precisely.

Buldakov
Posts: 3
Joined: Wed Oct 02, 2024 2:46 pm

Re: Different time of the interruption call

Postby Buldakov » Thu Oct 03, 2024 8:29 am

I didn't understand what I needed to do "Suggest you use a peripheral (RMT or MCPWM, for example) if you need to measure the time precisely"?
There is an assumption that the interrupt on pin 27 has a low interrupt priority. And if another interrupt has a higher priority, then the interrupt with a higher priority is executed first, and the interrupt on pin 27 waits for the end of this high-level interrupt.
Question:
1.How do I set a higher interrupt level for the interrupt on pin 27?
2. Is it possible to disable other high-level interrupts and leave the interrupt only on pin 27?
Please provide an example from the help file or correct this code. Or give a link to a similar example.

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

Re: Different time of the interruption call

Postby ESP_Sprite » Thu Oct 03, 2024 9:57 am

I'm saying that trying to get jitterless interrupt is a fools errand: aside from higher-level interrupts, there's a fair few other things that will affect timing, and you cannot influence those as they are fundamental to the system. Instead, use a peripheral (which is not affected by interrupt jitter) to take the measurements you need.

Buldakov
Posts: 3
Joined: Wed Oct 02, 2024 2:46 pm

Re: Different time of the interruption call

Postby Buldakov » Thu Oct 03, 2024 12:18 pm

And if you use not pin 27 to call an interrupt, but another pin that has a higher priority?
Which pin input can have a higher priority?

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

Re: Different time of the interruption call

Postby ESP_Sprite » Thu Oct 03, 2024 1:37 pm

Buldakov wrote:
Thu Oct 03, 2024 12:18 pm
And if you use not pin 27 to call an interrupt, but another pin that has a higher priority?
Which pin input can have a higher priority?
Please read what I wrote. Even if you were able to manage to snag a higher priority interrupt (which is independent from the GPIO you use, by the way) you would not solve the issue.

Who is online

Users browsing this forum: No registered users and 51 guests