How can i find interrupt execution time

I need to find interrupt execution time. But if the interrupt pin is low the program still continues. I want to stop the for loop if the interrupts end.
//#include <elapsedMillis.h>
//
//#include <timer-api.h>
//#include <timer_setup.h>

int ledPin = 13;
boolean led_durumu = LOW;
int input_pin =2;
int read_value;
void setup(){
Serial.begin(9600);
pinMode(ledPin,OUTPUT);

cli();

attachInterrupt(0, for_say, HIGH);
sei();

pinMode(input_pin, INPUT);
}

void loop(){
delay(1000);

}
void for_say()
{

unsigned long a=micros();

Serial.print(“time 1=”);
Serial.println(a);
while(read_value==HIGH){
for(int i=0;i<1000;i++)
{

Serial.print(“i=”);
Serial.println(i);
}
}
unsigned long b=micros();
Serial.print(“time 2=”);
Serial.println(b);
}

I think you are going about this all wrong.

You should not have any print statement in your Interrupt Service Routine (ISR) {a} because printing needs interrupts which are off inside an ISR and {b{ because printing is slow and an ISR should complete as quickly as possible - 100 microsecs would be a long time.

Your ISR should set a flag variable that can be detected by the code in loop() - something like this

void for_say() {
   isrTriggered = true;
}

and then the code in loop() can check that something like this

if (isrTriggered == true) {
   // do stuff
   isrTriggered = false;
}

The next question is what is the purpose of the program? Maybe there is no need to use any interrupt?

...R

The program's purpose is when an interrupt occurs, counter starts and whenever interrupts ends counter stops, even if for loop end too big number. Ex: pin 2(interrupts pin enable that I mean interrupt start) for loop start;1,2,3,4,...... and stop interrupt for must be stopped before the end of the loop. And I measure how long it takes to interrupt time duration.

You are describing what you think the solution is rather than what you are actually trying to do

For instance, what is the purpose of the for loop in the ISR ?

The aim is not a loop. There will be a function instead of a loop. And at the and of interrupt the function must be ended.

I assume that you realise that the system will remain in the ISR until it returns to the place from where it was called. The same thing goes if you call another function from within the ISR. Until that function ends the ISR will not end.

What does this other function do and how long does it take to run ?

What do you mean by "the and of interrupt" ? Do you mean at the end of the ISR or do you mean when the signal that caused the ISR is removed ?

I mean when the signal that caused the ISR is removed.

If you are interested in timing how long a pin was held high and it's brief enough that you need to use an interrupt to do it, use CHANGE, not HIGH. When the interrupt fires, check whether the pin is high or low. Depending on which it is, store micros in one of two variables.

In loop, print the difference between the two micros variables.

How do I don't think yes CHANGE :). Thanks a lot

…or use timer’s input capture hardware to timestamp the pulse’s transitions, and find the difference of the two timestamps.

ibrahimcicek17: The program's purpose is when an interrupt occurs,

That is a low level or internal view of the proposed program.

What we need to know is what is the real world purpose of the program - for example do you want to open the door of a chicken coop or perhaps control the speed of a motor.

...R