Ignore interrupt within time range arduino (lowpass filter)
<p>I'm trying to attach interrupts to the rising edge of a signal (PWM). However, the signal is somewhat noisy when it's <code>HIGH</code> which causes the code to register another interrupt when it should not. I obviously tried to fix this in my circuit but that's not quite working so I moved to the software part.</p>

<p>The question is how I can filter out interrupts within a given frequency range? I need to apply a lowpass filter so that the interrupts do not get triggered when the signal is <code>HIGH</code>. My idea was detach the interrupt for a given amount of time or simply ignore the interrupt if it happens within a certain time range.</p>

<p>I'm just not sure how to achieve this. </p>

<p>This is my code:</p>

<pre><code>unsigned long tsend = 0;
unsigned long techo = 0;
const int SEND = 2;
const int ECHO = 3;
unsigned long telapsed = 0;
unsigned long treal = 0;

void setup() {
  Serial.begin(115200);
  Serial.println("Start");

  pinMode(SEND, INPUT);
  pinMode(ECHO, INPUT);

  attachInterrupt(digitalPinToInterrupt(SEND), time_send, RISING);
  attachInterrupt(digitalPinToInterrupt(ECHO), time_echo, RISING);
}

void loop() {
  telapsed = techo - tsend;
  if (telapsed &gt; 100 &amp;&amp; telapsed &lt; 10000000) {
    treal = telapsed;
    Serial.println(treal);
  }
}

void time_send() {
  tsend = micros();
}
void time_echo() {
  techo = micros();

}
</code></pre>

<p>Below is the signal (yellow) which has a lot of noise. I need to ignore the interrupts when the signal is <code>HIGH</code>. Here is an image of the <a href="http://i.stack.imgur.com/wABNc.jpg" rel="nofollow">PWM Signal</a></p>