Falling interrupt issue

Hi,
I have attached the sketch I wrote for my project. The project involves a pulse, skin conductance and temperature sensor. The data obtained from these sensors are then logged to an SD card. When a button is pressed, the logging starts and stops when the same button is pushed again. When it is pressed one more time, data logging begins in a new file. But after a few button presses, the arduino stops responding to the interrupts. I have added an indicator led to check if the ISR was being executed and the state of the led does not change after a few key presses plus the led on the breakout board too does not flash( which flashes during R/W ops). Please help. I am using both interrupt0 and 1 plus the ISR of INT0 triggers the Timer1 to execute a function every 2 ms. I also want to know whether once the ISR of INT0 is interrupted by INT1, does the execution resume at the point where the ISR of int0 was left off when the processor is done with ISR of INT1??

sensor_project.ino (8.71 KB)

void loop()
{
  data.close();
  delay(20);                             //  take a break
}

Huh? The main loop just closes the data file constantly. Why? What if it is doing something?

void interruptSetup()
{
  digitalWrite(red,digitalRead(red)^1);
  data.close();
  check=check^1;
  if(check==1)
  {
    open_file();

I wouldn’t be opening a file in an ISR personally. File opening probably requires interrupts and they will be off.

http://www.gammon.com.au/interrupts

void pulse()
{  

  Timer1.detachInterrupt();  // disable interrupts while we do this
  Signal = analogRead(pulsePin);              // read the Pulse Sensor 

...

      double time=lastBeatTime;
      String x= doubleToString(time/1000,2) + "," + temperature() + "," + conductance() + "," + s_b;
      s_b=" ";

I also wouldn’t be using the String class inside an ISR. It probably is not interrupt safe.

I don’t see why you need interrupts at all, just to detect a button press. That’s what the main loop is for.

I also want to know whether once the ISR of INT0 is interrupted by INT1, does the execution resume at the point where the ISR of int0 was left off when the processor is done with ISR of INT1??

ISR routines are not themselves interrupt-able. Not unless you turn interrupts on inside, which I strongly suggest you do not do.

I suggest reworking the whole thing without interrupts.

Repeating theme: Generating interrupts from pushbuttons (or any mechanical contact) - very, very bad idea indeed.

It's a phenomenon called contact bounce - the contact is made not once, but perhaps dozens of times, causing multiple interrupts, possibly even during the execution of the interrupt routine.

Compared to the execution of processor instructions and even such things as opening files, user actuation of a button (or indeed, mouse click/ touch etc.) is a very slow process and a very low priority - the very opposite of what an interrupt is used or needed for.

I have used schmitt trigger to debounce the switch.

You mean a Schmitt trigger, capacitor and two resistors, don’t you?

Point is - why would you use it to trigger an interrupt?