Pages: [1]   Go Down
Author Topic: Button (INT0) interrupt freezes interrupts for 1 sec... stop!  (Read 441 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.93 KB - downloaded 6 times.)
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11133
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
//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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

.. 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:

    sei(); //Resume interrupts


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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you change it to use attachInterrupt rather than:

Code:
ISR(INT0_vect){

Replace these lines:

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

by:

Code:
attachInterrupt (0, buttonPress, FALLING);

And replace:

Code:
ISR(INT0_vect){

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

}


by:

Code:
void buttonPress ()
  {
  show_the_time = TRUE;
  }


See if that does anything.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 28
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It didnt seem to work...
Logged

Pages: [1]   Go Up
Jump to: