Help needed to display the correcr rpm value continuously

In the code below we have managed to regulate the speed of a dc motor while seeing the rpm readings continuously. The compiler passes the code, but the result is the above malfunction:

The motor starts to rotate according to the program, the lcd displays the data and values except the correct rpm reading. In the first step (value=50 in my code) the rpm reading is zero, in the second step (value=200) the rpm displays the previous speed (from value=50) and in the final third step (value=0) displays the speed from value=200, while the motor has stopped rotating!!!

Can you help me, where is the wrong point in the code?

#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,6,5,4,3);
int pwm=9;
float value=0;
int percent;
float rev=0;
int rpm;
int oldtime=0;
int time;
void isr() //interrupt service routine
{
rev++;
}
void setup()
{
lcd.begin(16,2); //initialize LCD
attachInterrupt(0,isr,RISING); //attaching the interrupt
}

void loop()
{
print_data();

value=50;
analogWrite(pwm,value); //sets the desired speed
print_data();
delay(6000);

value=200;
analogWrite(pwm,value); //sets the desired speed
print_data();
delay(6000);

value=0;
analogWrite(pwm,value); //sets the desired speed
print_data();

while(1); }

void print_data()
{
detachInterrupt(0); //detaches the interrupt
time=millis()-oldtime; //finds the time
rpm=(rev/time)*60000/2; //calculates rpm
rev=0;
oldtime=millis(); //saves the current time
percent=(value/255)*100; //finds the duty cycle %
lcd.clear();
lcd.setCursor(1,0);
lcd.print("MOTOR_");
lcd.setCursor(0,1);
lcd.print(rpm);
lcd.print(" RPM");
lcd.print(" ");
lcd.print(percent);
lcd.print("%");
lcd.print(" ");
lcd.print("S.P");
attachInterrupt(0,isr,RISING);
}

float rev=0;
int rpm;
int oldtime=0;
int time;
void isr() //interrupt service routine
{
rev++;
}

"rev" should be qualified "volatile", and really doesn't need to be a float - you can't count fractional interrupts.

Please remember to use code tags when posting code.

Check here

I suspect, because you have all those long delay()s that the display is showing the data from the previous iteration. If the delay() was 100millisecs you would not notice, but 6 seconds is a different matter.

Get rid of all the delay()s and use millis() to manage timing as illustrated in several things at a time.

...R