   }
   
   
-  // update speed from goalspeed taking acceleration limit into account
-  unsigned long dt = micros() - lastmicros;
-  lastmicros = micros();
-  
-  updateSpeed(dt);
+  if (!manualSpeed) {
+    // update speed from goalspeed taking acceleration limit into account
+    unsigned long dt = micros() - lastmicros;
+    lastmicros = micros();
+    
+    updateSpeed(dt);
+  }
   
   
 

  lastSetpoint = pidSetpoint;
  
  
  int endstop = digitalRead(EXTENSIONENDSTOPPIN);
  
  if (state==HOMING) {
    goalSpeed = homingSpeed;
  }

  }

  // check end stop
  int endstop = digitalRead(EXTENSIONENDSTOPPIN);
  
  bool manualSpeed = false;
  
  if (endstop) {
    if (state==HOMING) {
      state=HOMINGBACKOFF;
      encoder0Pos = -BACKOFF_STEPS;
      manualSpeed = true;
    }
    else if (state==HOMINGBACKOFF) {
      manualSpeed = true;
    }
    else if (state==MOTOROFF) {
      manualSpeed = true;
    }
    
    else {
