Help with pcint for flow meter

Hi guys,

Im designing a flow meter for use on a peristaltic pump where the displacement per revolution is known. The pump RPM is less than 40 so 1.5 - 2 seconds per revolution.

The old flowmeter used a hall effect sensor and I want to do the same as the magnet and bracket for the swensor are already there. I'm using an UNO with a 3.5" tft screen but the screen uses pins 2&3 so the normal interrupts are not available. So I wanted to use pcint on pin 10. The UNO updates the screen every 10 seconds, the rest of the time it just waits counting pulses.

I havent found out if I can handle a rising interrupt, just a falling one - all the examples I have seen have been the same so I thought that on each interrupt, I'd use a slight delay then check to see if the pin has gone high - ie magnet and sensor in proximity - and only update if it has. That seems to work OK - Im testing it by touching a wire from pin 10 to gnd. However, I cant seem to debounce it. Sometimes I only get one pulse, mostly I get two. I have even tried turning off interrupts at the start of the pcint handler and back on again at the end.

Any suggestions please? code is here

void pciSetup(byte pin)   //pcint setup for required pin(s)
{
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));   // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin));                    // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin));                    // enable interrupt for the group 
}


ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{ 
  cli(); 
  delay(100);  
  if (digitalRead(10)==1)  
  {
    Serial.println("A pulse!");
    delay(500);  
  }
  sei();
} 


void setup() 
{   
  Serial.begin(9600);
  Serial.println("Boe");
  pinMode(10, INPUT);       // Pin 10 is input to which a sensor is connected
  digitalWrite(10, HIGH);   // Configure internal pull-up resistor
  pciSetup(10);
}


void loop() {
  // Nothing needed
}

ISR (PCINT0_vect) // handle pin change interrupt for D8 to D13 here
{
cli();
delay(100);

Interrupts are already disabled when an interrupt service routine is called. It is not necessary to disable them.

It is NOT possible to use delay() in an ISR.

It IS possible to configure pin change interrupts to trigger on the rising edge, the falling edge, or both.

What you need to do is quit using delay() in the ISR. Record when the interesting interrupt happens. In the ISR, see if this interrupt is long enough after the last interesting interrupt to be interesting. If so, do whatever you need to do. If not, ignore this interrupt.