Arduino Interrupt Counter

I am counting interrupts and no matter what I do it goes 1,2, 10, 210.... I cannot figure out why

Here is the code:

/***********************************************************************************************************************

  • Function Name: countPulses

  • Description : Increments pulses counter, this is called everytime the pin of the flowmeter goes from LOW to HIGH

  • Arguments : none

  • Return Value : none
    ***********************************************************************************************************************/
    void countPulses_one() {
    //increment number of pulses by 1, this is us counting number of pulses

    // This gives the time between pulses in milliseconds
    int stop_time = millis();
    float pulse_time = stop_time - start_time;

    Serial.print(String(pulse_time, 3));
    Serial.print(" Pulse Time ");

    pulses_one_sum += pulse_time;
    pulses_one++;
    delay(10);
    Serial.print(String(pulses_one, 3));
    Serial.print(" Pulses ");

    if(pulses_one == 16){
    pulses_one_sum = pulses_one_sum/16;
    float freq = 1000/pulses_one_sum;
    Serial.print(String(freq, 5));
    Serial.println(" ");
    //zero them back out
    pulses_one_sum = 0;
    pulses_one_sum = 0;
    }

    start_time = stop_time;

}

Two suggestions, post the Code and a Schematic, not a frizzy thing. With the information you gave us. Currently we are in the same boat, I cannot figure out why either.

Hello,
do you have really delay()s and Serial.println() within in ISR?

1 Like

. . . and you know about defining variables which are set in an ISR and used outside that ISR as volatile ?

1 Like

... and you know about disabling interrupts when you read a multi-byte volatile variable?

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.