can anyone help me how to find the delay between the two interrupt execution. I want to display a time between two interrupts int0 and int1. Which is important for my project
Save the millis() for each interrupt then take the difference.
Define two variables as global would be easiest way. On entry into ISR1 save the first time then repeat with second in ISR2.
Weedpharma
Thanks weedpharma, i will try with this.
Subbu
unsigned long time;
unsigned long time1;
void setup()
{
// pinMode(A0,INPUT);
// pinMode(A1,INPUT);
// pinMode(INTERRUPT_PIN, INPUT);
attachInterrupt(0, blink, LOW);
attachInterrupt(1, blink1, LOW);
Serial.begin(9600);
}
void loop()
{
}
void blink()
{
// int y;
// if((y=analogRead(A0))>=50)
// {
Serial.print("Time: ");
time = micros();
//prints time since program started
Serial.println(time);
// // wait a second so as not to send massive amounts of data
// delay(1000);
// }
//
}
void blink1()
{
// int z;
// if((z=analogRead(A1))>=50)
// {
Serial.print("Time1: ");
time1 = micros();
//prints time since program started
Serial.println(time1);
// // wait a second so as not to send massive amounts of data
// delay(1000);
// }
}
this code is not showing the delay between two interrupts when i given i/p to int i changed to millis also.Please help me
In your ISRs you appear to be trying to print two values derived from millis(), not the difference between them. To compound the problem you are using Serial.print() in the ISRs. Serial.print() uses interrupts and they are automatically disabled within an ISR so that will not work.
What to do ?
In each ISR just get the time from millis() or micros() into unsigned long global variables that have been declared as volatile and print the difference between then in loop(). If you only want to print the difference once per interrupt then set a flag variable after you print, don't print when it is set and unset it when you get the second interrupt.
/interrupt occurs for low when reset button is pressed/
unsigned long time;
unsigned long time1;
volatile unsigned long diff;
void setup()
{
attachInterrupt(0, blink, LOW);
attachInterrupt(1, blink1, LOW);
Serial.begin(9600);
}
void loop()
{
int flag=0;
if(flag==0)
{
diff=(time-time1);
Serial.println(diff);
flag=1;
}
}
void blink()
{
time = millis();
}
void blink1()
{
time1 = millis();
}
Even though it is not working if i use milli it shows 0,if i use micro it shows 175,even if there is no i/p for interrupt it shows results
Please start using code tags!
But uhm, some comments.
time and time1 need to be volatile. diff does not because it's not acces in the interrupt.
What do you think will set the flag? Isn't it the interrupt that should flag the normal program?
Also I would suggest better function and variable names. More like startISR(), stopISR(), startTime, StopTime, timeDifference and timePassedFlag. More clear what they do.
Hi septillion even though it is not working i changed the code.
You changed it to what? What's not working? What does it do instead?
It's all a bit cryptic. What do you want from us?
I want a delay between two interrupt.How much time it takes to trigger an interrupt0 and 1.
Thank you
If you just gather all the hints we gave you, you should end up with a working program But if you just ignore them then you don't...
For goodness sake post your code as it is now and describe what it does when you run it.
int flag=0;
if(flag==0)
What are the chances that the if test will fail? It's stupid testing a condition that you have FORCED to be true.