From fcf98ac6a7f5e60c84d32ebb5d0ac6fd59bb8aa7 Mon Sep 17 00:00:00 2001 From: Tim Evers Date: Fri, 15 May 2020 21:16:53 +0200 Subject: [PATCH] motor setting and calibration --- src/F11Handler.cpp | 1 + src/F12Handler.cpp | 1 + src/F13Handler.cpp | 1 + src/Movement.cpp | 65 +++++++++++++++++++++++++++++++++++++++++----- src/Movement.h | 2 ++ src/TMC2130.cpp | 8 ++++++ 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/F11Handler.cpp b/src/F11Handler.cpp index 77bcb17..02954c9 100644 --- a/src/F11Handler.cpp +++ b/src/F11Handler.cpp @@ -122,6 +122,7 @@ int F11Handler::execute(Command *command) } else { + delay(500); goodConsecutiveHomings = 0; } } diff --git a/src/F12Handler.cpp b/src/F12Handler.cpp index 5ab7926..5e23fc5 100644 --- a/src/F12Handler.cpp +++ b/src/F12Handler.cpp @@ -121,6 +121,7 @@ int F12Handler::execute(Command *command) } else { + delay(500); goodConsecutiveHomings = 0; } } diff --git a/src/F13Handler.cpp b/src/F13Handler.cpp index d3c4d6a..65ca9f2 100644 --- a/src/F13Handler.cpp +++ b/src/F13Handler.cpp @@ -125,6 +125,7 @@ int F13Handler::execute(Command *command) } else { + delay(500); goodConsecutiveHomings = 0; } } diff --git a/src/Movement.cpp b/src/Movement.cpp index e2567df..c92603c 100644 --- a/src/Movement.cpp +++ b/src/Movement.cpp @@ -1124,7 +1124,35 @@ int Movement::calibrateAxis(int axis) int *axisStatus; long *axisStepsPerMm; + long stepDelay = 0; + unsigned long tickDelay = 0; + unsigned long nextTick = 0; + unsigned long lastTick = 0; + // 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(); reportEndStops(); @@ -1206,7 +1234,6 @@ int Movement::calibrateAxis(int axis) // Move towards home calibAxis->enableMotor(); - /**/ //calibAxis->setDirectionHome(); calibAxis->setDirectionAway(); @@ -1294,8 +1321,12 @@ int Movement::calibrateAxis(int axis) calibAxis->setStepAxis(); - - delayMicroseconds(100000 / speedHome[axis] / 2); + lastTick = calibrationTicks; + nextTick = calibrationTicks + tickDelay; + while (calibrationTicks < nextTick && calibrationTicks >= lastTick) + { + delay(1); + } stepsCount++; if (stepsCount % (speedHome[axis] * 3) == 0) @@ -1325,7 +1356,14 @@ int Movement::calibrateAxis(int axis) } calibAxis->resetMotorStep(); - delayMicroseconds(100000 / speedHome[axis] / 2); + + //delayMicroseconds(stepDelay); + lastTick = calibrationTicks; + nextTick = calibrationTicks + tickDelay; + while (calibrationTicks < nextTick && calibrationTicks >= lastTick) + { + delay(1); + } } else { @@ -1482,7 +1520,13 @@ int Movement::calibrateAxis(int axis) //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) { @@ -1498,7 +1542,14 @@ int Movement::calibrateAxis(int axis) } calibAxis->resetMotorStep(); - delayMicroseconds(100000 / speedHome[axis] / 2); + //delayMicroseconds(stepDelay); + lastTick = calibrationTicks; + nextTick = calibrationTicks + tickDelay; + while (calibrationTicks < nextTick && calibrationTicks >= lastTick) + { + delay(1); + } + } else { @@ -2046,10 +2097,10 @@ void Movement::handleMovementInterrupt(void) #endif // handle motor timing - axisX.incrementTick(); axisY.incrementTick(); axisZ.incrementTick(); + calibrationTicks++; } diff --git a/src/Movement.h b/src/Movement.h index d8cdb87..df830e2 100644 --- a/src/Movement.h +++ b/src/Movement.h @@ -88,6 +88,8 @@ private: int serialMessageNr = 0; int serialMessageDelay = 0; + unsigned long calibrationTicks = 0; + void serialBufferSendNext(); void serialBufferEmpty(); diff --git a/src/TMC2130.cpp b/src/TMC2130.cpp index bb6ab11..730ff12 100644 --- a/src/TMC2130.cpp +++ b/src/TMC2130.cpp @@ -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->set_GCONF(FB_TMC_GCONF_DIAG1_STALL, 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_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(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); + */ delay(100);