title: Arduino Due C Timer Coding (Interrupt Counting)
body: <p>I have an Arduino Due that I'm doing a lot of really neat stuff with in one section of code I'm handeling a flowsensor and getting readings from it. the flowsensor is hooked up to an interrupt as it is a hallsensor device. The problem I'm having is that my math is based off of a single seconds worth of collection data, when I turn on the interrupt and sleep for a second do the calculations for flowrate in gp/m it works great. For My purposes however I can't afford to pause and collect data, so instead I calculate a change in time of greater than a thousand milliseconds. then I take the amount of time passed since the last loop, devide it by 1000 milliseconds or 1 second then I have the percentage of 1 second stored in a variable, I multiply the count by the percentage and should arrive at the number of counts per second. This however results in an ever growing number regardless of the fact that I zero the numbers prior to the next loop. Below I've included the way I formatted the expressions and the loop code for the flowsensor, I'd post the whole code but I don't want to waste space on stackoverflow and I know that portion of code already works with the sleep method.</p>
  
  <pre><code>long currentMillis = 0;
  long lastMillis = 0;
  int checkMillis = 0;
  volatile int NbTopsFan; //measuring the rising edges of the signal
  int newNbTopsFan;
  float realNbTopsFan;
  float realMillis;
  float Calc;
  float Calcd;
  int Calcf;
  int hallsensor = 7;
  
  void loop()
  {
    if (lastMillis = 0) {
      lastMillis = millis();
    }
    currentMillis = millis();
    checkMillis = (currentMillis - lastMillis);
    if (checkMillis &gt;= 1000) {
      realMillis = (checkMillis / 1000);
      realNbTopsFan = (NbTopsFan * realMillis);
      newNbTopsFan = realNbTopsFan;
      Calc = (newNbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate
      Calc = (Calc / 60);
      Calc = (Calc / 3.78541);
      Calc = (Calc * 1.47);
      Calcd = (Calc * 100);
      Calcf = Calcd;
      NbTopsFan = 0;
      lastMillis = 0;
      checkMillis = 0;
      realMillis = 0;
      realNbTopsFan = 0;
      newNbTopsFan = 0;
    }
  }
  </code></pre>