[SOLVED] Dealing with a noisy interrupt signal

I have just now found time to look at this more closely. The stuff I was testing earlier was just not working properly - it was responding to electrical noise rather than optical changes. I think I have now got past that stage. But, at the moment the hardware I have is far from ideal. I may get a specialist reflective optical detector on Monday.

My initial thoughts on this subject are what @aarg mentioned

Doesn't letting the ISR handle the noise get a little CPU intensive?

I only need a RISING interrupt which should reduce the load (I think).

As far as I can see the code in Reply #33 works by ignoring interrupts during a pre-determined interval after the first interrupt - which is how I would debounce a switch if I was polling it. But the difference is that if I was using polling I just would not check the I/O pin during the interval.

My inclination with the interrupts is to switch off the interrupt after the first trigger and not re-instate it until the interval has elapsed (and clearing out any interrupts-in-waiting first). I think that could significantly reduce the load on the Arduino. But the part I have not figured yet is how to re-instate the interrupt if the interval is short. However for my application I should not be getting more than 250 useful interrupts per second - i.e. one every 4 millisecs so there should be plenty of time for the code in loop() to re-instate the interrupt.

I guess it would not be too difficult to arrange for the first interrupt to switch of future external interrupts on that pin and start a timer interrupt that would re-instate the external interrupt after the interval. That should take ALL the debounce load off the CPU.

One thing I have not seen mentioned in the discussion (apart from @aarg's comment) is the need to use a few CPU cycles as possible so the Arduino has time to other stuff. The best debounce system is useless if there is no time left to make use of the debounced input.

I probably won't get time to do any more with this today.

...R