diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-10-20 18:24:33 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-10-20 18:24:33 +0300 |
commit | 5d09951b844934ee0dd43f020d24bb95529ac143 (patch) | |
tree | 78ad425efb1b20d1285e0ce0b6a2b3d61151d75d /src/Movement | |
parent | 2cc54a41449563382c88f1428ba61de07b1787f4 (diff) |
Brought TMC51xx driver into line with Duet3Expansion
Diffstat (limited to 'src/Movement')
-rw-r--r-- | src/Movement/StepperDrivers/TMC51xx.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Movement/StepperDrivers/TMC51xx.cpp b/src/Movement/StepperDrivers/TMC51xx.cpp index 804019ca..a2cb4b11 100644 --- a/src/Movement/StepperDrivers/TMC51xx.cpp +++ b/src/Movement/StepperDrivers/TMC51xx.cpp @@ -379,7 +379,7 @@ private: uint16_t numReads, numWrites; // how many successful reads and writes we had static uint16_t numTimeouts; // how many times a transfer timed out - uint8_t standstillCurrentFraction; // divide this by 256 to get the motor current standstill fraction + uint16_t standstillCurrentFraction; // divide this by 256 to get the motor current standstill fraction uint8_t regIndexBeingUpdated; // which register we are sending uint8_t regIndexRequested; // the register we asked to read in the previous transaction, or 0xFF uint8_t previousRegIndexRequested; // the register we asked to read in the previous transaction, or 0xFF @@ -426,7 +426,7 @@ pre(!driversPowered) registersToUpdate = newRegistersToUpdate = 0; specialReadRegisterNumber = specialWriteRegisterNumber = 0xFF; motorCurrent = 0; - standstillCurrentFraction = (uint8_t)min<uint32_t>((DefaultStandstillCurrentPercent * 256)/100, 255); + standstillCurrentFraction = (uint16_t)min<uint32_t>((DefaultStandstillCurrentPercent * 256)/100, 256); // Set default values for all registers and flag them to be updated UpdateRegister(WriteGConf, DefaultGConfReg); @@ -494,7 +494,7 @@ float TmcDriverState::GetStandstillCurrentPercent() const noexcept void TmcDriverState::SetStandstillCurrentPercent(float percent) noexcept { - standstillCurrentFraction = (uint8_t)constrain<long>(lrintf((percent * 256)/100), 0, 255); + standstillCurrentFraction = (uint16_t)constrain<long>(lrintf((percent * 256)/100), 0, 256); UpdateCurrent(); } @@ -731,9 +731,9 @@ void TmcDriverState::UpdateCurrent() noexcept // At high motor currents, limit the standstill current fraction to avoid overheating particular pairs of mosfets. Avoid dividing by zero if motorCurrent is zero. constexpr uint32_t MaxStandstillCurrentTimes256 = 256 * (uint32_t)MaximumStandstillCurrent; - const uint8_t limitedStandstillCurrentFraction = (motorCurrent * standstillCurrentFraction <= MaxStandstillCurrentTimes256) + const uint16_t limitedStandstillCurrentFraction = (motorCurrent * standstillCurrentFraction <= MaxStandstillCurrentTimes256) ? standstillCurrentFraction - : (uint8_t)(MaxStandstillCurrentTimes256/motorCurrent); + : (uint16_t)(MaxStandstillCurrentTimes256/motorCurrent); const uint32_t iHold = (iRun * limitedStandstillCurrentFraction)/256; UpdateRegister(WriteIholdIrun, (writeRegisters[WriteIholdIrun] & ~(IHOLDIRUN_IRUN_MASK | IHOLDIRUN_IHOLD_MASK)) | (iRun << IHOLDIRUN_IRUN_SHIFT) | (iHold << IHOLDIRUN_IHOLD_SHIFT)); @@ -795,7 +795,8 @@ void TmcDriverState::AppendDriverStatus(const StringRef& reply, bool clearGlobal reply.cat(", SG min n/a"); } ResetLoadRegisters(); - reply.catf(", reads %u, writes %u timeouts %u", numReads, numWrites, numTimeouts); + + reply.catf(", mspos %u, reads %u, writes %u timeouts %u", (unsigned int)(readRegisters[ReadMsCnt] & 1023), numReads, numWrites, numTimeouts); numReads = numWrites = 0; if (clearGlobalStats) { |