motor setting and calibration

pull/146/head
Tim Evers 2020-05-15 21:16:53 +02:00
parent 99eaff7726
commit fcf98ac6a7
6 changed files with 71 additions and 7 deletions

View File

@ -122,6 +122,7 @@ int F11Handler::execute(Command *command)
} }
else else
{ {
delay(500);
goodConsecutiveHomings = 0; goodConsecutiveHomings = 0;
} }
} }

View File

@ -121,6 +121,7 @@ int F12Handler::execute(Command *command)
} }
else else
{ {
delay(500);
goodConsecutiveHomings = 0; goodConsecutiveHomings = 0;
} }
} }

View File

@ -125,6 +125,7 @@ int F13Handler::execute(Command *command)
} }
else else
{ {
delay(500);
goodConsecutiveHomings = 0; goodConsecutiveHomings = 0;
} }
} }

View File

@ -1124,7 +1124,35 @@ int Movement::calibrateAxis(int axis)
int *axisStatus; int *axisStatus;
long *axisStepsPerMm; long *axisStepsPerMm;
long stepDelay = 0;
unsigned long tickDelay = 0;
unsigned long nextTick = 0;
unsigned long lastTick = 0;
// Prepare for movement // Prepare for movement
tickDelay = (1000.0 * 1000.0 / MOVEMENT_INTERRUPT_SPEED / speedHome[axis] / 2);
stepDelay = 100000 / speedHome[axis] / 2;
Serial.print("R99");
Serial.print(" ");
Serial.print("tick delay");
Serial.print(" ");
Serial.print(tickDelay);
Serial.print(" ");
Serial.print("MOVEMENT_INTERRUPT_SPEED");
Serial.print(" ");
Serial.print(MOVEMENT_INTERRUPT_SPEED);
Serial.print(" ");
Serial.print("speedHome[axis]");
Serial.print(" ");
Serial.print(speedHome[axis]);
Serial.print(" ");
Serial.print("\r\n");
storeEndStops(); storeEndStops();
reportEndStops(); reportEndStops();
@ -1206,7 +1234,6 @@ int Movement::calibrateAxis(int axis)
// Move towards home // Move towards home
calibAxis->enableMotor(); calibAxis->enableMotor();
/**/
//calibAxis->setDirectionHome(); //calibAxis->setDirectionHome();
calibAxis->setDirectionAway(); calibAxis->setDirectionAway();
@ -1294,8 +1321,12 @@ int Movement::calibrateAxis(int axis)
calibAxis->setStepAxis(); calibAxis->setStepAxis();
lastTick = calibrationTicks;
delayMicroseconds(100000 / speedHome[axis] / 2); nextTick = calibrationTicks + tickDelay;
while (calibrationTicks < nextTick && calibrationTicks >= lastTick)
{
delay(1);
}
stepsCount++; stepsCount++;
if (stepsCount % (speedHome[axis] * 3) == 0) if (stepsCount % (speedHome[axis] * 3) == 0)
@ -1325,7 +1356,14 @@ int Movement::calibrateAxis(int axis)
} }
calibAxis->resetMotorStep(); calibAxis->resetMotorStep();
delayMicroseconds(100000 / speedHome[axis] / 2);
//delayMicroseconds(stepDelay);
lastTick = calibrationTicks;
nextTick = calibrationTicks + tickDelay;
while (calibrationTicks < nextTick && calibrationTicks >= lastTick)
{
delay(1);
}
} }
else else
{ {
@ -1482,7 +1520,13 @@ int Movement::calibrateAxis(int axis)
//checkAxisVsEncoder(&axisX, &encoderX, &motorConsMissedSteps[0], &motorLastPosition[0], &motorConsMissedStepsDecay[0], &motorConsEncoderEnabled[0]); //checkAxisVsEncoder(&axisX, &encoderX, &motorConsMissedSteps[0], &motorLastPosition[0], &motorConsMissedStepsDecay[0], &motorConsEncoderEnabled[0]);
delayMicroseconds(100000 / speedHome[axis] / 2); //delayMicroseconds(stepDelay);
lastTick = calibrationTicks;
nextTick = calibrationTicks + tickDelay;
while (calibrationTicks < nextTick && calibrationTicks >= lastTick)
{
delay(1);
}
if (stepsCount % (speedHome[axis] * 3) == 0) if (stepsCount % (speedHome[axis] * 3) == 0)
{ {
@ -1498,7 +1542,14 @@ int Movement::calibrateAxis(int axis)
} }
calibAxis->resetMotorStep(); calibAxis->resetMotorStep();
delayMicroseconds(100000 / speedHome[axis] / 2); //delayMicroseconds(stepDelay);
lastTick = calibrationTicks;
nextTick = calibrationTicks + tickDelay;
while (calibrationTicks < nextTick && calibrationTicks >= lastTick)
{
delay(1);
}
} }
else else
{ {
@ -2046,10 +2097,10 @@ void Movement::handleMovementInterrupt(void)
#endif #endif
// handle motor timing // handle motor timing
axisX.incrementTick(); axisX.incrementTick();
axisY.incrementTick(); axisY.incrementTick();
axisZ.incrementTick(); axisZ.incrementTick();
calibrationTicks++;
} }

