Button (INT0) interrupt freezes interrupts for 1 sec... stop!

I am currently writing code for a watch project using asynchronous timing between an external 32.768kHz crystal and the internal timer on an arduino. So far, I have gotten it working and am in the midst of debugging code… working in finalizing it.

basically, this is a modified BigTime watch (sold at sparkfun)

The 32.768kHz crystal is interrupting the arduino once every second, which updates timer variables. These are then used to set the time
On pin 8, I have an LED to see if the interrupt is being called. It flashes on and off every second, as it should. Except when I press the button (interrupts on INT0 to show the time), the LED fails to “tick” for a second, then this causes the timing to be off by a few seconds… I need to eliminate this stutter.

Here is my code

BinaTime6.ino (26.9 KB)

Except when I press the button (interrupts on INT0 to show the time)

If you use interrupts to be notified of the passage of time, then also using interrupts to do slow things like updating displays is probably a mistake. Especially if you have the interrupt configured to fire the interrupt handler repeatedly while the input remains active. I suggest you replace your button handling code with something that simply reads the state of the input at regular intervals.

But do interrupts based off an external crystal run continuously with the program? I can set it so that it is always on, and the clock runs fine, but I can press the button and the ext clock doesnt pause.

//This routine occurs when you hold the button down
//Holding the button down will increase the time (accelerates)
//Releasing the button for more than 2 seconds will exit this mode
void setTime(void) {

    cli(); //We don't want the interrupt changing values at the same time we are!

You've turned interrupts off, so the time won't update.

.. and then resume them. Anyways that function isnt supposed to be even called just by pressing the button, you need to hold the button...

    sei(); //Resume interrupts

its worth a shot to take that out to see if its getting called. Will get back to you

Can you change it to use attachInterrupt rather than:


Replace these lines:

  //Setup external INT0 interrupt
  EICRA = (1<<ISC01); //Interrupt on falling edge
  EIMSK = (1<<INT0); //Enable INT0 interrupt


attachInterrupt (0, buttonPress, FALLING);

And replace:


  //When you hit the button, we will need to display the time
  //if(show_the_time == FALSE) 
  show_the_time = TRUE;



void buttonPress ()
  show_the_time = TRUE;

See if that does anything.

It didnt seem to work...