     Serial.print(", ");
   }
   
-  //Calculate Weighted Average
+  if (tachDuration0 <= 0 || tachDuration1 <= 0 || tachDuration2 <= 0)
+    return 0;
+  
+  //Calculate Weighted Average duration
   unsigned long average = (3*tachDuration0 + 2*tachDuration1 + 1*tachDuration2)/6;
-  interrupts();
-  
+  
+  //Convert to RPM
   return 60.0 * 1000000 / average;
+}
+
+bool isStale()
+{
+  return (micros() - tachCurrent) > tachStale;
 }
 
 void enableCoil()

Flameduino Controls an ignition coil with a set dwell (compile time)
and variable spark frequency, specifically for purposes of flamethrowing.
*/
#include <TimerOne.h>

// -------------------------
//     Pin Definitions

unsigned int getRPM()
{
  noInterrupts();
  unsigned long current = tachCurrent;
  unsigned long previous = tachPrevious;
  interrupts();
  
  if (isStale())
  {
    tachDuration0 = 0;
    tachDuration1 = 0;
    tachDuration2 = 0;
    return 0;
  }
  
  unsigned long duration;
  if (current >= previous)
  {
    duration = current - previous + tachTrim;
  }
  else
  {
    //Handle Rollover
    duration = 0xFFFFFFFFu - previous + current + tachTrim;
  }
  
  //Shift the values
  tachDuration2 = tachDuration1;
  tachDuration1 = tachDuration0;
  tachDuration0 = duration;
  
  if (false && debug && loopsSinceSerialWrite >= serialOutLoops)
  {
    Serial.print("t0: ");
    Serial.print(tachDuration0);
