Interrupts not functioning properly


We are working with an Arduino Duemilanove, and have run into a frustrating problem. Pins 2 and 3 have been configured for a rising voltage interrupt, and read the rising voltage fine at first. However, 2-3 seconds after reading the rising voltage, the values that are set by the interrupt are reset suddenly, as though the button were pressed a second time. However, if we put a Serial.println in the interrupt block, then there are no problems. But if we have another Serial.println in the loop, then we start having the problems again.

We then tried changing the interrupt pins to look for a falling voltage, which stopped the values from changing on their own, but now there is a delay between when the voltage is sent and when the board "sees" the falling voltage, again of about 2-3 seconds. Also, now the differently placed Serial.println commands have no effect on the board's operation.

It seems to us as though the board is seeing a rising voltage for much longer than the voltage is actually being applied to the interrupt pin. Perhaps this is the wrong forum for this, but has anyone experienced a similar problem? Is that even what's actually wrong? What can we do about this? Our code is very simple so we're mildly certain it's not the problem - and is pasted in its entirety below. Any help on this matter would be appreciated!

int bCheck = 0; int previousBuzz = 0; int startPin = 2; int stopPin = 3; volatile boolean onCheck = false; int buzzerPins[5] = {5, 6, 9, 10, 11}; int ledPins[5] = {4, 7, 8, 12, 13};

// Debounce variables unsigned long lastDebounceTime = 0; unsigned long currentTime = 0; unsigned long debounceDelay = 1000;

void setup() { Serial.begin(9600); // set pin modes for LED output

pinMode(4, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(12, OUTPUT); pinMode(13, OUTPUT);

// set pin modes for PWM output pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT);

pinMode(startPin, INPUT); pinMode(stopPin, INPUT);

// analog input on unconnected analog pin 0, fairly random seed randomSeed(analogRead(0));

// start button interrupt on pin 11 attachInterrupt(0, startPress, RISING);

// stop button interrupt on pin 13 attachInterrupt(1, stopPress, RISING); }

void loop() {


currentTime = millis(); // previous off, new random output on, gated by debounce delay and onCheck if ( ((currentTime - lastDebounceTime) > debounceDelay) && (onCheck == true)) {

// turn off previous buzzer analogWrite(buzzerPins[previousBuzz], 0); digitalWrite(ledPins[previousBuzz], LOW);

previousBuzz = random(5); // choose new buzzerbreak when it is different from the last one while (previousBuzz == bCheck) { previousBuzz = random(5); } bCheck = previousBuzz;

// turn on new buzzer pin analogWrite(buzzerPins[previousBuzz], 130); // turn on new LED digitalWrite(ledPins[previousBuzz], HIGH); onCheck = false; } }

void startPress() { onCheck = true; lastDebounceTime = millis(); }

void stopPress() { analogWrite(buzzerPins[previousBuzz], 0); digitalWrite(ledPins[previousBuzz], LOW); onCheck = false; }

Please use the code tags with the # button to make the post more readable .

for (int pin=4; pin <=13; pin++) pinMode(pin, OUTPUT)

// start button interrupt on pin 11
attachInterrupt(0, startPress, RISING);

// stop button interrupt on pin 13
attachInterrupt(1, stopPress, RISING);

COde and comments conflict: IRQ 0 is allways pin 2 IRQ 1 is allways pin 3
keeping comments right prevents misunderstandings

How did you attach the switches to pin 2 and 3, if they are not connected is there a pulldown resistor? NOte if they fluctuate you get a lot of IRQ’s. This is easy to check by addin a counter in every IRQ and show them over serial.