Go Down

Topic: Button (INT0) interrupt freezes interrupts for 1 sec... stop! (Read 565 times) previous topic - next topic


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


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.
I only provide help via the forum - please do not contact me for private consultancy.


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.

Nick Gammon

Code: [Select]
//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...

Code: [Select]

    sei(); //Resume interrupts

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

Go Up