Interrupt Smoothing without Delays()

Hey Guys

I have a project that receives Pulses and then triggers interrupts. It works pretty well accept for the fact that the pulses really need to be solid otherwise the signal is a little wavy and also counts as way more then one.So it seems at least. I need a little "Delay" type function using the milli() function to just stop it from Interrupting/ReInterrupting more then once every 2 seconds.

If there is anyway to do this please let me know. Thanks guys

You can certainly create a 'dead zone' during which whatever you're doing is not triggered, based on checking the millis() timer for an elapsed time as an example.

Can you share your code so a more concrete suggestion is possible?

Cheers ! Geoff

Look at debouncing!. If the signal is only once every one or two seconds you should be polling not using interrupts.


pseudo code

volatile unsigned long lastTime =0;
void ISR()
  if (millis() - lastTime < 1000) return; // ignore events faster than 1 second
  lastTime = millis();

  // do the real interrup thing here

Ok but pooling doesnt seem to work IF Pooling refers toe the MCU trying to constantly check if a buttons is pressed. If I press the button it varies ALLOT in reaction time.WAY to much then whats needed for a pulse to switch it on BUT not switch it of at the same Pulse time. I had this as a little Debouncer.

void ButtonReadProto()
           if (TrackUni==0)
          preUni = millis();
           unsigned long curUni = millis();
            if(curUni - preUni > 500) 
              reading = digitalRead(in1);
             TrackUni =0;
       if (reading == LOW)

I have that little function all over my code.Theres no way that it can mis but still its really awkward when the button is actually pushed. Also the delay is 500 now but was 50 , 100 , 200 and 300 .Same stuff

Hey Rob

Sorry if im being retarded but is that for a Button or for an Interrupt function? Cause Millis() dont work in Interrupts right? by "Real interrupt thing" you mean the function that its suppose to have been in the interrupt or the function "if I am using buttons" would be.

It is the code for an Interrupt Service Routine (ISR for short) If you have your button on a interrupt pin it works for a button too

You are right that millis() wont get updated in the ISR BUT (big but) it still has an actual value as it is updated outside the ISR.

That's why you can compare its value with another value (previous) in an ISR

As your not using interrupts (which is a good thing), you need to take a look at the blink without delay and the button debounceing examples. What you are calling smoothing is known as dedounceing.


If you read the button once every -say- 30 ms you'll get pretty decent debouncing. You must use the blink without delay technique, not calls to delay(), to make the digitalRead(buttonPin) happen every 30 ms. And you can totally avoid interrupts - which are a headache in themselves if not properly understood.