From aeb483f9e02f03ae67c93f99603aea733de2cf08 Mon Sep 17 00:00:00 2001 From: David Crocker Date: Mon, 28 Feb 2022 15:19:57 +0000 Subject: Improved M569 T parameter support on MB6XD --- src/GCodes/GCodes3.cpp | 22 ++++++++++++++-------- src/Movement/DriveMovement.h | 6 +++--- src/Platform/Platform.cpp | 18 ++++++++++++++---- src/Platform/Platform.h | 9 +++++++-- 4 files changed, 38 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/GCodes/GCodes3.cpp b/src/GCodes/GCodes3.cpp index 26f5c711..05b0dea1 100644 --- a/src/GCodes/GCodes3.cpp +++ b/src/GCodes/GCodes3.cpp @@ -1567,15 +1567,21 @@ GCodeResult GCodes::ConfigureLocalDriverBasicParameters(GCodeBuffer& gb, const S drive, (platform.GetDirectionValue(drive)) ? "forwards" : "in reverse", (platform.GetEnableValue(drive) > 0) ? "high" : "low"); - float timings[4]; - const bool isSlowDriver = platform.GetDriverStepTiming(drive, timings); - if (isSlowDriver) { - reply.catf("%.1f:%.1f:%.1f:%.1fus", (double)timings[0], (double)timings[1], (double)timings[2], (double)timings[3]); - } - else - { - reply.cat("fast"); + float timings[4]; + const bool isSlowDriver = platform.GetDriverStepTiming(drive, timings); + if (isSlowDriver) + { + reply.catf("%.1f:%.1f:%.1f:%.1fus", (double)timings[0], (double)timings[1], (double)timings[2], (double)timings[3]); +#ifdef DUET3_MB6XD + platform.GetActualDriverTimings(timings); + reply.catf(" (actual %.1f:%.1f:%.1f:%.1fus)", (double)timings[0], (double)timings[1], (double)timings[2], (double)timings[3]); +#endif + } + else + { + reply.cat("fast"); + } } #if HAS_SMART_DRIVERS diff --git a/src/Movement/DriveMovement.h b/src/Movement/DriveMovement.h index 473091d3..18e2eb38 100644 --- a/src/Movement/DriveMovement.h +++ b/src/Movement/DriveMovement.h @@ -165,11 +165,11 @@ inline bool DriveMovement::CalcNextStepTime(const DDA &dda) noexcept { if (stepsTillRecalc != 0) { - --stepsTillRecalc; // we are doing double/quad/octal stepping + --stepsTillRecalc; // we are doing double/quad/octal stepping #if EVEN_STEPS nextStepTime += stepInterval; #endif -#if SAME70 +#ifdef DUET3_MB6HC // we need to increase the minimum step pulse length to be long enough for the TMC5160 asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); @@ -183,7 +183,7 @@ inline bool DriveMovement::CalcNextStepTime(const DDA &dda) noexcept } state = DMState::idle; -#if SAME70 +#ifdef DUET3_MB6HC // we need to increase the minimum step pulse length to be long enough for the TMC5160 asm volatile("nop"); asm volatile("nop"); asm volatile("nop"); diff --git a/src/Platform/Platform.cpp b/src/Platform/Platform.cpp index f89bc9f0..10089590 100644 --- a/src/Platform/Platform.cpp +++ b/src/Platform/Platform.cpp @@ -2799,11 +2799,10 @@ GCodeResult Platform::SetMotorCurrent(size_t axisOrExtruder, float currentOrPerc #ifdef DUET3_MB6XD // Fetch the worst (longest) timings of any driver, set up the step pulse width timer, and convert the other timings from microseconds to step clocks -void Platform::UpdateDriverTimings() +void Platform::UpdateDriverTimings() noexcept { - float worstTimings[4]; - memcpyf(worstTimings, driverTimingMicroseconds[0], 4); - for (size_t driver = 1; driver < NumDirectDrivers; ++driver) + float worstTimings[4] = { 0.1, 0.1, 0.0, 0.0 }; // minimum 100ns step high/step low time, zero direction setup/hold time + for (size_t driver = 0; driver < NumDirectDrivers; ++driver) { for (size_t i = 0; i < 4; ++i) { @@ -2833,6 +2832,17 @@ void Platform::UpdateDriverTimings() // debugPrintf("Clocks: %" PRIu32 " %" PRIu32 " %" PRIu32 "\n", stepPulseMinimumPeriodClocks, directionSetupClocks, directionHoldClocksFromLeadingEdge); } +void Platform::GetActualDriverTimings(float timings[4]) noexcept +{ + constexpr uint32_t StepGateTcClockFrequency = (SystemCoreClockFreq/2)/8; + constexpr float MicrosecondsPerStepGateClock = 1.0e6/(float)StepGateTcClockFrequency; + constexpr float StepClocksToMicroseconds = 1.0e6/(float)StepClockRate; + timings[0] = (float)STEP_GATE_TC->TC_CHANNEL[STEP_GATE_TC_CHAN].TC_RC * MicrosecondsPerStepGateClock; + timings[1] = stepPulseMinimumPeriodClocks * StepClocksToMicroseconds - timings[0]; + timings[2] = directionSetupClocks * StepClocksToMicroseconds; + timings[3] = directionHoldClocksFromLeadingEdge * StepClocksToMicroseconds - timings[0]; +} + #endif // This must not be called from an ISR, or with interrupts disabled. diff --git a/src/Platform/Platform.h b/src/Platform/Platform.h index 4035aeb5..b6c0226d 100644 --- a/src/Platform/Platform.h +++ b/src/Platform/Platform.h @@ -470,6 +470,11 @@ public: unsigned int GetMicrostepping(size_t axisOrExtruder, bool& interpolation) const noexcept; void SetDriverStepTiming(size_t driver, const float microseconds[4]) noexcept; bool GetDriverStepTiming(size_t driver, float microseconds[4]) const noexcept; + +#ifdef DUET3_MB6XD + void GetActualDriverTimings(float timings[4]) noexcept; +#endif + float DriveStepsPerUnit(size_t axisOrExtruder) const noexcept; const float *_ecv_array GetDriveStepsPerUnit() const noexcept { return driveStepsPerUnit; } @@ -702,11 +707,11 @@ private: // Convert microseconds to step clocks, rounding up to the next step clock static constexpr uint32_t MicrosecondsToStepClocks(float us) noexcept { - return (uint32_t)(((float)StepClockRate * 0.000001 * us) + 0.99); + return (uint32_t)ceilf((float)StepClockRate * 0.000001 * us); } #ifdef DUET3_MB6XD - void UpdateDriverTimings(); + void UpdateDriverTimings() noexcept; #endif #if HAS_MASS_STORAGE -- cgit v1.2.3