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

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

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

