IR Sensor - RPM Counter

Hey guys! I’m new here, and I have a problem with my program.
Basically , I’ve built an RPM counter , using the IR Sensor, LCD to show the value, and one button which has the functionality to save the current RPM when pressed ( using an interrupt function ).
My problem is with the motor speed control. With the code below, the LCD is showing random numbers for RPM, even tho im not holding the sensor towards the motor, and when I do it , i’m pretty sure its not working 100% correct ( my values are not constant, jumping to 10k + which should be imposibble ) .
When I tried to power up the motor using a second arduino ( so im not using analogRead(motor,90) in the main code anymore ) , the code is working as intended .

Im not sure when to disable the interrupts, maybe its from them . Or maybe im using to much power having the motor conected to the arduino aswell ?

#include<LiquidCrystal.h> //librarie LCD
LiquidCrystal lcd(7,8,9,10,11,12);  
volatile unsigned long rev=0; 
volatile unsigned long OK;
unsigned long rpm;
unsigned long time , oldtime = 0 ;
const int buton=3;
const int motor=5;
void RPM_Count()
void button()
void setup()
attachInterrupt(0,RPM_Count,RISING); // RPM count interrupt
pinMode(buton,INPUT_PULLUP); // button to save RPM
attachInterrupt(1,button,FALLING); // pull-up buton interrupt

void loop()

delay(1000); // update RPM every second
//--------- Also, if someone can explain this next  4 lines for me ,and how RPM is calculated,as I'm a bit confused.
lcd.print(" RPM");

Update :

Another thing that's weird is with the motor control that I just saw , is that the values are inverted.
Meaning that if I send 0 PWM it acts like 255 , and vice versa. Its weird and I dont understand why. Im using a simple H Bridge module to control it, by the way.

Even if I comment the line // analogWrite(motor,90) , and run the code (while my motor is still conected to the arduino PWM pin ,but it runs on a 5V power module ) , my lcd is still displaying random numbers. How is that posibble ? Something is happening because my interrupt function gets activated by itself