Different time of the interruption call

Buldakov
Posts: 5
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.

Code: Untitled.txt Select all


const    int      interruptPin = 27; // GPIO pin where the interrupt will be configured               //
bool start_gate=1; //
uint32_t tik_new,tik_old; //
uint64_t tik,tik_start; //
uint64_t time_new,time_old; //
uint64_t N_int; //
volatile uint64_t N=0,M=0; //
//----------------------------------------------------------------------------------------------------//
void IRAM_ATTR buttonTick() //
{ //
tik_new = esp_cpu_get_cycle_count(); //
tik = tik+tik_new-tik_old; //
if (tik_new<tik_old) tik=tik+4294967296; //
tik_old=tik_new; //
N_int=N_int+1; //
if (start_gate==1 ) {tik_start=tik;N_int=0;start_gate=0; } //
if ((tik-tik_start)>=240000000) {N=N_int;M=tik-tik_start;start_gate=1;} //
} //
//----------------------------------------------------------------------------------------------------//
void setup() //
{ //
Serial.begin(115200); //
pinMode(interruptPin, INPUT); // Configure the pin as an input with an internal pull-up resistor //
attachInterrupt(interruptPin, buttonTick, RISING); // Configure the interrup //
} //
//----------------------------------------------------------------------------------------------------//
void loop() //
{ //
time_new = esp_timer_get_time(); //
if ((time_new-time_old)>=1000000) //
{ //
Serial.print(" N= ");Serial.print(N);Serial.print(" M= ");Serial.println(M); //
time_old=time_new; //
} //
} //
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

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Different time of the interruption call

Postby 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: 5
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.

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Different time of the interruption call

Postby 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: 5
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?

Sprite
Espressif staff
Espressif staff
Posts: 10596
Joined: Thu Nov 26, 2015 4:08 am

Re: Different time of the interruption call

Postby Sprite » Thu Oct 03, 2024 1:37 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: Applebot, Semrush [Bot] and 1 guest