External Interrupt not responding properly

Hello all,

I’m trying to read a pulse flow meter and I’m simulating the input in the external interrupt oin with a 5v 100 Hz square wave signal.

The ISR consists simply of “count++;” and all variables used in ISR’s are declared volatile.

#include <TimerOne.h>

volatile uint8_t runCalc=1;
volatile uint16_t count = 0;
volatile uint16_t freq = 0;

void startCalcs(void)
{
  freq = count;
  count = 0;
  runCalc = 1;
}
void counter(void)
{
  count++;
}
void setup() {
  Serial.begin(115200);
  pinMode(2, INPUT);
  digitalWrite(2, LOW);
  Timer1.initialize(1000000);
  Timer1.attachInterrupt(startCalcs);
  attachInterrupt(digitalPinToInterrupt(3), counter, RISING);
}

if(runCalc)
 {
  ReadAllTemps();
  float power= CalcPower(tempInGlobal, tempOutGlobal, Kfactor, freq);
  
  Serial.println(count);
  runCalc = 0; 
 }

I tried sending the freq value via serial, but it reads 6-7 at 100 Hz…

Any ideas as to what’s going on here?

Sorry, I see what I did... I printed the count variable instead of the freq.

DOH..! :slight_smile:

How do I delete this thread?