Need help with AccelStepper sketch

Trying to mover a stepper-motor first to a predefined hardware position with a photo-interrupter i ran into a programming problem.
I wil post the complete sketch as far i have now in this post starting with the setup and loop.

// LIBRARIES
#include "Arduino.h"
#include <Wire.h>
#include <AccelStepper.h>          // http://www.airspayce.com/mikem/arduino/AccelStepper/index.html

// Arduino version compatibility Pre-Compiler Directives
#if defined(ARDUINO) && ARDUINO >= 100   // Arduino v1.0 and newer
#define I2C_WRITE Wire.write 
#define I2C_READ Wire.read
#else                                   // Arduino Prior to v1.0 
#define I2C_WRITE Wire.send 
#define I2C_READ Wire.receive
#endif

// PINS
int YAxisDIR = 13;      // Stepper direction output
int XAxisDIR = 12;
int YAxisPWM = 11;      // Stepper steps output
int XAxisPWM = 10;

int yStopper1 = 5;      // Y Rotor end stops
int yStopper2 = 4;
int xStopper1 = 3;      // X Rotor end stops
int xStopper2 = 2;

// DEGREES / STEPS CONVERSION
float stepsPerRotation = 200;   // 200 steps per rotation (1.8 degrees per step)
int xGearRatio = 42;            // stepper degrees per pan degree of rotation
int yGearRatio = 42;            // stepper degrees per tilt degree of rotation + calibration factor
int xMicroSteps = 1;
int yMicroSteps = 1;

typedef enum { 
  X_ROTOR, Y_ROTOR } 
stepperfn;

long deg2step( float degrees, stepperfn stepper );
long deg2step( float degrees, stepperfn stepper ) {
  if(stepper == X_ROTOR)	return (( degrees/1.8)*xMicroSteps*xGearRatio);
  if(stepper == Y_ROTOR)	return ((-degrees/1.8)*yMicroSteps*yGearRatio);
}
// VARIABLES
typedef enum { 
  CALIBRATE, NEUTRAL, TRACKING, RESET} 
states;    // Posible states inside the program
states state = CALIBRATE;    // Default state is calibration at startup

int xStop1 = 0;    // Holds the switches digitalRead result
int xStop2 = 0;
int yStop1 = 0;
int yStop2 = 0;

boolean  hitXStop = false;
boolean  hitYStop = false;
boolean  xCentered = false;
boolean  yCentered = false;

// Steppers , see AccelStepper documotation for more information
AccelStepper stepperX(1,XAxisPWM,XAxisDIR);
AccelStepper stepperY(1,YAxisPWM,YAxisDIR);
int xMotorSpeed = 500;  // Maximum steps per second
int yMotorSpeed = 500;  // Maximum steps per second
int xMotorAccel = 8000;  // Steps per second for acceleration
int yMotorAccel = 8000;  // Steps per second for acceleration

// The setup function is only called once
void setup() {

  pinMode(yStopper1, INPUT_PULLUP );      // Initialize the switches inputs
  pinMode(yStopper2, INPUT_PULLUP );      // The internal resistors are made active
  pinMode(xStopper1, INPUT_PULLUP );
  pinMode(xStopper2, INPUT_PULLUP );

  stepperX.setMaxSpeed(xMotorSpeed);        // Set the X rotor-motor maximum speed
  stepperX.setAcceleration(xMotorAccel);    // Set the X rotor-motor acceleration speed
  stepperY.setMaxSpeed(yMotorSpeed);        // Set the Y rotor-motor maximum speed
  stepperY.setAcceleration(yMotorAccel);    // Set the Y rotor-motor acceleration speed

}    // End setup()

void loop() {
  readSwitches();
  switch(state) {
// Calibrate the system. Called at program startup. At theend the dish points upwards.
    case(CALIBRATE):
      calibrateSystem();
    
    break;

  } // End state

}    // End loop()

As the system must be calibrated after a power loss the first thing to do is to run to a end-stop. These are a photo-interrupter at either end of the 180 degrees sweep. These are read with a simple routine:

void readSwitches() {
  xStop1 = digitalRead(xStopper1);  
  xStop2 = digitalRead(xStopper2);  
}

When a interrupter is activated it changes from LOW to HIGH.
This is checked in this part:

void calibrateSystem() {
// See if any switches are active, else run the steppers
  if(hitXStop == false)  stepperX.moveTo(deg2step(-200, X_ROTOR));
  
// If a switch is activate determinate the position and save it
  if(xStop1 == HIGH && hitXStop == false) {
    stepperX.stop();

    stepperX.setCurrentPosition(deg2step(180, X_ROTOR));
    stepperX.moveTo(deg2step(90, X_ROTOR));
  }
  else if(xStop2 == HIGH && hitXStop == false) {
    stepperX.stop();
    stepperX.setCurrentPosition(deg2step(0, X_ROTOR));
    stepperX.moveTo(deg2step(90, X_ROTOR));
  }
  
  stepperX.run();
}

But after it hits the end stop the stepper wont move to the 90 degrees position but it goes for and backwards.
Any insight is welcome.

Harry

It would be easier to read as one complete post or attachment. Having said that, I'm puzzled as to why the calibration routine isn't called from setup. Also, I don't see anything that changes state from CALIBRATE, so it looks like it's just calibrating perpetually.

Is there some reason to be using AccelStepper? That library is intended for situations where you need to be able to run two steppers simultaneously. Since you block until the stepper gets to the new position, anyway, using Stepper would seem to make more sense.

PaulS:
Is there some reason to be using AccelStepper? That library is intended for situations where you need to be able to run two steppers simultaneously. Since you block until the stepper gets to the new position, anyway, using Stepper would seem to make more sense.

As the resulting sketch is for two steppers, but in the building fase i am only working on one stepper and then copying it for the second step[per.