Flow Totalizer using Interrupt

Using a simple code to read and total the pulses coming from a gear flow meter (GFM) which is supposed to give 1 pulse for every 0.6cc passing through it. Thus when 1 liter or 1000 cc passes thorugh it, the GFM ought to give 1000/0.6 = 1667 pulses. But when I run this code I get exactly double this number around 3300 pulses. That’s issue no 1.

Issue No 2 : As you can see I am updating the LCD once every second and this means the values of flow pulses jump in chunks in successive displays. It will be nice to have this happen smooth. When 1 LPM passes through the GFM the pulses will update once every 60 / 1667 = 0.04 second. Obviously I cannot try to update the LCD at this fast rate of once every 0.04 s or 25 Hz which is way too fast for the display. So what other methods exist to smoothen out the update rate ?

/*
   11 Jan 2016 / R RAGHUNATHAN

   Hardware : Arduino UNO / MEGA board @ 16Mhz

   Created from16x2 LCD template, this is for a Flow Totalizer  using interrupst

   UNO Pin Assignments :
   0 : Serial TXD
   1 : Serial RXD
   2 : Interrupt Pin
   3 : Start Push Button
   4 : SPare
   5 : Increment Push Button
   6 : Decrement Push Button
   7 : Enter Push Button
   A4 : SDA of I2C [ RTC + LCD ]
   A5 : SCL of I2C [ RTC + LCD ]

  LCD : 20 Character x 4 Line interfaced using I/O expander I2C interface


  ###############################################
*/
//=================== INCLUDE ==================

// Include Libraries :
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <phi_interfaces.h>
#include <Wire.h>


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//================== DEFINES ====================
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

// Define the LCD pins to use and Initialize an instance
LiquidCrystal_I2C  lcd(0x27, 2, 1, 0, 4, 5, 6, 7);        // [C] 0x27 is the I2C bus address

// Define the Machine Digital Inputs and Outputs
#define StartPB 31                                         // [C]
#define IncrPB 35                                          // [C]
#define DecrPB 33                                          // [C]
#define EnterPB 37                                         // [C]
#define total_buttons 4
char mapDIN[] = {'S', 'I', 'D', 'E'};                      // [C] This is a list of names for each button.
byte pinDIN[] = { StartPB, IncrPB, DecrPB, EnterPB};       // [C] The digital pins connected to the 4 buttons.
phi_button_groups MyDIN(mapDIN, pinDIN, total_buttons);

// List all global variables....
char LCDmsg[21];
unsigned int ScanMs = 100;
char ValidDIN = '0';
boolean HomeDisp_Gate = 1;
volatile unsigned int flowPulse ;

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//================= SETUP =======================
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void setup()
{
  // START SERIAL FOR DEBUGGING
  Serial.begin(9600);
  // Usage : Serial.println(variable);

  // START THE I2C INTERFACE
  Wire.begin();

  // SETUP THE INTERRUPT ON PIN2
  attachInterrupt (0, totalFlow, RISING);  // attach interrupt handler

  // START THE LCD INTERFACE

  lcd.begin(20, 4);
  lcd.setBacklightPin(3, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
  lcd.write( "   FLOW TOTAL..  " );
  lcd.setCursor(0, 1);
  lcd.write( " Version : 1.00 " );
  delay (2000);

}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
//================ SCAN LOOP =====================
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

void loop()
{

  // Read the Push buttons  for every scan..
  ValidDIN = MyDIN.getKey();

  if ( ValidDIN == 'S') {                                // Press START button to reset current value..
    flowPulse = 0;
    ValidDIN = '0';
  }

  if (HomeDisp_Gate) displayHome();                      // Update the Home Screen with pulse total once every second

  delay (ScanMs);
}// End of main loop.

//================ SCAN LOOP END ================

// ISR and Other Functions...

void totalFlow() {
  flowPulse = flowPulse + 1;
}

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void displayHome(void)
{
  unsigned int static HomeCnt = 0;
  if ( HomeCnt >= 1000) {
    char string[21];
    lcd.clear();
    lcd.write( "     FLOW VALUE     ");
    lcd.setCursor(0, 1);
    lcd.write( "********************" );
    sprintf(string, "       %04d       ", flowPulse );   // TODO : Convert and display in liters.,
    lcd.setCursor( 0, 3);
    lcd.write(string);
    HomeCnt = 0;
  }
  else
  {
    HomeCnt += ScanMs;
  }

}
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

what other methods exist to smoothen out the update rate

Maybe only update the display when the value has changed by a certain amount.

UKHeliBob:
Maybe only update the display when the value has changed by a certain amount.

Yes that’s one idea worth trying - maybe I will update once every 10 or 20 pulses !!