controlling rpm of DC motor using pid

The project is to enter a specific rpm via mobile and to maintain that speed using optical encoder

code:

#include <PID_v1.h>
volatile int count;
unsigned long prevmillis=0;
double act_rpm=0,m=3,t=3000,prevx,in_rpm=0,Output=0,Kp=0.5, Ki=10, Kd=4;
PID myPID(&act_rpm, &Output, &in_rpm, Kp, Ki, Kd, DIRECT);
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(m,OUTPUT);
myPID.SetMode(AUTOMATIC);
attachInterrupt(0,counter,RISING);
}
void loop() {
if(Serial.available())
in_rpm=Serial.parseInt();
if(millis()-prevmillis==t)
{
detachInterrupt(0);
act_rpm=(count60000)/(20t);
Serial.println(act_rpm);
prevmillis=millis();
count=0;
prevmillis=millis();
Serial.print("Output=");
Serial.println(Output);
attachInterrupt(0,counter,RISING);
}
myPID.Compute();
analogWrite(m,Output);

}
void counter()
{
count++;
}

pid2.ino (778 Bytes)

Is there a question, or is this a presentation?
Why didn't you simply post the code?

i edited the post and i wrote the code
Sorry this is the first time for me to post here

I have a project using PID (well, just PI actually) to control a small DC motor. I posted the recent code here.

There is no need to go to the trouble of calculating RPM. Just measure the time for a revolution in microseconds.

Look at how my program gets the value from the ISR without needing to detach the interrupt. and how it disables the interrupt for the shortest time possible.

...R