View File

@ -88,6 +88,8 @@ private:
int serialMessageNr = 0; int serialMessageNr = 0;
int serialMessageDelay = 0; int serialMessageDelay = 0;
unsigned long calibrationTicks = 0;
void serialBufferSendNext(); void serialBufferSendNext();
void serialBufferEmpty(); void serialBufferEmpty();

View File

@ -162,11 +162,19 @@ void loadTMC2130ParametersMotor(TMC2130_Basics *tb, int microsteps, int current,
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(1) << FB_TMC_CHOPCONF_TBL, FB_TMC_CHOPCONF_MASKS[FB_TMC_CHOPCONF_TBL] << FB_TMC_CHOPCONF_TBL); tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(1) << FB_TMC_CHOPCONF_TBL, FB_TMC_CHOPCONF_MASKS[FB_TMC_CHOPCONF_TBL] << FB_TMC_CHOPCONF_TBL);
tb->set_GCONF(FB_TMC_GCONF_DIAG1_STALL, 1); tb->set_GCONF(FB_TMC_GCONF_DIAG1_STALL, 1);
tb->set_GCONF(FB_TMC_GCONF_DIAG1_ONSTATE, 1); tb->set_GCONF(FB_TMC_GCONF_DIAG1_ONSTATE, 1);
tb->write_REG(FB_TMC_REG_TCOOLTHRS, 0xFFFFF & FB_TMC_TCOOLTHRS_MASK);
tb->write_REG(FB_TMC_REG_THIGH, 0xFFFFF & FB_TMC_THIGH_MASK);
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(5) << FB_TMC_COOLCONF_SEMIN, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMIN] << FB_TMC_COOLCONF_SEMIN);
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(15) << FB_TMC_COOLCONF_SEMAX, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMAX] << FB_TMC_COOLCONF_SEMAX);
/* // 2020-05-15 copy of settings before experiments
tb->write_REG(FB_TMC_REG_TCOOLTHRS, 0xFFFFF & FB_TMC_TCOOLTHRS_MASK); tb->write_REG(FB_TMC_REG_TCOOLTHRS, 0xFFFFF & FB_TMC_TCOOLTHRS_MASK);
tb->write_REG(FB_TMC_REG_THIGH, 0 & FB_TMC_THIGH_MASK); tb->write_REG(FB_TMC_REG_THIGH, 0 & FB_TMC_THIGH_MASK);
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(5) << FB_TMC_COOLCONF_SEMIN, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMIN] << FB_TMC_COOLCONF_SEMIN); tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(5) << FB_TMC_COOLCONF_SEMIN, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMIN] << FB_TMC_COOLCONF_SEMIN);
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(2) << FB_TMC_COOLCONF_SEMAX, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMAX] << FB_TMC_COOLCONF_SEMAX); tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(2) << FB_TMC_COOLCONF_SEMAX, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEMAX] << FB_TMC_COOLCONF_SEMAX);
tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(0b01) << FB_TMC_COOLCONF_SEDN, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEDN] << FB_TMC_COOLCONF_SEDN); tb->alter_REG(FB_TMC_REG_CHOPCONF, uint32_t(0b01) << FB_TMC_COOLCONF_SEDN, FB_TMC_CHOPCONF_MASKS[FB_TMC_COOLCONF_SEDN] << FB_TMC_COOLCONF_SEDN);
*/
delay(100); delay(100);