Tachometer does not reset to zero when its is idle.

HELP! programming Masters...

I have a project that reads RPM of a fan and I found a working program in the Net and used it with equivalent parts that I have.

The problem is, the rpm on the LCD doesn't reset or get back to zero whenever I'm not using the program..

What program should I add to reset its counter?

Please see below code that he used. Any help will be greatly appreciated. thanks in advance..

CODE:

#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 5, 9, 10, 11, 12);

volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};

void setup()
{
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);

// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Current RPM:");
}

//Main Loop To Calculate RPM and Update LCD Display
void loop()
{

int rpm = 0;

while(1){

//Slow Down The LCD Display Updates
delay(400);

//Clear The Bottom Row
lcd.setCursor(0, 1);
lcd.print(" ");

//Update The Rpm Count
lcd.setCursor(0, 1);
lcd.print(rpm);

////lcd.setCursor(4, 1);
////lcd.print(time);

//Update The RPM
//if(time > 0)
//{
//5 Sample Moving Average To Smooth Out The Data
rpm_array[0] = rpm_array[1];
rpm_array[1] = rpm_array[2];
rpm_array[2] = rpm_array[3];
rpm_array[3] = rpm_array[4];
rpm_array[4] = 60*(1000000/(time*2));
//Last 5 Average RPM Counts Eqauls....
rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
// }

}
}

//Capture The IR Break-Beam Interrupt
void fan_interrupt()
{
time = (micros() - time_last);
time_last = micros();
}

Jhon_r20:
The problem is, the rpm on the LCD doesn't reset or get back to zero whenever I'm not using the program..

What do you mean "not using the program"? Who cares what it does if you aren't using it? If you aren't using it, it won't be doing anything.

Code tags, please, not bold.

http://forum.arduino.cc/index.php/topic,148850.0.html

If you mean, the LCD shows the last thing you sent to it, that would be right. It updates when it is told to.

Hi Nick, thanks for the reply.

I mean when ever it goes idle for some time, the last rpm reading is what it displays on the LCD.

what i want it to do is to reset its last reading to zero if it goes idle for like 3 secs or so.

BTW I'm sorry for the bold letters.

what i want it to do is to reset its last reading to zero if it goes idle for like 3 secs or so.

So, tell it to do that.

  while(1){

There is NO excuse for running an infinite loop inside an infinite loop(). GET RID OF THIS CRAP!

  ////lcd.setCursor(4, 1);
  ////lcd.print(time);

If your delete key is broken, get it fixed. If it isn't make use of it! Don't post code full of commented out crap.

Why are printing rpm to the LCD BEFORE computing rpm?

      rpm_array[4] = 60*(1000000/(time*2));

If there are no interrupts, time never gets updated.

That is NOT how to compute RPM. The interrupt service routine should count interrupts. Then, loop() should compute RPM based on the time it determines and the number of pulses in that period of time. That way, 0 pulses will equal 0 rpm.