 double hall_counter = 0;
 double rpm = 0;
 unsigned long last_time = 0;
-const double hall_sample_rate = 100;
+const unsigned long hall_sample_rate = 123456; //1.23456 second
 
-double pwm = 0,setpoint = 1500;
-double Kp=5, Ki=3, Kd=1;
+double pwm = 0,setpoint = 2136; // 2221 RPM
+double Kp=0.1, Ki=0.07, Kd=0.01;
 PID pid(&rpm, &pwm, &setpoint, Kp, Ki, Kd,100000,ON,REVERSE,0,255);
 
 void setup()

}

void HallISR(){
  hall_counter++;
}

  digitalWrite(motor_pin_1,LOW);
  digitalWrite(motor_pin_2,HIGH);
  
  last_time = micros();
}

void loop()
{
  
  if((micros() - last_time) >= hall_sample_rate){
    rpm = ((hall_counter * (1000000.0f/(double)(micros()-last_time))) * 60);
    hall_counter = 0;
    last_time = micros();
    
    if(DEBUG){
      Serial.print(rpm);
      Serial.print(",");
      Serial.println(pwm);
    }
  }
  pid.Computing();
  analogWrite(enable,pwm);
  
